@j0hanz/prompt-tuner-mcp-server 1.0.5 → 1.0.7

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.
Files changed (171) hide show
  1. package/AGENTS.md +20 -20
  2. package/CONFIGURATION.md +150 -159
  3. package/README.md +136 -188
  4. package/dist/config/constants.d.ts +4 -2
  5. package/dist/config/constants.d.ts.map +1 -1
  6. package/dist/config/constants.js +4 -2
  7. package/dist/config/constants.js.map +1 -1
  8. package/dist/config/env.d.ts +0 -1
  9. package/dist/config/env.d.ts.map +1 -1
  10. package/dist/config/env.js +0 -2
  11. package/dist/config/env.js.map +1 -1
  12. package/dist/config/types.d.ts +30 -34
  13. package/dist/config/types.d.ts.map +1 -1
  14. package/dist/config/types.js.map +1 -1
  15. package/dist/index.js +33 -18
  16. package/dist/index.js.map +1 -1
  17. package/dist/lib/abort-signals.d.ts +2 -0
  18. package/dist/lib/abort-signals.d.ts.map +1 -0
  19. package/dist/lib/abort-signals.js +5 -0
  20. package/dist/lib/abort-signals.js.map +1 -0
  21. package/dist/lib/errors.d.ts +2 -5
  22. package/dist/lib/errors.d.ts.map +1 -1
  23. package/dist/lib/errors.js +36 -64
  24. package/dist/lib/errors.js.map +1 -1
  25. package/dist/lib/llm-client.d.ts +5 -1
  26. package/dist/lib/llm-client.d.ts.map +1 -1
  27. package/dist/lib/llm-client.js +4 -0
  28. package/dist/lib/llm-client.js.map +1 -1
  29. package/dist/lib/llm-json.d.ts.map +1 -1
  30. package/dist/lib/llm-json.js +75 -4
  31. package/dist/lib/llm-json.js.map +1 -1
  32. package/dist/lib/llm-providers/helpers.d.ts +14 -0
  33. package/dist/lib/llm-providers/helpers.d.ts.map +1 -0
  34. package/dist/lib/llm-providers/helpers.js +45 -0
  35. package/dist/lib/llm-providers/helpers.js.map +1 -0
  36. package/dist/lib/llm-providers.d.ts +3 -0
  37. package/dist/lib/llm-providers.d.ts.map +1 -1
  38. package/dist/lib/llm-providers.js +35 -65
  39. package/dist/lib/llm-providers.js.map +1 -1
  40. package/dist/lib/llm.d.ts +1 -1
  41. package/dist/lib/llm.d.ts.map +1 -1
  42. package/dist/lib/llm.js +4 -11
  43. package/dist/lib/llm.js.map +1 -1
  44. package/dist/lib/output-normalization.d.ts +7 -0
  45. package/dist/lib/output-normalization.d.ts.map +1 -0
  46. package/dist/lib/output-normalization.js +74 -0
  47. package/dist/lib/output-normalization.js.map +1 -0
  48. package/dist/lib/output-validation.d.ts +11 -0
  49. package/dist/lib/output-validation.d.ts.map +1 -0
  50. package/dist/lib/output-validation.js +144 -0
  51. package/dist/lib/output-validation.js.map +1 -0
  52. package/dist/lib/prompt-policy.d.ts +0 -2
  53. package/dist/lib/prompt-policy.d.ts.map +1 -1
  54. package/dist/lib/prompt-policy.js +6 -2
  55. package/dist/lib/prompt-policy.js.map +1 -1
  56. package/dist/lib/retry.d.ts.map +1 -1
  57. package/dist/lib/retry.js +17 -10
  58. package/dist/lib/retry.js.map +1 -1
  59. package/dist/lib/technique-templates/format-instructions.d.ts +3 -0
  60. package/dist/lib/technique-templates/format-instructions.d.ts.map +1 -0
  61. package/dist/lib/technique-templates/format-instructions.js +42 -0
  62. package/dist/lib/technique-templates/format-instructions.js.map +1 -0
  63. package/dist/lib/technique-templates/templates-advanced.d.ts +5 -0
  64. package/dist/lib/technique-templates/templates-advanced.d.ts.map +1 -0
  65. package/dist/lib/technique-templates/templates-advanced.js +139 -0
  66. package/dist/lib/technique-templates/templates-advanced.js.map +1 -0
  67. package/dist/lib/technique-templates/templates-basic.d.ts +5 -0
  68. package/dist/lib/technique-templates/templates-basic.d.ts.map +1 -0
  69. package/dist/lib/technique-templates/templates-basic.js +129 -0
  70. package/dist/lib/technique-templates/templates-basic.js.map +1 -0
  71. package/dist/lib/technique-templates.d.ts +1 -1
  72. package/dist/lib/technique-templates.d.ts.map +1 -1
  73. package/dist/lib/technique-templates.js +12 -342
  74. package/dist/lib/technique-templates.js.map +1 -1
  75. package/dist/lib/tool-formatters.d.ts +13 -0
  76. package/dist/lib/tool-formatters.d.ts.map +1 -0
  77. package/dist/lib/tool-formatters.js +26 -0
  78. package/dist/lib/tool-formatters.js.map +1 -0
  79. package/dist/lib/tool-helpers.d.ts +8 -1
  80. package/dist/lib/tool-helpers.d.ts.map +1 -1
  81. package/dist/lib/tool-helpers.js +32 -7
  82. package/dist/lib/tool-helpers.js.map +1 -1
  83. package/dist/lib/tool-resources.d.ts +3 -0
  84. package/dist/lib/tool-resources.d.ts.map +1 -0
  85. package/dist/lib/tool-resources.js +23 -0
  86. package/dist/lib/tool-resources.js.map +1 -0
  87. package/dist/lib/validation.d.ts +0 -1
  88. package/dist/lib/validation.d.ts.map +1 -1
  89. package/dist/lib/validation.js +0 -6
  90. package/dist/lib/validation.js.map +1 -1
  91. package/dist/prompts/quick-workflows.d.ts.map +1 -1
  92. package/dist/prompts/quick-workflows.js +13 -7
  93. package/dist/prompts/quick-workflows.js.map +1 -1
  94. package/dist/schemas/index.d.ts +0 -1
  95. package/dist/schemas/index.d.ts.map +1 -1
  96. package/dist/schemas/index.js +0 -1
  97. package/dist/schemas/index.js.map +1 -1
  98. package/dist/schemas/inputs.d.ts +4 -4
  99. package/dist/schemas/inputs.d.ts.map +1 -1
  100. package/dist/schemas/inputs.js +33 -2
  101. package/dist/schemas/inputs.js.map +1 -1
  102. package/dist/schemas/llm-responses.d.ts +8 -78
  103. package/dist/schemas/llm-responses.d.ts.map +1 -1
  104. package/dist/schemas/llm-responses.js +3 -3
  105. package/dist/schemas/llm-responses.js.map +1 -1
  106. package/dist/schemas/outputs.d.ts +150 -102
  107. package/dist/schemas/outputs.d.ts.map +1 -1
  108. package/dist/schemas/outputs.js +44 -13
  109. package/dist/schemas/outputs.js.map +1 -1
  110. package/dist/server.d.ts.map +1 -1
  111. package/dist/server.js +6 -2
  112. package/dist/server.js.map +1 -1
  113. package/dist/tools/analyze-prompt.d.ts.map +1 -1
  114. package/dist/tools/analyze-prompt.js +105 -161
  115. package/dist/tools/analyze-prompt.js.map +1 -1
  116. package/dist/tools/optimize-prompt/formatters.d.ts +2 -0
  117. package/dist/tools/optimize-prompt/formatters.d.ts.map +1 -0
  118. package/dist/tools/optimize-prompt/formatters.js +57 -0
  119. package/dist/tools/optimize-prompt/formatters.js.map +1 -0
  120. package/dist/tools/optimize-prompt.d.ts.map +1 -1
  121. package/dist/tools/optimize-prompt.js +306 -155
  122. package/dist/tools/optimize-prompt.js.map +1 -1
  123. package/dist/tools/refine-prompt.d.ts.map +1 -1
  124. package/dist/tools/refine-prompt.js +73 -36
  125. package/dist/tools/refine-prompt.js.map +1 -1
  126. package/dist/tools/validate-prompt/prompt.d.ts +2 -0
  127. package/dist/tools/validate-prompt/prompt.d.ts.map +1 -0
  128. package/dist/tools/validate-prompt/prompt.js +40 -0
  129. package/dist/tools/validate-prompt/prompt.js.map +1 -0
  130. package/dist/tools/validate-prompt.d.ts.map +1 -1
  131. package/dist/tools/validate-prompt.js +108 -152
  132. package/dist/tools/validate-prompt.js.map +1 -1
  133. package/package.json +5 -2
  134. package/src/config/constants.ts +4 -2
  135. package/src/config/env.ts +0 -3
  136. package/src/config/types.ts +38 -34
  137. package/src/index.ts +43 -23
  138. package/src/lib/abort-signals.ts +7 -0
  139. package/src/lib/errors.ts +60 -103
  140. package/src/lib/llm-client.ts +9 -1
  141. package/src/lib/llm-json.ts +92 -3
  142. package/src/lib/llm-providers/helpers.ts +78 -0
  143. package/src/lib/llm-providers.ts +55 -83
  144. package/src/lib/llm.ts +6 -13
  145. package/src/lib/output-normalization.ts +100 -0
  146. package/src/lib/output-validation.ts +183 -0
  147. package/src/lib/prompt-policy.ts +9 -2
  148. package/src/lib/retry.ts +27 -9
  149. package/src/lib/technique-templates/format-instructions.ts +45 -0
  150. package/src/lib/technique-templates/templates-advanced.ts +147 -0
  151. package/src/lib/technique-templates/templates-basic.ts +137 -0
  152. package/src/lib/technique-templates.ts +13 -350
  153. package/src/lib/tool-formatters.ts +46 -0
  154. package/src/lib/tool-helpers.ts +50 -12
  155. package/src/lib/tool-resources.ts +31 -0
  156. package/src/lib/validation.ts +0 -7
  157. package/src/prompts/quick-workflows.ts +12 -7
  158. package/src/schemas/index.ts +0 -7
  159. package/src/schemas/inputs.ts +36 -5
  160. package/src/schemas/llm-responses.ts +3 -13
  161. package/src/schemas/outputs.ts +50 -13
  162. package/src/server.ts +8 -3
  163. package/src/tools/analyze-prompt.ts +135 -179
  164. package/src/tools/optimize-prompt/formatters.ts +70 -0
  165. package/src/tools/optimize-prompt.ts +495 -179
  166. package/src/tools/refine-prompt.ts +150 -55
  167. package/src/tools/validate-prompt/prompt.ts +40 -0
  168. package/src/tools/validate-prompt.ts +172 -177
  169. package/tests/llm-json.test.ts +17 -0
  170. package/src/lib/cache.ts +0 -52
  171. package/src/resources/index.ts +0 -3
