@j0hanz/prompt-tuner-mcp-server 1.0.4 → 1.0.6
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 +20 -23
- package/CONFIGURATION.md +150 -159
- package/README.md +136 -226
- package/dist/config/constants.d.ts +4 -3
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +4 -3
- package/dist/config/constants.js.map +1 -1
- package/dist/config/env.d.ts +0 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +0 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/instructions.d.ts +1 -1
- package/dist/config/instructions.d.ts.map +1 -1
- package/dist/config/instructions.js +21 -43
- package/dist/config/instructions.js.map +1 -1
- package/dist/config/types.d.ts +30 -57
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +0 -7
- package/dist/config/types.js.map +1 -1
- package/dist/config/typos.d.ts.map +1 -1
- package/dist/config/typos.js +1 -4
- package/dist/config/typos.js.map +1 -1
- package/dist/index.js +93 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/abort-signals.d.ts +2 -0
- package/dist/lib/abort-signals.d.ts.map +1 -0
- package/dist/lib/abort-signals.js +5 -0
- package/dist/lib/abort-signals.js.map +1 -0
- package/dist/lib/cache.d.ts +0 -1
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +0 -4
- package/dist/lib/cache.js.map +1 -1
- package/dist/lib/errors.d.ts +3 -7
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +52 -51
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/llm-client.d.ts +5 -1
- package/dist/lib/llm-client.d.ts.map +1 -1
- package/dist/lib/llm-client.js +4 -0
- package/dist/lib/llm-client.js.map +1 -1
- package/dist/lib/llm-json.d.ts.map +1 -1
- package/dist/lib/llm-json.js +67 -1
- package/dist/lib/llm-json.js.map +1 -1
- package/dist/lib/llm-providers/helpers.d.ts +14 -0
- package/dist/lib/llm-providers/helpers.d.ts.map +1 -0
- package/dist/lib/llm-providers/helpers.js +45 -0
- package/dist/lib/llm-providers/helpers.js.map +1 -0
- package/dist/lib/llm-providers.d.ts +2 -0
- package/dist/lib/llm-providers.d.ts.map +1 -1
- package/dist/lib/llm-providers.js +28 -67
- package/dist/lib/llm-providers.js.map +1 -1
- package/dist/lib/llm-runtime.d.ts +1 -1
- package/dist/lib/llm-runtime.d.ts.map +1 -1
- package/dist/lib/llm-runtime.js +8 -6
- package/dist/lib/llm-runtime.js.map +1 -1
- package/dist/lib/llm.d.ts +1 -1
- package/dist/lib/llm.d.ts.map +1 -1
- package/dist/lib/llm.js +4 -11
- package/dist/lib/llm.js.map +1 -1
- package/dist/lib/output-normalization.d.ts +7 -0
- package/dist/lib/output-normalization.d.ts.map +1 -0
- package/dist/lib/output-normalization.js +65 -0
- package/dist/lib/output-normalization.js.map +1 -0
- package/dist/lib/output-validation.d.ts +11 -0
- package/dist/lib/output-validation.d.ts.map +1 -0
- package/dist/lib/output-validation.js +128 -0
- package/dist/lib/output-validation.js.map +1 -0
- package/dist/lib/prompt-analysis/scoring.d.ts.map +1 -1
- package/dist/lib/prompt-analysis/scoring.js +7 -3
- package/dist/lib/prompt-analysis/scoring.js.map +1 -1
- package/dist/lib/prompt-analysis.d.ts +0 -2
- package/dist/lib/prompt-analysis.d.ts.map +1 -1
- package/dist/lib/prompt-analysis.js +0 -2
- package/dist/lib/prompt-analysis.js.map +1 -1
- package/dist/lib/prompt-policy.d.ts +3 -0
- package/dist/lib/prompt-policy.d.ts.map +1 -0
- package/dist/lib/prompt-policy.js +16 -0
- package/dist/lib/prompt-policy.js.map +1 -0
- package/dist/lib/retry.d.ts +1 -1
- package/dist/lib/retry.d.ts.map +1 -1
- package/dist/lib/retry.js +35 -13
- package/dist/lib/retry.js.map +1 -1
- package/dist/lib/technique-templates/format-instructions.d.ts +3 -0
- package/dist/lib/technique-templates/format-instructions.d.ts.map +1 -0
- package/dist/lib/technique-templates/format-instructions.js +42 -0
- package/dist/lib/technique-templates/format-instructions.js.map +1 -0
- package/dist/lib/technique-templates/templates-advanced.d.ts +5 -0
- package/dist/lib/technique-templates/templates-advanced.d.ts.map +1 -0
- package/dist/lib/technique-templates/templates-advanced.js +139 -0
- package/dist/lib/technique-templates/templates-advanced.js.map +1 -0
- package/dist/lib/technique-templates/templates-basic.d.ts +5 -0
- package/dist/lib/technique-templates/templates-basic.d.ts.map +1 -0
- package/dist/lib/technique-templates/templates-basic.js +129 -0
- package/dist/lib/technique-templates/templates-basic.js.map +1 -0
- package/dist/lib/technique-templates.d.ts +1 -1
- package/dist/lib/technique-templates.d.ts.map +1 -1
- package/dist/lib/technique-templates.js +15 -318
- package/dist/lib/technique-templates.js.map +1 -1
- package/dist/lib/tool-formatters.d.ts +13 -0
- package/dist/lib/tool-formatters.d.ts.map +1 -0
- package/dist/lib/tool-formatters.js +26 -0
- package/dist/lib/tool-formatters.js.map +1 -0
- package/dist/lib/tool-helpers.d.ts +8 -1
- package/dist/lib/tool-helpers.d.ts.map +1 -1
- package/dist/lib/tool-helpers.js +32 -7
- package/dist/lib/tool-helpers.js.map +1 -1
- package/dist/lib/tool-resources.d.ts +3 -0
- package/dist/lib/tool-resources.d.ts.map +1 -0
- package/dist/lib/tool-resources.js +23 -0
- package/dist/lib/tool-resources.js.map +1 -0
- package/dist/lib/validation.d.ts +0 -2
- package/dist/lib/validation.d.ts.map +1 -1
- package/dist/lib/validation.js +0 -13
- package/dist/lib/validation.js.map +1 -1
- package/dist/prompts/quick-workflows.d.ts.map +1 -1
- package/dist/prompts/quick-workflows.js +127 -219
- package/dist/prompts/quick-workflows.js.map +1 -1
- package/dist/resources/index.d.ts +1 -2
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +2 -3
- package/dist/resources/index.js.map +1 -1
- package/dist/resources/prompt-templates.d.ts.map +1 -1
- package/dist/resources/prompt-templates.js +3 -12
- package/dist/resources/prompt-templates.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -3
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +2 -3
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/inputs.d.ts +4 -27
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +0 -17
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/schemas/llm-responses.d.ts +11 -186
- package/dist/schemas/llm-responses.d.ts.map +1 -1
- package/dist/schemas/llm-responses.js +8 -19
- package/dist/schemas/llm-responses.js.map +1 -1
- package/dist/schemas/outputs.d.ts +149 -350
- package/dist/schemas/outputs.d.ts.map +1 -1
- package/dist/schemas/outputs.js +47 -74
- package/dist/schemas/outputs.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -5
- package/dist/server.js.map +1 -1
- package/dist/tools/analyze-prompt.d.ts.map +1 -1
- package/dist/tools/analyze-prompt.js +121 -168
- package/dist/tools/analyze-prompt.js.map +1 -1
- package/dist/tools/compare-prompts.d.ts.map +1 -1
- package/dist/tools/compare-prompts.js +48 -31
- package/dist/tools/compare-prompts.js.map +1 -1
- package/dist/tools/detect-format.d.ts.map +1 -1
- package/dist/tools/detect-format.js +49 -39
- package/dist/tools/detect-format.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +0 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/optimize-prompt/formatters.d.ts +2 -0
- package/dist/tools/optimize-prompt/formatters.d.ts.map +1 -0
- package/dist/tools/optimize-prompt/formatters.js +57 -0
- package/dist/tools/optimize-prompt/formatters.js.map +1 -0
- package/dist/tools/optimize-prompt.d.ts.map +1 -1
- package/dist/tools/optimize-prompt.js +156 -147
- package/dist/tools/optimize-prompt.js.map +1 -1
- package/dist/tools/refine-prompt.d.ts.map +1 -1
- package/dist/tools/refine-prompt.js +66 -38
- package/dist/tools/refine-prompt.js.map +1 -1
- package/dist/tools/validate-prompt/prompt.d.ts +2 -0
- package/dist/tools/validate-prompt/prompt.d.ts.map +1 -0
- package/dist/tools/validate-prompt/prompt.js +40 -0
- package/dist/tools/validate-prompt/prompt.js.map +1 -0
- package/dist/tools/validate-prompt.d.ts.map +1 -1
- package/dist/tools/validate-prompt.js +113 -143
- package/dist/tools/validate-prompt.js.map +1 -1
- package/package.json +5 -4
- package/src/config/constants.ts +4 -3
- package/src/config/env.ts +0 -3
- package/src/config/instructions.ts +21 -43
- package/src/config/types.ts +36 -66
- package/src/index.ts +112 -10
- package/src/lib/abort-signals.ts +7 -0
- package/src/lib/errors.ts +90 -85
- package/src/lib/llm-client.ts +9 -1
- package/src/lib/llm-json.ts +85 -1
- package/src/lib/llm-providers/helpers.ts +78 -0
- package/src/lib/llm-providers.ts +59 -95
- package/src/lib/llm-runtime.ts +28 -21
- package/src/lib/llm.ts +6 -13
- package/src/lib/output-normalization.ts +91 -0
- package/src/lib/output-validation.ts +164 -0
- package/src/lib/prompt-analysis.ts +0 -5
- package/src/lib/prompt-policy.ts +18 -0
- package/src/lib/retry.ts +51 -13
- package/src/lib/technique-templates/format-instructions.ts +45 -0
- package/src/lib/technique-templates/templates-advanced.ts +147 -0
- package/src/lib/technique-templates/templates-basic.ts +137 -0
- package/src/lib/technique-templates.ts +16 -326
- package/src/lib/tool-formatters.ts +46 -0
- package/src/lib/tool-helpers.ts +50 -12
- package/src/lib/tool-resources.ts +31 -0
- package/src/lib/validation.ts +0 -15
- package/src/prompts/quick-workflows.ts +128 -230
- package/src/schemas/index.ts +0 -12
- package/src/schemas/inputs.ts +0 -19
- package/src/schemas/llm-responses.ts +8 -32
- package/src/schemas/outputs.ts +53 -79
- package/src/server.ts +8 -6
- package/src/tools/analyze-prompt.ts +158 -188
- package/src/tools/index.ts +0 -4
- package/src/tools/optimize-prompt/formatters.ts +70 -0
- package/src/tools/optimize-prompt.ts +258 -174
- package/src/tools/refine-prompt.ts +141 -60
- package/src/tools/validate-prompt/prompt.ts +40 -0
- package/src/tools/validate-prompt.ts +185 -167
- package/src/types/regexp-escape.d.ts +3 -0
- package/tests/llm-json.test.ts +17 -0
- package/tests/quick-workflows.test.ts +1 -34
- package/tsconfig.json +1 -1
- package/src/config/typos.ts +0 -121
- package/src/lib/cache.ts +0 -57
- package/src/lib/prompt-analysis/scoring.ts +0 -235
- package/src/lib/prompt-analysis/suggestions.ts +0 -115
- package/src/resources/index.ts +0 -7
- package/src/resources/prompt-templates/analysis.ts +0 -156
- package/src/resources/prompt-templates/coding.ts +0 -302
- package/src/resources/prompt-templates/data-extraction.ts +0 -122
- package/src/resources/prompt-templates/system-prompts.ts +0 -81
- package/src/resources/prompt-templates/writing.ts +0 -176
- package/src/resources/prompt-templates.ts +0 -203
- package/src/tools/compare-prompts.ts +0 -301
- package/src/tools/detect-format.ts +0 -172
package/AGENTS.md
CHANGED
|
@@ -2,41 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Structure & Module Organization
|
|
4
4
|
|
|
5
|
-
- `src/`
|
|
6
|
-
- `tests/`
|
|
7
|
-
- `
|
|
8
|
-
- `
|
|
5
|
+
- `src/` holds TypeScript source. `src/index.ts` is the entry point and `src/server.ts` wires the MCP server. Subfolders include `config/`, `lib/`, `tools/`, `resources/`, `prompts/`, `schemas/`, and `types/`.
|
|
6
|
+
- `tests/` contains Vitest suites; test files use the `*.test.ts` naming pattern.
|
|
7
|
+
- `dist/` is generated build output (do not edit by hand).
|
|
8
|
+
- `docs/` stores static assets. `CONFIGURATION.md` documents runtime environment variables.
|
|
9
9
|
|
|
10
10
|
## Build, Test, and Development Commands
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- `npm
|
|
15
|
-
- `npm run
|
|
16
|
-
- `npm run
|
|
17
|
-
- `npm
|
|
18
|
-
- `npm test` runs Vitest once; `npm run test:watch` watches tests.
|
|
19
|
-
- `npm run lint` runs ESLint; `npm run format` runs Prettier; `npm run type-check` runs `tsc --noEmit`.
|
|
20
|
-
- `npm run inspector` starts the MCP Inspector (use `inspector:http` for HTTP).
|
|
12
|
+
- `npm run dev` / `npm run dev:http`: run from source with tsx watch (HTTP variant adds `--http`).
|
|
13
|
+
- `npm run build`: compile TypeScript into `dist/` and set executable permissions.
|
|
14
|
+
- `npm run start` / `npm run start:http`: run the compiled server from `dist/`.
|
|
15
|
+
- `npm run test` / `npm run test:watch`: run Vitest once or in watch mode.
|
|
16
|
+
- `npm run lint` and `npm run format`: ESLint checks and Prettier formatting.
|
|
17
|
+
- `npm run type-check`: `tsc --noEmit` for strict type validation.
|
|
21
18
|
|
|
22
19
|
## Coding Style & Naming Conventions
|
|
23
20
|
|
|
24
|
-
- TypeScript
|
|
25
|
-
- Prettier
|
|
26
|
-
- ESLint is strict
|
|
27
|
-
- Naming: `camelCase` for variables/functions, `PascalCase` for types
|
|
21
|
+
- TypeScript, ES modules, Node >= 20.
|
|
22
|
+
- Prettier rules: 2-space indentation, single quotes, trailing commas, 80-char line width, sorted imports.
|
|
23
|
+
- ESLint is strict; avoid `any`, unused imports, and floating promises; prefer `type` imports.
|
|
24
|
+
- Naming: `camelCase` for variables/functions, `PascalCase` for types, `UPPER_CASE` for constants; leading `_` is allowed for unused args.
|
|
28
25
|
|
|
29
26
|
## Testing Guidelines
|
|
30
27
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
28
|
+
- Use Vitest in the Node environment; keep tests in `tests/` and name `*.test.ts`.
|
|
29
|
+
- Favor deterministic tests and keep individual tests under the 15s timeout.
|
|
33
30
|
|
|
34
31
|
## Commit & Pull Request Guidelines
|
|
35
32
|
|
|
36
|
-
-
|
|
37
|
-
- PRs should include a
|
|
33
|
+
- History favors short, imperative summaries; common pattern is `refactor: ...`, plus plain `Add ...` and version bumps like `1.0.5`.
|
|
34
|
+
- PRs should include a brief summary, tests run (for example, `npm run test`), and note any config or environment changes. Link related issues when applicable.
|
|
38
35
|
|
|
39
36
|
## Security & Configuration Tips
|
|
40
37
|
|
|
41
|
-
-
|
|
42
|
-
- Be cautious with `INCLUDE_ERROR_CONTEXT=true`
|
|
38
|
+
- Runtime behavior is driven by environment variables; see `CONFIGURATION.md` for required keys and limits.
|
|
39
|
+
- Never commit API keys. Be cautious with `INCLUDE_ERROR_CONTEXT=true` in production.
|
package/CONFIGURATION.md
CHANGED
|
@@ -1,227 +1,218 @@
|
|
|
1
1
|
# PromptTuner MCP Configuration Guide
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Required configuration
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
You must pick a provider and supply its API key.
|
|
8
8
|
|
|
9
|
-
| Variable |
|
|
10
|
-
| ------------------- |
|
|
11
|
-
| `LLM_PROVIDER` |
|
|
12
|
-
| `OPENAI_API_KEY` |
|
|
13
|
-
| `ANTHROPIC_API_KEY` |
|
|
14
|
-
| `GOOGLE_API_KEY` |
|
|
15
|
-
| `LLM_MODEL` | Model to use (optional) | Provider-specific | `gpt-4o`, `claude-3-5-sonnet-20241022`, `gemini-2.0-flash-exp`, `gemini-2.5-pro-exp` |
|
|
9
|
+
| Variable | Default | Description |
|
|
10
|
+
| ------------------- | -------- | --------------------------------------- |
|
|
11
|
+
| `LLM_PROVIDER` | `openai` | `openai`, `anthropic`, or `google`. |
|
|
12
|
+
| `OPENAI_API_KEY` | - | Required when `LLM_PROVIDER=openai`. |
|
|
13
|
+
| `ANTHROPIC_API_KEY` | - | Required when `LLM_PROVIDER=anthropic`. |
|
|
14
|
+
| `GOOGLE_API_KEY` | - | Required when `LLM_PROVIDER=google`. |
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
PromptTuner checks that the correct API key environment variable is set at startup. The provider will reject invalid keys at request time.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
## Provider defaults
|
|
20
19
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
| `
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `CACHE_MAX_SIZE` | Max cached refinements | `1000` | 500-5000 |
|
|
20
|
+
| Provider | Default model | API key env |
|
|
21
|
+
| ----------- | ---------------------------- | ------------------- |
|
|
22
|
+
| `openai` | `gpt-4o` | `OPENAI_API_KEY` |
|
|
23
|
+
| `anthropic` | `claude-3-5-sonnet-20241022` | `ANTHROPIC_API_KEY` |
|
|
24
|
+
| `google` | `gemini-2.0-flash-exp` | `GOOGLE_API_KEY` |
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
Set `LLM_MODEL` to override the default model for the chosen provider.
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
| ------------------------ | ------------------------------ | ---------------- | ----------------- |
|
|
32
|
-
| `RETRY_MAX_ATTEMPTS` | Max retry attempts | `3` | 1-5 |
|
|
33
|
-
| `RETRY_BASE_DELAY_MS` | Initial retry delay (ms) | `1000` | 500-2000 |
|
|
34
|
-
| `RETRY_MAX_DELAY_MS` | Max retry delay (ms) | `10000` | 5000-30000 |
|
|
35
|
-
| `RETRY_TOTAL_TIMEOUT_MS` | Total timeout for retries (ms) | `180000` (3 min) | 60000-300000 |
|
|
28
|
+
## Limits and timeouts (optional)
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
| Variable | Default | Description |
|
|
31
|
+
| ------------------- | ------- | ------------------------------------ |
|
|
32
|
+
| `MAX_PROMPT_LENGTH` | `10000` | Max trimmed prompt length (chars). |
|
|
33
|
+
| `LLM_MAX_TOKENS` | `8000` | Upper bound for model output tokens. |
|
|
34
|
+
| `LLM_TIMEOUT_MS` | `60000` | Per-request timeout (ms). |
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
| ----------------------- | ------------------------- | ------- | --------------- |
|
|
41
|
-
| `LOG_FORMAT` | Log output format | `text` | `text`, `json` |
|
|
42
|
-
| `DEBUG` | Enable debug logging | `false` | `true`, `false` |
|
|
43
|
-
| `INCLUDE_ERROR_CONTEXT` | Include context in errors | `false` | `true`, `false` |
|
|
36
|
+
### Prompt length enforcement
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
- Input is trimmed before validation.
|
|
39
|
+
- If raw input exceeds `MAX_PROMPT_LENGTH * 2`, it is rejected as excessive whitespace.
|
|
40
|
+
- If trimmed input exceeds `MAX_PROMPT_LENGTH`, it is rejected.
|
|
46
41
|
|
|
47
|
-
###
|
|
42
|
+
### Tool token caps
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
| ------------------------ | ----------------------------- | ------- | --------------- |
|
|
51
|
-
| `GOOGLE_SAFETY_DISABLED` | Disable Gemini safety filters | `false` | `true`, `false` |
|
|
44
|
+
Tool max tokens are derived from `LLM_MAX_TOKENS`:
|
|
52
45
|
|
|
53
|
-
|
|
46
|
+
| Tool | Max tokens |
|
|
47
|
+
| ----------------- | --------------------------- |
|
|
48
|
+
| `analyze_prompt` | `min(LLM_MAX_TOKENS, 4000)` |
|
|
49
|
+
| `refine_prompt` | `min(LLM_MAX_TOKENS, 2000)` |
|
|
50
|
+
| `optimize_prompt` | `min(LLM_MAX_TOKENS, 3000)` |
|
|
51
|
+
| `validate_prompt` | `min(LLM_MAX_TOKENS, 1000)` |
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
## Retry behavior (optional)
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
| Variable | Default | Description |
|
|
56
|
+
| ------------------------ | -------- | ---------------------------------------------- |
|
|
57
|
+
| `RETRY_MAX_ATTEMPTS` | `3` | Max retry attempts (total attempts = max + 1). |
|
|
58
|
+
| `RETRY_BASE_DELAY_MS` | `1000` | Base delay for exponential backoff. |
|
|
59
|
+
| `RETRY_MAX_DELAY_MS` | `10000` | Max delay between retries. |
|
|
60
|
+
| `RETRY_TOTAL_TIMEOUT_MS` | `180000` | Total time allowed across retries. |
|
|
61
|
+
|
|
62
|
+
Retries use exponential backoff with jitter and stop when the total timeout is exceeded.
|
|
63
|
+
|
|
64
|
+
## Logging and error context (optional)
|
|
65
|
+
|
|
66
|
+
| Variable | Default | Description |
|
|
67
|
+
| ----------------------- | ------- | -------------------------------------------------------------- |
|
|
68
|
+
| `DEBUG` | `false` | Enables debug logging. Logs are written to stderr. |
|
|
69
|
+
| `LOG_FORMAT` | `text` | Parsed but currently unused (logging output is JSON via pino). |
|
|
70
|
+
| `INCLUDE_ERROR_CONTEXT` | `false` | Adds a sanitized prompt snippet (up to 200 chars) to errors. |
|
|
71
|
+
|
|
72
|
+
## Provider-specific settings
|
|
73
|
+
|
|
74
|
+
| Variable | Default | Description |
|
|
75
|
+
| ------------------------ | ------- | ------------------------------------------ |
|
|
76
|
+
| `GOOGLE_SAFETY_DISABLED` | `false` | When true, disables Gemini safety filters. |
|
|
77
|
+
|
|
78
|
+
## validate_prompt token limits
|
|
69
79
|
|
|
70
|
-
|
|
80
|
+
`validate_prompt` uses fixed limits when calculating `tokenUtilization`:
|
|
81
|
+
|
|
82
|
+
| targetModel | Token limit |
|
|
83
|
+
| ----------- | ----------- |
|
|
84
|
+
| `claude` | `200000` |
|
|
85
|
+
| `gpt` | `128000` |
|
|
86
|
+
| `gemini` | `1000000` |
|
|
87
|
+
| `generic` | `8000` |
|
|
88
|
+
|
|
89
|
+
## Example configurations
|
|
90
|
+
|
|
91
|
+
### Minimal (npx)
|
|
71
92
|
|
|
72
93
|
```json
|
|
73
94
|
{
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"LLM_MAX_TOKENS": "8000",
|
|
83
|
-
"CACHE_MAX_SIZE": "2000",
|
|
84
|
-
"RETRY_MAX_ATTEMPTS": "5"
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"prompttuner": {
|
|
97
|
+
"command": "npx",
|
|
98
|
+
"args": ["-y", "@j0hanz/prompt-tuner-mcp-server@latest"],
|
|
99
|
+
"env": {
|
|
100
|
+
"LLM_PROVIDER": "openai",
|
|
101
|
+
"OPENAI_API_KEY": "${input:openai-api-key}"
|
|
102
|
+
}
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
}
|
|
88
106
|
```
|
|
89
107
|
|
|
90
|
-
###
|
|
108
|
+
### From source (dist build)
|
|
91
109
|
|
|
92
110
|
```json
|
|
93
111
|
{
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"LLM_MAX_TOKENS": "16000",
|
|
103
|
-
"CACHE_MAX_SIZE": "3000"
|
|
112
|
+
"mcpServers": {
|
|
113
|
+
"prompttuner": {
|
|
114
|
+
"command": "node",
|
|
115
|
+
"args": ["/path/to/prompttuner-mcp/dist/index.js"],
|
|
116
|
+
"env": {
|
|
117
|
+
"LLM_PROVIDER": "anthropic",
|
|
118
|
+
"ANTHROPIC_API_KEY": "${input:anthropic-api-key}"
|
|
119
|
+
}
|
|
104
120
|
}
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
123
|
```
|
|
108
124
|
|
|
109
|
-
###
|
|
125
|
+
### Performance tuned
|
|
110
126
|
|
|
111
127
|
```json
|
|
112
128
|
{
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
"mcpServers": {
|
|
130
|
+
"prompttuner": {
|
|
131
|
+
"command": "node",
|
|
132
|
+
"args": ["/path/to/prompttuner-mcp/dist/index.js"],
|
|
133
|
+
"env": {
|
|
134
|
+
"LLM_PROVIDER": "anthropic",
|
|
135
|
+
"ANTHROPIC_API_KEY": "${input:anthropic-api-key}",
|
|
136
|
+
"LLM_MODEL": "claude-3-5-sonnet-20241022",
|
|
137
|
+
"LLM_TIMEOUT_MS": "90000",
|
|
138
|
+
"LLM_MAX_TOKENS": "8000",
|
|
139
|
+
"RETRY_MAX_ATTEMPTS": "5"
|
|
140
|
+
}
|
|
123
141
|
}
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
144
|
```
|
|
127
145
|
|
|
128
|
-
### High
|
|
146
|
+
### High volume / low latency
|
|
129
147
|
|
|
130
148
|
```json
|
|
131
149
|
{
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"prompttuner": {
|
|
152
|
+
"command": "node",
|
|
153
|
+
"args": ["/path/to/prompttuner-mcp/dist/index.js"],
|
|
154
|
+
"env": {
|
|
155
|
+
"LLM_PROVIDER": "openai",
|
|
156
|
+
"OPENAI_API_KEY": "${input:openai-api-key}",
|
|
157
|
+
"LLM_MODEL": "gpt-4o-mini",
|
|
158
|
+
"LLM_TIMEOUT_MS": "30000",
|
|
159
|
+
"LLM_MAX_TOKENS": "1500",
|
|
160
|
+
"RETRY_MAX_ATTEMPTS": "2",
|
|
161
|
+
"RETRY_BASE_DELAY_MS": "500"
|
|
162
|
+
}
|
|
144
163
|
}
|
|
145
164
|
}
|
|
146
165
|
}
|
|
147
166
|
```
|
|
148
167
|
|
|
149
|
-
## What
|
|
150
|
-
|
|
151
|
-
The following are intentionally hardcoded for stability and optimal performance:
|
|
152
|
-
|
|
153
|
-
### Scoring Algorithm
|
|
154
|
-
|
|
155
|
-
- **Scoring dimension weights** (clarity: 0.25, specificity: 0.25, etc.)
|
|
156
|
-
- **Reason**: Carefully tuned based on prompt engineering research
|
|
168
|
+
## What is not configurable
|
|
157
169
|
|
|
158
|
-
|
|
170
|
+
The following behaviors are hardcoded for stability:
|
|
159
171
|
|
|
160
|
-
-
|
|
161
|
-
-
|
|
172
|
+
- Scoring weights: clarity 0.25, specificity 0.25, completeness 0.2, structure 0.15, effectiveness 0.15.
|
|
173
|
+
- Prompt format detection patterns and scoring heuristics.
|
|
174
|
+
- OpenAI temperature (0.7). Other providers use SDK defaults.
|
|
175
|
+
- LLM response length cap (500000 chars) and JSON parsing safeguards.
|
|
176
|
+
- Error context truncation length (200 chars when enabled).
|
|
162
177
|
|
|
163
|
-
|
|
178
|
+
## Migration notes (older configs)
|
|
164
179
|
|
|
165
|
-
|
|
166
|
-
- **Reason**: Optimal balance between creativity and consistency for prompt refinement
|
|
180
|
+
If you have an old `.env` file, remove unused settings:
|
|
167
181
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
|
|
176
|
-
## Migration from Old Configuration
|
|
177
|
-
|
|
178
|
-
If you have an old `.env` file with these variables, **remove them** (they are not used):
|
|
179
|
-
|
|
180
|
-
- ❌ `PORT` / `HOST` - HTTP mode not fully implemented in stdio version
|
|
181
|
-
- ❌ `API_KEY` - No API authentication in current version
|
|
182
|
-
- ❌ `CORS_ORIGIN` - No HTTP CORS in stdio version
|
|
183
|
-
- ❌ `LOG_LEVEL` - Use `DEBUG=true/false` instead
|
|
184
|
-
- ❌ `RATE_LIMIT` / `RATE_WINDOW_MS` - No rate limiting in current version
|
|
185
|
-
- ❌ `REDIS_URL` / `CACHE_TTL` - In-memory cache only
|
|
186
|
-
- ❌ `CIRCUIT_BREAKER_*` - Not implemented
|
|
187
|
-
- ❌ `NODE_ENV` - Not used for configuration
|
|
188
|
-
- ❌ `SESSION_TIMEOUT_MS` - No session management
|
|
182
|
+
- `PORT`, `HOST`, `CORS_ORIGIN` (stdio transport only; `--http` is reserved).
|
|
183
|
+
- `API_KEY` (no server-level auth).
|
|
184
|
+
- `LOG_LEVEL` (use `DEBUG=true` or false).
|
|
185
|
+
- `RATE_LIMIT`, `RATE_WINDOW_MS` (no server-side rate limiting).
|
|
186
|
+
- `REDIS_URL`, `CACHE_TTL` (no caching).
|
|
187
|
+
- `CIRCUIT_BREAKER_*` (not implemented).
|
|
188
|
+
- `NODE_ENV` (not used for configuration).
|
|
189
|
+
- `SESSION_TIMEOUT_MS` (no session management).
|
|
189
190
|
|
|
190
191
|
## Troubleshooting
|
|
191
192
|
|
|
192
|
-
###
|
|
193
|
-
|
|
194
|
-
- Reduce `CACHE_MAX_SIZE` (e.g., `500`)
|
|
195
|
-
- Reduce `MAX_PROMPT_LENGTH` (e.g., `5000`)
|
|
196
|
-
|
|
197
|
-
### Timeout Errors
|
|
193
|
+
### Prompt rejected
|
|
198
194
|
|
|
199
|
-
-
|
|
200
|
-
- Increase `RETRY_TOTAL_TIMEOUT_MS` (e.g., `300000`)
|
|
201
|
-
- Reduce `LLM_MAX_TOKENS` (e.g., `1500`)
|
|
195
|
+
- Reduce `MAX_PROMPT_LENGTH` or trim the input to remove excessive whitespace.
|
|
202
196
|
|
|
203
|
-
###
|
|
197
|
+
### Timeout errors
|
|
204
198
|
|
|
205
|
-
- Increase `
|
|
206
|
-
-
|
|
199
|
+
- Increase `LLM_TIMEOUT_MS` or `RETRY_TOTAL_TIMEOUT_MS`.
|
|
200
|
+
- Reduce `LLM_MAX_TOKENS`.
|
|
207
201
|
|
|
208
|
-
###
|
|
202
|
+
### Rate limit errors
|
|
209
203
|
|
|
210
|
-
- Increase `
|
|
211
|
-
-
|
|
212
|
-
- Reduce `LLM_MAX_TOKENS` (e.g., `1500`)
|
|
204
|
+
- Increase `RETRY_BASE_DELAY_MS` or `RETRY_MAX_ATTEMPTS`.
|
|
205
|
+
- Reduce request frequency.
|
|
213
206
|
|
|
214
|
-
###
|
|
207
|
+
### Slow performance
|
|
215
208
|
|
|
216
|
-
-
|
|
217
|
-
-
|
|
209
|
+
- Use a faster model (for example `gpt-4o-mini` or `gemini-2.0-flash-exp`).
|
|
210
|
+
- Reduce `LLM_MAX_TOKENS`.
|
|
218
211
|
|
|
219
|
-
## Best
|
|
212
|
+
## Best practices
|
|
220
213
|
|
|
221
|
-
1.
|
|
222
|
-
2.
|
|
223
|
-
3.
|
|
224
|
-
4.
|
|
225
|
-
5.
|
|
226
|
-
6. **Test timeout settings** - Start conservative, increase if seeing timeout errors
|
|
227
|
-
7. **Use JSON logging in production** - `LOG_FORMAT=json` for easier parsing
|
|
214
|
+
1. Configure only the API key for your chosen provider.
|
|
215
|
+
2. Use input variables for secrets (for example `"OPENAI_API_KEY": "${input:openai-api-key}"`).
|
|
216
|
+
3. Start with defaults and tune only when needed.
|
|
217
|
+
4. Enable `DEBUG=true` temporarily for troubleshooting.
|
|
218
|
+
5. Prefer JSON logging in production (current output is JSON via pino).
|