@j0hanz/prompt-tuner-mcp-server 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CONFIGURATION.md +35 -12
- package/README.md +51 -32
- package/dist/config/constants.js +0 -1
- package/dist/config/env.js +0 -5
- package/dist/config/patterns.d.ts +0 -7
- package/dist/config/patterns.js +0 -7
- package/dist/config/types.d.ts +11 -30
- package/dist/index.js +192 -70
- package/dist/lib/errors.js +0 -5
- package/dist/lib/llm-client.d.ts +2 -5
- package/dist/lib/llm-json.js +42 -40
- package/dist/lib/llm-providers/helpers.d.ts +3 -3
- package/dist/lib/llm-providers/helpers.js +2 -0
- package/dist/lib/llm-providers.js +9 -8
- package/dist/lib/llm-runtime.d.ts +1 -1
- package/dist/lib/llm-runtime.js +70 -8
- package/dist/lib/output-normalization.js +12 -32
- package/dist/lib/output-validation.js +21 -55
- package/dist/lib/prompt-analysis/format.js +0 -4
- package/dist/lib/telemetry.d.ts +23 -0
- package/dist/lib/telemetry.js +92 -0
- package/dist/lib/tool-formatters.d.ts +2 -4
- package/dist/lib/tool-helpers.d.ts +5 -5
- package/dist/lib/tool-helpers.js +33 -42
- package/dist/lib/tool-resources.js +2 -6
- package/dist/lib/validation.d.ts +0 -4
- package/dist/lib/validation.js +0 -36
- package/dist/prompts/quick-workflows.js +11 -5
- package/dist/schemas/index.js +0 -1
- package/dist/schemas/inputs.d.ts +4 -4
- package/dist/schemas/inputs.js +1 -10
- package/dist/schemas/llm-responses.d.ts +4 -4
- package/dist/schemas/llm-responses.js +0 -7
- package/dist/schemas/outputs.d.ts +42 -42
- package/dist/server.d.ts +1 -2
- package/dist/server.js +13 -14
- package/dist/tools/analyze-prompt.js +20 -23
- package/dist/tools/optimize-prompt/validation.js +23 -16
- package/dist/tools/optimize-prompt.js +261 -26
- package/dist/tools/refine-prompt.js +97 -41
- package/dist/tools/validate-prompt/constants.d.ts +3 -0
- package/dist/tools/validate-prompt/constants.js +13 -0
- package/dist/tools/validate-prompt/prompt.d.ts +1 -1
- package/dist/tools/validate-prompt/prompt.js +2 -1
- package/dist/tools/validate-prompt.js +105 -37
- package/package.json +9 -11
- package/src/config/constants.ts +0 -2
- package/src/config/env.ts +0 -5
- package/src/config/patterns.ts +0 -28
- package/src/config/types.ts +10 -40
- package/src/index.ts +259 -78
- package/src/lib/errors.ts +0 -5
- package/src/lib/llm-client.ts +2 -5
- package/src/lib/llm-json.ts +53 -59
- package/src/lib/llm-providers/helpers.ts +5 -3
- package/src/lib/llm-providers.ts +11 -10
- package/src/lib/llm-runtime.ts +123 -15
- package/src/lib/output-normalization.ts +16 -34
- package/src/lib/output-validation.ts +21 -68
- package/src/lib/prompt-analysis/format.ts +0 -4
- package/src/lib/telemetry.ts +150 -0
- package/src/lib/tool-formatters.ts +3 -4
- package/src/lib/tool-helpers.ts +78 -115
- package/src/lib/tool-resources.ts +2 -8
- package/src/lib/validation.ts +0 -76
- package/src/prompts/quick-workflows.ts +17 -7
- package/src/schemas/index.ts +0 -2
- package/src/schemas/inputs.ts +4 -11
- package/src/schemas/llm-responses.ts +0 -7
- package/src/server.ts +14 -15
- package/src/tools/analyze-prompt.ts +48 -42
- package/src/tools/optimize-prompt.ts +462 -42
- package/src/tools/refine-prompt.ts +198 -113
- package/src/tools/validate-prompt.ts +148 -63
- package/tests/input-schema.test.ts +15 -14
- package/tests/integration.test.ts +72 -57
- package/tests/llm-json.test.ts +17 -14
- package/tests/output-validation.test.ts +11 -7
- package/tests/quick-workflows.test.ts +8 -3
- package/tests/server.test.ts +3 -2
- package/tsconfig.json +1 -1
- package/benchmark/llm-json.bench.ts +0 -96
- package/benchmark/output-validation.bench.ts +0 -108
- package/benchmark/prompt-analysis.bench.ts +0 -105
- package/src/lib/prompt-analysis.ts +0 -5
- package/src/tools/index.ts +0 -22
- package/src/tools/optimize-prompt/constants.ts +0 -66
- package/src/tools/optimize-prompt/formatters.ts +0 -100
- package/src/tools/optimize-prompt/inputs.ts +0 -40
- package/src/tools/optimize-prompt/output.ts +0 -96
- package/src/tools/optimize-prompt/prompt.ts +0 -19
- package/src/tools/optimize-prompt/run.ts +0 -27
- package/src/tools/optimize-prompt/types.ts +0 -35
- package/src/tools/optimize-prompt/validation.ts +0 -114
- package/src/tools/refine-prompt/formatters.ts +0 -82
- package/src/tools/refine-prompt/types.ts +0 -22
- package/src/tools/validate-prompt/formatters.ts +0 -77
- package/src/tools/validate-prompt/prompt.ts +0 -40
- package/src/tools/validate-prompt/types.ts +0 -1
- package/src/types/regexp-escape.d.ts +0 -3
- package/vitest.config.ts +0 -12
package/AGENTS.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Project Overview
|
|
4
4
|
|
|
5
5
|
- **Goal**: MCP server for refining, analyzing, optimizing, and validating AI prompts.
|
|
6
|
-
- **Stack**: Node.js (>=20), TypeScript, Model Context Protocol (MCP), Zod,
|
|
6
|
+
- **Stack**: Node.js (>=20), TypeScript, Model Context Protocol (MCP), Zod, `node:test`.
|
|
7
7
|
- **Key Libraries**: `@modelcontextprotocol/sdk`, `openai`, `@anthropic-ai/sdk`, `@google/genai`, `zod`.
|
|
8
8
|
|
|
9
9
|
## Repo Map / Structure
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
|
|
39
39
|
## Testing
|
|
40
40
|
|
|
41
|
-
- **Run all tests**: `npm run test` (uses
|
|
41
|
+
- **Run all tests**: `npm run test` (uses `node:test`).
|
|
42
42
|
- **Watch mode**: `npm run test:watch`.
|
|
43
43
|
- **Coverage**: `npm run test:coverage`.
|
|
44
44
|
- **Test files**: Located in `tests/` directory, matching `*.test.ts`.
|
package/CONFIGURATION.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# PromptTuner MCP Configuration Guide
|
|
2
2
|
|
|
3
|
-
PromptTuner MCP is configured entirely via environment variables. Set them in your MCP client configuration (for example `mcp.json`, `claude_desktop_config.json`) or a `.env` file.
|
|
3
|
+
PromptTuner MCP is configured entirely via environment variables. Set them in your MCP client configuration (for example `mcp.json`, `claude_desktop_config.json`) or a `.env` file. Node.js >= 22.0.0 is required (see `package.json` engines).
|
|
4
4
|
|
|
5
5
|
## Required configuration
|
|
6
6
|
|
|
@@ -25,18 +25,37 @@ PromptTuner checks that the correct API key environment variable is set at start
|
|
|
25
25
|
|
|
26
26
|
Set `LLM_MODEL` to override the default model for the chosen provider.
|
|
27
27
|
|
|
28
|
+
## CLI overrides
|
|
29
|
+
|
|
30
|
+
CLI flags override environment variables. Flags only cover a subset of settings; retry options and `GOOGLE_SAFETY_DISABLED` are env-only.
|
|
31
|
+
|
|
32
|
+
| Flag | Env var | Description |
|
|
33
|
+
| ------------------------------ | ----------------------- | ------------------------------------------- | --------------------------------------- |
|
|
34
|
+
| `--log-format <text | json>` | `LOG_FORMAT` | Override log format (currently unused). |
|
|
35
|
+
| `--debug / --no-debug` | `DEBUG` | Enable/disable debug logging. |
|
|
36
|
+
| `--include-error-context` | `INCLUDE_ERROR_CONTEXT` | Include sanitized prompt snippet in errors. |
|
|
37
|
+
| `--llm-provider <provider>` | `LLM_PROVIDER` | `openai`, `anthropic`, or `google`. |
|
|
38
|
+
| `--llm-model <name>` | `LLM_MODEL` | Override the default model. |
|
|
39
|
+
| `--llm-timeout-ms <number>` | `LLM_TIMEOUT_MS` | Override request timeout (ms). |
|
|
40
|
+
| `--llm-max-tokens <number>` | `LLM_MAX_TOKENS` | Override output token cap. |
|
|
41
|
+
| `--max-prompt-length <number>` | `MAX_PROMPT_LENGTH` | Override max prompt length (chars). |
|
|
42
|
+
|
|
28
43
|
## Limits and timeouts (optional)
|
|
29
44
|
|
|
30
45
|
| Variable | Default | Description |
|
|
31
46
|
| ------------------- | ------- | ------------------------------------ |
|
|
32
47
|
| `MAX_PROMPT_LENGTH` | `10000` | Max trimmed prompt length (chars). |
|
|
33
48
|
| `LLM_MAX_TOKENS` | `8000` | Upper bound for model output tokens. |
|
|
34
|
-
| `LLM_TIMEOUT_MS` | `60000` |
|
|
49
|
+
| `LLM_TIMEOUT_MS` | `60000` | Request timeout (ms). |
|
|
50
|
+
|
|
51
|
+
All numeric values are parsed as integers. Invalid values or values below the minimum thresholds will fail startup validation.
|
|
52
|
+
|
|
53
|
+
Minimums: `MAX_PROMPT_LENGTH` >= 1, `LLM_MAX_TOKENS` >= 1, `LLM_TIMEOUT_MS` >= 1000.
|
|
35
54
|
|
|
36
55
|
### Prompt length enforcement
|
|
37
56
|
|
|
38
57
|
- Input is trimmed before validation.
|
|
39
|
-
-
|
|
58
|
+
- Raw input length is capped at `MAX_PROMPT_LENGTH * 2` before trimming.
|
|
40
59
|
- If trimmed input exceeds `MAX_PROMPT_LENGTH`, it is rejected.
|
|
41
60
|
|
|
42
61
|
### Tool token caps
|
|
@@ -59,15 +78,19 @@ Tool max tokens are derived from `LLM_MAX_TOKENS`:
|
|
|
59
78
|
| `RETRY_MAX_DELAY_MS` | `10000` | Max delay between retries. |
|
|
60
79
|
| `RETRY_TOTAL_TIMEOUT_MS` | `180000` | Total time allowed across retries. |
|
|
61
80
|
|
|
62
|
-
Retries use exponential backoff
|
|
81
|
+
Retries use exponential backoff (no jitter) and stop when the total timeout is exceeded.
|
|
82
|
+
|
|
83
|
+
Minimums: `RETRY_MAX_ATTEMPTS` >= 0, `RETRY_BASE_DELAY_MS` >= 100, `RETRY_MAX_DELAY_MS` >= 1000, `RETRY_TOTAL_TIMEOUT_MS` >= 10000.
|
|
63
84
|
|
|
64
85
|
## Logging and error context (optional)
|
|
65
86
|
|
|
66
|
-
| Variable | Default | Description
|
|
67
|
-
| ----------------------- | ------- |
|
|
68
|
-
| `DEBUG` | `false` | Enables debug logging. Logs are written to stderr.
|
|
69
|
-
| `LOG_FORMAT` | `text` |
|
|
70
|
-
| `INCLUDE_ERROR_CONTEXT` | `false` | Adds a sanitized prompt snippet (up to 200 chars) to errors.
|
|
87
|
+
| Variable | Default | Description |
|
|
88
|
+
| ----------------------- | ------- | ---------------------------------------------------------------------------------------- |
|
|
89
|
+
| `DEBUG` | `false` | Enables debug logging (set to the string `true` or `false`). Logs are written to stderr. |
|
|
90
|
+
| `LOG_FORMAT` | `text` | Accepted values: `json`, `text`. Currently ignored; output is always JSON via pino. |
|
|
91
|
+
| `INCLUDE_ERROR_CONTEXT` | `false` | Adds a sanitized prompt snippet (up to 200 chars) to errors. |
|
|
92
|
+
|
|
93
|
+
When `DEBUG=true`, the server also logs diagnostics-channel telemetry for LLM requests and event-loop health.
|
|
71
94
|
|
|
72
95
|
## Provider-specific settings
|
|
73
96
|
|
|
@@ -179,7 +202,7 @@ The following behaviors are hardcoded for stability:
|
|
|
179
202
|
|
|
180
203
|
If you have an old `.env` file, remove unused settings:
|
|
181
204
|
|
|
182
|
-
- `PORT`, `HOST`, `CORS_ORIGIN` (stdio transport only;
|
|
205
|
+
- `PORT`, `HOST`, `CORS_ORIGIN` (stdio transport only; no HTTP listener).
|
|
183
206
|
- `API_KEY` (no server-level auth).
|
|
184
207
|
- `LOG_LEVEL` (use `DEBUG=true` or false).
|
|
185
208
|
- `RATE_LIMIT`, `RATE_WINDOW_MS` (no server-side rate limiting).
|
|
@@ -192,7 +215,7 @@ If you have an old `.env` file, remove unused settings:
|
|
|
192
215
|
|
|
193
216
|
### Prompt rejected
|
|
194
217
|
|
|
195
|
-
-
|
|
218
|
+
- Shorten the prompt, remove excessive whitespace, or increase `MAX_PROMPT_LENGTH`.
|
|
196
219
|
|
|
197
220
|
### Timeout errors
|
|
198
221
|
|
|
@@ -215,4 +238,4 @@ If you have an old `.env` file, remove unused settings:
|
|
|
215
238
|
2. Use input variables for secrets (for example `"OPENAI_API_KEY": "${input:openai-api-key}"`).
|
|
216
239
|
3. Start with defaults and tune only when needed.
|
|
217
240
|
4. Enable `DEBUG=true` temporarily for troubleshooting.
|
|
218
|
-
5.
|
|
241
|
+
5. Logs are JSON via pino; plan parsing/collection accordingly.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@j0hanz/prompt-tuner-mcp-server)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
[](https://nodejs.org/)
|
|
8
8
|
|
|
9
9
|
PromptTuner MCP is an MCP server that refines, analyzes, optimizes, and validates prompts using OpenAI, Anthropic, or Google Gemini.
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ PromptTuner MCP is an MCP server that refines, analyzes, optimizes, and validate
|
|
|
14
14
|
2. Resolves the target format (`auto` uses heuristics; falls back to `gpt` if no format is detected).
|
|
15
15
|
3. Calls the selected provider with retry and timeout controls.
|
|
16
16
|
4. Validates and normalizes LLM output, falling back to stricter prompts or the `basic` technique when needed.
|
|
17
|
-
5. Returns human-readable text plus machine-friendly `structuredContent` (and
|
|
17
|
+
5. Returns human-readable text plus machine-friendly `structuredContent` (and resource blocks for refined/optimized outputs).
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
|
@@ -24,10 +24,11 @@ PromptTuner MCP is an MCP server that refines, analyzes, optimizes, and validate
|
|
|
24
24
|
- Auto-detect target format (Claude XML, GPT Markdown, or JSON).
|
|
25
25
|
- Structured outputs with provider/model metadata, fallback indicators, and score normalization.
|
|
26
26
|
- Retry logic with exponential backoff for transient provider failures.
|
|
27
|
+
- Emits MCP progress notifications for `analyze_prompt` when a progress token is provided.
|
|
27
28
|
|
|
28
29
|
## Quick Start
|
|
29
30
|
|
|
30
|
-
PromptTuner runs over stdio
|
|
31
|
+
PromptTuner runs over stdio only. The `dev:http` and `start:http` scripts are compatibility aliases (no HTTP transport yet).
|
|
31
32
|
|
|
32
33
|
### Claude Desktop
|
|
33
34
|
|
|
@@ -52,7 +53,7 @@ Add to `claude_desktop_config.json`:
|
|
|
52
53
|
|
|
53
54
|
## Configuration (Essentials)
|
|
54
55
|
|
|
55
|
-
PromptTuner reads configuration from environment variables. Full reference in `CONFIGURATION.md`.
|
|
56
|
+
PromptTuner reads configuration from environment variables. CLI flags can override them (run `prompt-tuner-mcp-server --help`). Full reference in `CONFIGURATION.md`.
|
|
56
57
|
|
|
57
58
|
| Variable | Default | Description |
|
|
58
59
|
| ------------------- | ---------------- | ---------------------------------------------- |
|
|
@@ -65,6 +66,21 @@ PromptTuner reads configuration from environment variables. Full reference in `C
|
|
|
65
66
|
| `LLM_MAX_TOKENS` | `8000` | Upper bound for LLM outputs (tool caps apply). |
|
|
66
67
|
| `MAX_PROMPT_LENGTH` | `10000` | Max trimmed prompt length (chars). |
|
|
67
68
|
|
|
69
|
+
## CLI Options
|
|
70
|
+
|
|
71
|
+
CLI flags override environment variables (run `prompt-tuner-mcp-server --help`).
|
|
72
|
+
|
|
73
|
+
| Flag | Env var | Description |
|
|
74
|
+
| ------------------------------ | ----------------------- | ------------------------------------------- | --------------------------------------- |
|
|
75
|
+
| `--log-format <text | json>` | `LOG_FORMAT` | Override log format (currently unused). |
|
|
76
|
+
| `--debug / --no-debug` | `DEBUG` | Enable/disable debug logging. |
|
|
77
|
+
| `--include-error-context` | `INCLUDE_ERROR_CONTEXT` | Include sanitized prompt snippet in errors. |
|
|
78
|
+
| `--llm-provider <provider>` | `LLM_PROVIDER` | `openai`, `anthropic`, or `google`. |
|
|
79
|
+
| `--llm-model <name>` | `LLM_MODEL` | Override the default model. |
|
|
80
|
+
| `--llm-timeout-ms <number>` | `LLM_TIMEOUT_MS` | Override request timeout (ms). |
|
|
81
|
+
| `--llm-max-tokens <number>` | `LLM_MAX_TOKENS` | Override output token cap. |
|
|
82
|
+
| `--max-prompt-length <number>` | `MAX_PROMPT_LENGTH` | Override max prompt length (chars). |
|
|
83
|
+
|
|
68
84
|
## Tools
|
|
69
85
|
|
|
70
86
|
All tools accept plain text, Markdown, or XML prompts. Responses include `content` (human-readable) and `structuredContent` (machine-readable).
|
|
@@ -95,11 +111,11 @@ Returns: `ok`, `hasTypos`, `isVague`, `missingContext`, `suggestions`, `score`,
|
|
|
95
111
|
|
|
96
112
|
Apply multiple techniques sequentially and return before/after scores.
|
|
97
113
|
|
|
98
|
-
| Parameter | Type | Required | Default | Notes
|
|
99
|
-
| -------------- | -------- | -------- | ----------- |
|
|
100
|
-
| `prompt` | string | Yes | - | Trimmed and length-checked.
|
|
101
|
-
| `techniques` | string[] | No | `["basic"]` | 1-6 techniques;
|
|
102
|
-
| `targetFormat` | string | No | `auto` | `auto`, `claude`, `gpt`, `json`.
|
|
114
|
+
| Parameter | Type | Required | Default | Notes |
|
|
115
|
+
| -------------- | -------- | -------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `prompt` | string | Yes | - | Trimmed and length-checked. |
|
|
117
|
+
| `techniques` | string[] | No | `["basic"]` | 1-6 techniques; order preserved. `comprehensive` expands to `basic -> roleBased -> structured -> fewShot -> chainOfThought`. |
|
|
118
|
+
| `targetFormat` | string | No | `auto` | `auto`, `claude`, `gpt`, `json`. |
|
|
103
119
|
|
|
104
120
|
Returns: `ok`, `original`, `optimized`, `techniquesApplied`, `targetFormat`, `beforeScore`, `afterScore`, `scoreDelta`, `improvements`, `usedFallback`, `scoreAdjusted`, `overallSource`, `provider`, `model`.
|
|
105
121
|
|
|
@@ -119,10 +135,11 @@ Token limits used for `validate_prompt`: `claude` 200000, `gpt` 128000, `gemini`
|
|
|
119
135
|
|
|
120
136
|
## Response Format
|
|
121
137
|
|
|
122
|
-
- `content`: human-readable Markdown
|
|
138
|
+
- `content`: array of content blocks (human-readable Markdown text plus optional resources).
|
|
123
139
|
- `structuredContent`: machine-parseable results.
|
|
124
140
|
- Errors return `structuredContent.ok=false` and an `error` object with `code`, `message`, optional `context` (sanitized, up to 200 chars), `details`, and `recoveryHint`.
|
|
125
|
-
-
|
|
141
|
+
- Error responses also include `isError: true`.
|
|
142
|
+
- `refine_prompt` and `optimize_prompt` include a `resource` content block with a `file:///` URI and the prompt text in `resource.text` (Markdown).
|
|
126
143
|
|
|
127
144
|
## Prompts
|
|
128
145
|
|
|
@@ -132,6 +149,8 @@ Token limits used for `validate_prompt`: `claude` 200000, `gpt` 128000, `gemini`
|
|
|
132
149
|
| `deep-optimize` | Comprehensive optimization using the `comprehensive` technique. |
|
|
133
150
|
| `analyze` | Score prompt quality and return suggestions. |
|
|
134
151
|
|
|
152
|
+
All prompts accept a single argument: `{ "prompt": "..." }`.
|
|
153
|
+
|
|
135
154
|
## Prompt Optimization Workflow
|
|
136
155
|
|
|
137
156
|
### Technique selection guide
|
|
@@ -159,27 +178,29 @@ Token limits used for `validate_prompt`: `claude` 200000, `gpt` 128000, `gemini`
|
|
|
159
178
|
|
|
160
179
|
### Prerequisites
|
|
161
180
|
|
|
162
|
-
- Node.js >=
|
|
181
|
+
- Node.js >= 22.0.0
|
|
163
182
|
- npm
|
|
164
183
|
|
|
165
184
|
### Scripts
|
|
166
185
|
|
|
167
|
-
| Command | Description
|
|
168
|
-
| ------------------------ |
|
|
169
|
-
| `npm run build` | Compile TypeScript and set permissions.
|
|
170
|
-
| `npm run
|
|
171
|
-
| `npm run dev
|
|
172
|
-
| `npm run
|
|
173
|
-
| `npm run
|
|
174
|
-
| `npm run
|
|
175
|
-
| `npm run
|
|
176
|
-
| `npm run test
|
|
177
|
-
| `npm run
|
|
178
|
-
| `npm run
|
|
179
|
-
| `npm run
|
|
180
|
-
| `npm run
|
|
181
|
-
| `npm run
|
|
182
|
-
| `npm run
|
|
186
|
+
| Command | Description |
|
|
187
|
+
| ------------------------ | ----------------------------------------------------- |
|
|
188
|
+
| `npm run build` | Compile TypeScript and set permissions. |
|
|
189
|
+
| `npm run prepare` | Build on install (publishing helper). |
|
|
190
|
+
| `npm run dev` | Run from source in watch mode. |
|
|
191
|
+
| `npm run dev:http` | Alias of `npm run dev` (no HTTP transport yet). |
|
|
192
|
+
| `npm run watch` | TypeScript compiler in watch mode. |
|
|
193
|
+
| `npm run start` | Run the compiled server from `dist/`. |
|
|
194
|
+
| `npm run start:http` | Alias of `npm run start` (no HTTP transport yet). |
|
|
195
|
+
| `npm run test` | Run `node:test` once. |
|
|
196
|
+
| `npm run test:coverage` | Run `node:test` with experimental coverage. |
|
|
197
|
+
| `npm run test:watch` | Run `node:test` in watch mode. |
|
|
198
|
+
| `npm run lint` | Run ESLint. |
|
|
199
|
+
| `npm run format` | Run Prettier. |
|
|
200
|
+
| `npm run type-check` | TypeScript type checking. |
|
|
201
|
+
| `npm run inspector` | Run MCP Inspector against `dist/index.js`. |
|
|
202
|
+
| `npm run inspector:http` | Alias of `npm run inspector` (no HTTP transport yet). |
|
|
203
|
+
| `npm run duplication` | Run jscpd duplication report. |
|
|
183
204
|
|
|
184
205
|
## Project Structure
|
|
185
206
|
|
|
@@ -190,12 +211,10 @@ src/
|
|
|
190
211
|
config/ Configuration and constants
|
|
191
212
|
lib/ Shared utilities (LLM, retry, validation)
|
|
192
213
|
tools/ Tool implementations
|
|
193
|
-
prompts/
|
|
194
|
-
resources/ Resource registration (currently none)
|
|
214
|
+
prompts/ MCP prompt templates
|
|
195
215
|
schemas/ Zod input/output schemas
|
|
196
|
-
types/ Shared types
|
|
197
216
|
|
|
198
|
-
tests/
|
|
217
|
+
tests/ node:test suites
|
|
199
218
|
|
|
200
219
|
dist/ Compiled output (generated)
|
|
201
220
|
|
package/dist/config/constants.js
CHANGED
|
@@ -11,7 +11,6 @@ export const SCORING_WEIGHTS = {
|
|
|
11
11
|
};
|
|
12
12
|
export const SERVER_NAME = 'prompttuner-mcp';
|
|
13
13
|
export const SERVER_VERSION = packageJson.version;
|
|
14
|
-
// Configurable via environment variables
|
|
15
14
|
const { MAX_PROMPT_LENGTH: ENV_MAX_PROMPT_LENGTH, LLM_TIMEOUT_MS: ENV_LLM_TIMEOUT_MS, LLM_MAX_TOKENS: ENV_LLM_MAX_TOKENS, } = config;
|
|
16
15
|
export const MAX_PROMPT_LENGTH = ENV_MAX_PROMPT_LENGTH;
|
|
17
16
|
export const MIN_PROMPT_LENGTH = 1;
|
package/dist/config/env.js
CHANGED
|
@@ -11,11 +11,9 @@ const numberString = (def, min = 0) => z
|
|
|
11
11
|
.transform((v) => parseInt(v, 10))
|
|
12
12
|
.refine((n) => n >= min, { message: `Must be >= ${min}` });
|
|
13
13
|
const envSchema = z.object({
|
|
14
|
-
// Server
|
|
15
14
|
LOG_FORMAT: z.enum(['json', 'text']).optional().default('text'),
|
|
16
15
|
DEBUG: booleanString,
|
|
17
16
|
INCLUDE_ERROR_CONTEXT: booleanString,
|
|
18
|
-
// LLM
|
|
19
17
|
LLM_PROVIDER: z
|
|
20
18
|
.enum(['openai', 'anthropic', 'google'])
|
|
21
19
|
.optional()
|
|
@@ -28,13 +26,10 @@ const envSchema = z.object({
|
|
|
28
26
|
.optional()
|
|
29
27
|
.default('false')
|
|
30
28
|
.transform((v) => v === 'true'),
|
|
31
|
-
// Keys
|
|
32
29
|
OPENAI_API_KEY: z.string().optional(),
|
|
33
30
|
ANTHROPIC_API_KEY: z.string().optional(),
|
|
34
31
|
GOOGLE_API_KEY: z.string().optional(),
|
|
35
|
-
// Constraints
|
|
36
32
|
MAX_PROMPT_LENGTH: numberString(10000, 1),
|
|
37
|
-
// Retry
|
|
38
33
|
RETRY_MAX_ATTEMPTS: numberString(3, 0),
|
|
39
34
|
RETRY_BASE_DELAY_MS: numberString(1000, 100),
|
|
40
35
|
RETRY_MAX_DELAY_MS: numberString(10000, 1000),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const PATTERNS: {
|
|
2
|
-
readonly roleIndicators: RegExp;
|
|
3
2
|
readonly exampleIndicators: RegExp;
|
|
4
3
|
readonly stepByStepIndicators: RegExp;
|
|
5
4
|
readonly xmlStructure: RegExp;
|
|
@@ -8,12 +7,6 @@ export declare const PATTERNS: {
|
|
|
8
7
|
readonly claudePatterns: RegExp;
|
|
9
8
|
readonly gptPatterns: RegExp;
|
|
10
9
|
readonly vagueWords: RegExp;
|
|
11
|
-
readonly needsReasoning: RegExp;
|
|
12
|
-
readonly hasStepByStep: RegExp;
|
|
13
10
|
readonly hasRole: RegExp;
|
|
14
|
-
readonly constraintPatterns: RegExp;
|
|
15
|
-
readonly outputSpecPatterns: RegExp;
|
|
16
11
|
readonly fewShotStructure: RegExp;
|
|
17
|
-
readonly qualityIndicators: RegExp;
|
|
18
|
-
readonly antiPatterns: RegExp;
|
|
19
12
|
};
|
package/dist/config/patterns.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export const PATTERNS = {
|
|
2
|
-
roleIndicators: /\b(you are|act as|pretend to be|as a|role:|persona:|imagine you are|your role is|you're an?)\b/i,
|
|
3
2
|
exampleIndicators: /(?:^|\s|[([{])(example:|for example|e\.g\.|such as|here's an example|input:|output:|sample:|demonstration:)(?:$|\s|[)\]}.!?,])/i,
|
|
4
3
|
stepByStepIndicators: /(?:^|\s|[([{])(step by step|step-by-step|first,|then,|finally,|1\.|2\.|3\.|let's think|let's work through|let's analyze|let's break|systematically)(?:$|\s|[)\]}.!?,])/i,
|
|
5
4
|
xmlStructure: /<[a-z_]+>[^<]*<\/[a-z_]+>/is,
|
|
@@ -8,12 +7,6 @@ export const PATTERNS = {
|
|
|
8
7
|
claudePatterns: /<(thinking|response|context|instructions|example|task|requirements|output_format|rules|constraints)>/i,
|
|
9
8
|
gptPatterns: /^##\s|^###\s|\*\*[^*]+\*\*|^>\s/m,
|
|
10
9
|
vagueWords: /\b(something|stuff|things|maybe|kind of|sort of|etc|whatever|somehow|certain|various)\b/gi,
|
|
11
|
-
needsReasoning: /\b(calculate|analyze|compare|evaluate|explain|solve|debug|review|reason|deduce|derive|prove|assess|investigate|examine|determine)\b/i,
|
|
12
|
-
hasStepByStep: /step[- ]by[- ]step|first,|then,|finally,|let's think|let's work through|let's analyze/i,
|
|
13
10
|
hasRole: /\b(you are|act as|as a|role:|persona:|your role|you're an?|imagine you are)\b/i,
|
|
14
|
-
constraintPatterns: /\b(NEVER|ALWAYS|MUST|MUST NOT|DO NOT|RULES:|CONSTRAINTS:|REQUIREMENTS:)\b/,
|
|
15
|
-
outputSpecPatterns: /\b(output format|respond with|return as|format:|expected output|response format|<output|## Output)\b/i,
|
|
16
11
|
fewShotStructure: /<example>|Example \d+:|Input:|Output:|###\s*Example|Q:|A:/i,
|
|
17
|
-
qualityIndicators: /\b(specific|detailed|comprehensive|thorough|clear|concise|precise|accurate)\b/i,
|
|
18
|
-
antiPatterns: /\b(do whatever|anything|everything|all of it|any way you want)\b/i,
|
|
19
12
|
};
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export type ToolRegistrar = (server: McpServer) => void;
|
|
3
|
-
interface TextContentBlock {
|
|
4
|
-
type: 'text';
|
|
5
|
-
text: string;
|
|
6
|
-
}
|
|
7
|
-
interface TextResourcePayload {
|
|
1
|
+
interface ResourceTextPayload {
|
|
8
2
|
uri: string;
|
|
9
|
-
mimeType?: string;
|
|
10
3
|
text: string;
|
|
11
|
-
}
|
|
12
|
-
interface BlobResourcePayload {
|
|
13
|
-
uri: string;
|
|
14
4
|
mimeType?: string;
|
|
15
|
-
blob: string;
|
|
16
5
|
}
|
|
17
|
-
|
|
6
|
+
export type ContentBlock = {
|
|
7
|
+
type: 'text';
|
|
8
|
+
text: string;
|
|
9
|
+
} | {
|
|
18
10
|
type: 'resource';
|
|
19
|
-
resource:
|
|
20
|
-
}
|
|
21
|
-
interface ResourceLinkContentBlock {
|
|
22
|
-
type: 'resource_link';
|
|
23
|
-
uri: string;
|
|
24
|
-
name: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
mimeType?: string;
|
|
27
|
-
}
|
|
28
|
-
export type ContentBlock = TextContentBlock | ResourceContentBlock | ResourceLinkContentBlock;
|
|
11
|
+
resource: ResourceTextPayload;
|
|
12
|
+
};
|
|
29
13
|
export interface ErrorResponse {
|
|
30
14
|
[key: string]: unknown;
|
|
31
15
|
content: ContentBlock[];
|
|
@@ -86,7 +70,10 @@ export interface FormatResult {
|
|
|
86
70
|
rawScore: number;
|
|
87
71
|
}
|
|
88
72
|
export type LLMProvider = 'openai' | 'anthropic' | 'google';
|
|
89
|
-
export
|
|
73
|
+
export interface ProviderInfo {
|
|
74
|
+
provider: LLMProvider;
|
|
75
|
+
model: string;
|
|
76
|
+
}
|
|
90
77
|
export interface SafeErrorDetails {
|
|
91
78
|
status?: number;
|
|
92
79
|
code?: string;
|
|
@@ -113,12 +100,6 @@ export interface LLMToolOptions {
|
|
|
113
100
|
timeoutMs?: number;
|
|
114
101
|
signal?: AbortSignal;
|
|
115
102
|
}
|
|
116
|
-
export interface RetryOptions {
|
|
117
|
-
maxRetries?: number;
|
|
118
|
-
baseDelayMs?: number;
|
|
119
|
-
maxDelayMs?: number;
|
|
120
|
-
totalTimeoutMs?: number;
|
|
121
|
-
}
|
|
122
103
|
export interface McpErrorOptions {
|
|
123
104
|
context?: string;
|
|
124
105
|
details?: Record<string, unknown>;
|