package/AGENTS.md CHANGED
@@ -2,38 +2,38 @@
2
2
 
3
3
  ## Project Structure & Module Organization
4
4
 
5
- - `src/` contains TypeScript source. Key entry points: `src/index.ts` and `src/server.ts`. Feature areas include `src/tools/`, `src/resources/`, `src/prompts/`, `src/schemas/`, `src/config/`, and `src/lib/`.
6
- - `tests/` holds Vitest suites (for example, `tests/integration.test.ts`).
7
- - `docs/` contains documentation and assets such as `docs/logo.png`.
8
- - `dist/` is generated build output; do not edit directly.
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
- - `npm run build`: compile TypeScript to `dist/` and mark `dist/index.js` executable.
13
- - `npm run dev` / `npm run dev:http`: run the server from `src/` in watch mode (stdio or 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
14
  - `npm run start` / `npm run start:http`: run the compiled server from `dist/`.
15
- - `npm run test`: run Vitest once; `npm run test:watch` for watch mode.
16
- - `npm run lint`: ESLint checks; `npm run format`: Prettier formatting; `npm run type-check`: TypeScript without emit.
17
- - `npm run inspector`: launch the MCP inspector against `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.
18
18
 
19
19
  ## Coding Style & Naming Conventions
20
20
 
21
- - Formatting is enforced by Prettier: 2-space indentation, single quotes, semicolons, 80-char print width.
22
- - ESLint with typescript-eslint is strict: no unused imports, no `any`, prefer type-only imports, explicit return types.
23
- - Naming: camelCase for variables/functions, PascalCase for types/classes, UPPER_CASE for constants. Leading underscores are allowed for intentionally unused args.
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.
24
25
 
25
26
  ## Testing Guidelines
26
27
 
27
- - Tests use Vitest and live in `tests/` using `*.test.ts` filenames.
28
- - Integration tests require an API key (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GOOGLE_API_KEY`) and a built `dist/` (`npm run build`). If no key is set, integration tests are skipped.
29
- - Keep unit tests fast; add integration coverage for new tools/resources when behavior depends on the running server.
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.
30
30
 
31
31
  ## Commit & Pull Request Guidelines
32
32
 
33
- - Commit subjects in this repo are short, descriptive, imperative sentences (for example, "Refactor cache configuration..."). Version bumps may be bare tags like `1.0.4`.
34
- - Before opening a PR, run `npm run lint`, `npm run type-check`, and `npm run test`.
35
- - PRs should describe the change, include test commands run, and update `README.md` or `CONFIGURATION.md` when behavior or env vars change.
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.
36
35
 
37
- ## Security & Configuration
36
+ ## Security & Configuration Tips
38
37
 
39
- - Runtime configuration is via environment variables documented in `CONFIGURATION.md`. Never commit API keys; prefer MCP client config or a local `.env` file.
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
- ## Environment Variables
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
- All configuration is done through environment variables. Set them in your MCP client configuration (e.g., `mcp.json` for VS Code) or in a `.env` file.
5
+ ## Required configuration
6
6
 
7
- ### Required Configuration
7
+ You must pick a provider and supply its API key.
8
8
 
9
- | Variable | Description | Default | Example |
10
- | ------------------- | ----------------------- | ----------------- | ------------------------------------------------------------------------------------ |
11
- | `LLM_PROVIDER` | LLM provider to use | `openai` | `openai`, `anthropic`, `google` |
12
- | `OPENAI_API_KEY` | OpenAI API key | - | `sk-...` |
13
- | `ANTHROPIC_API_KEY` | Anthropic API key | - | `sk-ant-...` |
14
- | `GOOGLE_API_KEY` | Google Gemini API key | - | `AIzaSy...` |
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
- **Note**: Only provide the API key for your chosen provider.
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
- ### Performance & Limits (Optional)
18
+ ## Provider defaults
20
19
 
21
- | Variable | Description | Default | Recommended Range |
22
- | ------------------- | ------------------------- | --------------- | ----------------------- |
23
- | `LLM_TIMEOUT_MS` | LLM request timeout (ms) | `60000` (1 min) | 30000-120000 |
24
- | `LLM_MAX_TOKENS` | Max tokens per response | `8000` | 2000-16000 (pro: 8000+) |
25
- | `MAX_PROMPT_LENGTH` | Max prompt length (chars) | `10000` | 5000-50000 |
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
- ### Retry Configuration (Optional)
26
+ Set `LLM_MODEL` to override the default model for the chosen provider.
29
27
 
30
- | Variable | Description | Default | Recommended Range |
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
- ### Logging & Debugging (Optional)
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
- | Variable | Description | Default | Options |
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
- **Security Note**: When `INCLUDE_ERROR_CONTEXT=true`, error responses may include up to 500 characters of the prompt that caused the error. Only enable this in development.
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
- ### Provider-Specific (Optional)
42
+ ### Tool token caps
48
43
 
49
- | Variable | Description | Default | Options |
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
- ## Example Configurations
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
- ### Minimal (Production)
53
+ ## Retry behavior (optional)
56
54
 
57
- ```json
58
- {
59
- "prompttuner": {
60
- "command": "node",
61
- "args": ["/path/to/prompttuner-mcp/dist/index.js"],
62
- "env": {
63
- "LLM_PROVIDER": "openai",
64
- "OPENAI_API_KEY": "${input:openai-api-key}"
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
- ### Performance Tuned
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
- "prompttuner": {
75
- "command": "node",
76
- "args": ["/path/to/prompttuner-mcp/dist/index.js"],
77
- "env": {
78
- "LLM_PROVIDER": "anthropic",
79
- "ANTHROPIC_API_KEY": "${input:anthropic-api-key}",
80
- "LLM_MODEL": "claude-3-5-sonnet-20241022",
81
- "LLM_TIMEOUT_MS": "90000",
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
- ### Pro Models (Gemini 2.5 Pro, GPT-4o)
108
+ ### From source (dist build)
91
109
 
92
110
  ```json
93
111
  {
94
- "prompttuner": {
95
- "command": "node",
96
- "args": ["/path/to/prompttuner-mcp/dist/index.js"],
97
- "env": {
98
- "LLM_PROVIDER": "google",
99
- "GOOGLE_API_KEY": "${input:google-api-key}",
100
- "LLM_MODEL": "gemini-2.5-pro-exp",
101
- "LLM_TIMEOUT_MS": "120000",
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
- ### Development/Debug
125
+ ### Performance tuned
110
126
 
111
127
  ```json
112
128
  {
113
- "prompttuner": {
114
- "command": "node",
115
- "args": ["/path/to/prompttuner-mcp/dist/index.js"],
116
- "env": {
117
- "LLM_PROVIDER": "google",
118
- "GOOGLE_API_KEY": "${input:google-api-key}",
119
- "LLM_MODEL": "gemini-2.0-flash-exp",
120
- "LOG_FORMAT": "json",
121
- "DEBUG": "true",
122
- "INCLUDE_ERROR_CONTEXT": "true"
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 Volume / Low Latency
146
+ ### High volume / low latency
129
147
 
130
148
  ```json
131
149
  {
132
- "prompttuner": {
133
- "command": "node",
134
- "args": ["/path/to/prompttuner-mcp/dist/index.js"],
135
- "env": {
136
- "LLM_PROVIDER": "openai",
137
- "OPENAI_API_KEY": "${input:openai-api-key}",
138
- "LLM_MODEL": "gpt-4o-mini",
139
- "LLM_TIMEOUT_MS": "30000",
140
- "LLM_MAX_TOKENS": "1500",
141
- "CACHE_MAX_SIZE": "5000",
142
- "RETRY_MAX_ATTEMPTS": "2",
143
- "RETRY_BASE_DELAY_MS": "500"
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's NOT Configurable (and Why)
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
- ### Analysis Constants
170
+ The following behaviors are hardcoded for stability:
159
171
 
160
- - **Pattern matching regex** for detecting prompt characteristics
161
- - **Reason**: Complex regex patterns that work across all use cases
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
- ### LLM Behavior
178
+ ## Migration notes (older configs)
164
179
 
165
- - **Temperature** (0.7 for refinement tasks)
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
- ### Internal Limits
169
-
170
- - **Analysis max tokens** (1500)
171
- - **Analysis timeout** (60000ms)
172
- - **Max LLM response length** (500,000 chars)
173
- - **Error context truncation** (500 chars)
174
- - **Reason**: Safety constraints to prevent resource exhaustion
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
- ### High Memory Usage
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
- - Increase `LLM_TIMEOUT_MS` (e.g., `90000`)
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
- ### Rate Limit Errors
197
+ ### Timeout errors
204
198
 
205
- - Increase `RETRY_BASE_DELAY_MS` (e.g., `2000`)
206
- - Increase `RETRY_MAX_ATTEMPTS` (e.g., `5`)
199
+ - Increase `LLM_TIMEOUT_MS` or `RETRY_TOTAL_TIMEOUT_MS`.
200
+ - Reduce `LLM_MAX_TOKENS`.
207
201
 
208
- ### Slow Performance
202
+ ### Rate limit errors
209
203
 
210
- - Increase `CACHE_MAX_SIZE` (e.g., `2000`)
211
- - Use faster model (e.g., `gpt-4o-mini` or `gemini-2.0-flash-exp`)
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
- ### Debug Logging Not Showing
207
+ ### Slow performance
215
208
 
216
- - Set `DEBUG=true`
217
- - Check logs are going to stderr (where MCP logs are captured)
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 Practices
212
+ ## Best practices
220
213
 
221
- 1. **Always set only one API key** - Only configure the key for your chosen provider
222
- 2. **Use input variables for secrets** - In mcp.json: `"OPENAI_API_KEY": "${input:openai-api-key}"`
223
- 3. **Start with defaults** - Only override what you need
224
- 4. **Enable debug logging temporarily** - `DEBUG=true` for troubleshooting only
225
- 5. **Monitor cache hit rate** - Check logs for "Cache hit for refinement" messages
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).