@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.
Files changed (229) hide show
  1. package/AGENTS.md +20 -23
  2. package/CONFIGURATION.md +150 -159
  3. package/README.md +136 -226
  4. package/dist/config/constants.d.ts +4 -3
  5. package/dist/config/constants.d.ts.map +1 -1
  6. package/dist/config/constants.js +4 -3
  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/instructions.d.ts +1 -1
  13. package/dist/config/instructions.d.ts.map +1 -1
  14. package/dist/config/instructions.js +21 -43
  15. package/dist/config/instructions.js.map +1 -1
  16. package/dist/config/types.d.ts +30 -57
  17. package/dist/config/types.d.ts.map +1 -1
  18. package/dist/config/types.js +0 -7
  19. package/dist/config/types.js.map +1 -1
  20. package/dist/config/typos.d.ts.map +1 -1
  21. package/dist/config/typos.js +1 -4
  22. package/dist/config/typos.js.map +1 -1
  23. package/dist/index.js +93 -9
  24. package/dist/index.js.map +1 -1
  25. package/dist/lib/abort-signals.d.ts +2 -0
  26. package/dist/lib/abort-signals.d.ts.map +1 -0
  27. package/dist/lib/abort-signals.js +5 -0
  28. package/dist/lib/abort-signals.js.map +1 -0
  29. package/dist/lib/cache.d.ts +0 -1
  30. package/dist/lib/cache.d.ts.map +1 -1
  31. package/dist/lib/cache.js +0 -4
  32. package/dist/lib/cache.js.map +1 -1
  33. package/dist/lib/errors.d.ts +3 -7
  34. package/dist/lib/errors.d.ts.map +1 -1
  35. package/dist/lib/errors.js +52 -51
  36. package/dist/lib/errors.js.map +1 -1
  37. package/dist/lib/llm-client.d.ts +5 -1
  38. package/dist/lib/llm-client.d.ts.map +1 -1
  39. package/dist/lib/llm-client.js +4 -0
  40. package/dist/lib/llm-client.js.map +1 -1
  41. package/dist/lib/llm-json.d.ts.map +1 -1
  42. package/dist/lib/llm-json.js +67 -1
  43. package/dist/lib/llm-json.js.map +1 -1
  44. package/dist/lib/llm-providers/helpers.d.ts +14 -0
  45. package/dist/lib/llm-providers/helpers.d.ts.map +1 -0
  46. package/dist/lib/llm-providers/helpers.js +45 -0
  47. package/dist/lib/llm-providers/helpers.js.map +1 -0
  48. package/dist/lib/llm-providers.d.ts +2 -0
  49. package/dist/lib/llm-providers.d.ts.map +1 -1
  50. package/dist/lib/llm-providers.js +28 -67
  51. package/dist/lib/llm-providers.js.map +1 -1
  52. package/dist/lib/llm-runtime.d.ts +1 -1
  53. package/dist/lib/llm-runtime.d.ts.map +1 -1
  54. package/dist/lib/llm-runtime.js +8 -6
  55. package/dist/lib/llm-runtime.js.map +1 -1
  56. package/dist/lib/llm.d.ts +1 -1
  57. package/dist/lib/llm.d.ts.map +1 -1
  58. package/dist/lib/llm.js +4 -11
  59. package/dist/lib/llm.js.map +1 -1
  60. package/dist/lib/output-normalization.d.ts +7 -0
  61. package/dist/lib/output-normalization.d.ts.map +1 -0
  62. package/dist/lib/output-normalization.js +65 -0
  63. package/dist/lib/output-normalization.js.map +1 -0
  64. package/dist/lib/output-validation.d.ts +11 -0
  65. package/dist/lib/output-validation.d.ts.map +1 -0
  66. package/dist/lib/output-validation.js +128 -0
  67. package/dist/lib/output-validation.js.map +1 -0
  68. package/dist/lib/prompt-analysis/scoring.d.ts.map +1 -1
  69. package/dist/lib/prompt-analysis/scoring.js +7 -3
  70. package/dist/lib/prompt-analysis/scoring.js.map +1 -1
  71. package/dist/lib/prompt-analysis.d.ts +0 -2
  72. package/dist/lib/prompt-analysis.d.ts.map +1 -1
  73. package/dist/lib/prompt-analysis.js +0 -2
  74. package/dist/lib/prompt-analysis.js.map +1 -1
  75. package/dist/lib/prompt-policy.d.ts +3 -0
  76. package/dist/lib/prompt-policy.d.ts.map +1 -0
  77. package/dist/lib/prompt-policy.js +16 -0
  78. package/dist/lib/prompt-policy.js.map +1 -0
  79. package/dist/lib/retry.d.ts +1 -1
  80. package/dist/lib/retry.d.ts.map +1 -1
  81. package/dist/lib/retry.js +35 -13
  82. package/dist/lib/retry.js.map +1 -1
  83. package/dist/lib/technique-templates/format-instructions.d.ts +3 -0
  84. package/dist/lib/technique-templates/format-instructions.d.ts.map +1 -0
  85. package/dist/lib/technique-templates/format-instructions.js +42 -0
  86. package/dist/lib/technique-templates/format-instructions.js.map +1 -0
  87. package/dist/lib/technique-templates/templates-advanced.d.ts +5 -0
  88. package/dist/lib/technique-templates/templates-advanced.d.ts.map +1 -0
  89. package/dist/lib/technique-templates/templates-advanced.js +139 -0
  90. package/dist/lib/technique-templates/templates-advanced.js.map +1 -0
  91. package/dist/lib/technique-templates/templates-basic.d.ts +5 -0
  92. package/dist/lib/technique-templates/templates-basic.d.ts.map +1 -0
  93. package/dist/lib/technique-templates/templates-basic.js +129 -0
  94. package/dist/lib/technique-templates/templates-basic.js.map +1 -0
  95. package/dist/lib/technique-templates.d.ts +1 -1
  96. package/dist/lib/technique-templates.d.ts.map +1 -1
  97. package/dist/lib/technique-templates.js +15 -318
  98. package/dist/lib/technique-templates.js.map +1 -1
  99. package/dist/lib/tool-formatters.d.ts +13 -0
  100. package/dist/lib/tool-formatters.d.ts.map +1 -0
  101. package/dist/lib/tool-formatters.js +26 -0
  102. package/dist/lib/tool-formatters.js.map +1 -0
  103. package/dist/lib/tool-helpers.d.ts +8 -1
  104. package/dist/lib/tool-helpers.d.ts.map +1 -1
  105. package/dist/lib/tool-helpers.js +32 -7
  106. package/dist/lib/tool-helpers.js.map +1 -1
  107. package/dist/lib/tool-resources.d.ts +3 -0
  108. package/dist/lib/tool-resources.d.ts.map +1 -0
  109. package/dist/lib/tool-resources.js +23 -0
  110. package/dist/lib/tool-resources.js.map +1 -0
  111. package/dist/lib/validation.d.ts +0 -2
  112. package/dist/lib/validation.d.ts.map +1 -1
  113. package/dist/lib/validation.js +0 -13
  114. package/dist/lib/validation.js.map +1 -1
  115. package/dist/prompts/quick-workflows.d.ts.map +1 -1
  116. package/dist/prompts/quick-workflows.js +127 -219
  117. package/dist/prompts/quick-workflows.js.map +1 -1
  118. package/dist/resources/index.d.ts +1 -2
  119. package/dist/resources/index.d.ts.map +1 -1
  120. package/dist/resources/index.js +2 -3
  121. package/dist/resources/index.js.map +1 -1
  122. package/dist/resources/prompt-templates.d.ts.map +1 -1
  123. package/dist/resources/prompt-templates.js +3 -12
  124. package/dist/resources/prompt-templates.js.map +1 -1
  125. package/dist/schemas/index.d.ts +2 -3
  126. package/dist/schemas/index.d.ts.map +1 -1
  127. package/dist/schemas/index.js +2 -3
  128. package/dist/schemas/index.js.map +1 -1
  129. package/dist/schemas/inputs.d.ts +4 -27
  130. package/dist/schemas/inputs.d.ts.map +1 -1
  131. package/dist/schemas/inputs.js +0 -17
  132. package/dist/schemas/inputs.js.map +1 -1
  133. package/dist/schemas/llm-responses.d.ts +11 -186
  134. package/dist/schemas/llm-responses.d.ts.map +1 -1
  135. package/dist/schemas/llm-responses.js +8 -19
  136. package/dist/schemas/llm-responses.js.map +1 -1
  137. package/dist/schemas/outputs.d.ts +149 -350
  138. package/dist/schemas/outputs.d.ts.map +1 -1
  139. package/dist/schemas/outputs.js +47 -74
  140. package/dist/schemas/outputs.js.map +1 -1
  141. package/dist/server.d.ts.map +1 -1
  142. package/dist/server.js +6 -5
  143. package/dist/server.js.map +1 -1
  144. package/dist/tools/analyze-prompt.d.ts.map +1 -1
  145. package/dist/tools/analyze-prompt.js +121 -168
  146. package/dist/tools/analyze-prompt.js.map +1 -1
  147. package/dist/tools/compare-prompts.d.ts.map +1 -1
  148. package/dist/tools/compare-prompts.js +48 -31
  149. package/dist/tools/compare-prompts.js.map +1 -1
  150. package/dist/tools/detect-format.d.ts.map +1 -1
  151. package/dist/tools/detect-format.js +49 -39
  152. package/dist/tools/detect-format.js.map +1 -1
  153. package/dist/tools/index.d.ts.map +1 -1
  154. package/dist/tools/index.js +0 -4
  155. package/dist/tools/index.js.map +1 -1
  156. package/dist/tools/optimize-prompt/formatters.d.ts +2 -0
  157. package/dist/tools/optimize-prompt/formatters.d.ts.map +1 -0
  158. package/dist/tools/optimize-prompt/formatters.js +57 -0
  159. package/dist/tools/optimize-prompt/formatters.js.map +1 -0
  160. package/dist/tools/optimize-prompt.d.ts.map +1 -1
  161. package/dist/tools/optimize-prompt.js +156 -147
  162. package/dist/tools/optimize-prompt.js.map +1 -1
  163. package/dist/tools/refine-prompt.d.ts.map +1 -1
  164. package/dist/tools/refine-prompt.js +66 -38
  165. package/dist/tools/refine-prompt.js.map +1 -1
  166. package/dist/tools/validate-prompt/prompt.d.ts +2 -0
  167. package/dist/tools/validate-prompt/prompt.d.ts.map +1 -0
  168. package/dist/tools/validate-prompt/prompt.js +40 -0
  169. package/dist/tools/validate-prompt/prompt.js.map +1 -0
  170. package/dist/tools/validate-prompt.d.ts.map +1 -1
  171. package/dist/tools/validate-prompt.js +113 -143
  172. package/dist/tools/validate-prompt.js.map +1 -1
  173. package/package.json +5 -4
  174. package/src/config/constants.ts +4 -3
  175. package/src/config/env.ts +0 -3
  176. package/src/config/instructions.ts +21 -43
  177. package/src/config/types.ts +36 -66
  178. package/src/index.ts +112 -10
  179. package/src/lib/abort-signals.ts +7 -0
  180. package/src/lib/errors.ts +90 -85
  181. package/src/lib/llm-client.ts +9 -1
  182. package/src/lib/llm-json.ts +85 -1
  183. package/src/lib/llm-providers/helpers.ts +78 -0
  184. package/src/lib/llm-providers.ts +59 -95
  185. package/src/lib/llm-runtime.ts +28 -21
  186. package/src/lib/llm.ts +6 -13
  187. package/src/lib/output-normalization.ts +91 -0
  188. package/src/lib/output-validation.ts +164 -0
  189. package/src/lib/prompt-analysis.ts +0 -5
  190. package/src/lib/prompt-policy.ts +18 -0
  191. package/src/lib/retry.ts +51 -13
  192. package/src/lib/technique-templates/format-instructions.ts +45 -0
  193. package/src/lib/technique-templates/templates-advanced.ts +147 -0
  194. package/src/lib/technique-templates/templates-basic.ts +137 -0
  195. package/src/lib/technique-templates.ts +16 -326
  196. package/src/lib/tool-formatters.ts +46 -0
  197. package/src/lib/tool-helpers.ts +50 -12
  198. package/src/lib/tool-resources.ts +31 -0
  199. package/src/lib/validation.ts +0 -15
  200. package/src/prompts/quick-workflows.ts +128 -230
  201. package/src/schemas/index.ts +0 -12
  202. package/src/schemas/inputs.ts +0 -19
  203. package/src/schemas/llm-responses.ts +8 -32
  204. package/src/schemas/outputs.ts +53 -79
  205. package/src/server.ts +8 -6
  206. package/src/tools/analyze-prompt.ts +158 -188
  207. package/src/tools/index.ts +0 -4
  208. package/src/tools/optimize-prompt/formatters.ts +70 -0
  209. package/src/tools/optimize-prompt.ts +258 -174
  210. package/src/tools/refine-prompt.ts +141 -60
  211. package/src/tools/validate-prompt/prompt.ts +40 -0
  212. package/src/tools/validate-prompt.ts +185 -167
  213. package/src/types/regexp-escape.d.ts +3 -0
  214. package/tests/llm-json.test.ts +17 -0
  215. package/tests/quick-workflows.test.ts +1 -34
  216. package/tsconfig.json +1 -1
  217. package/src/config/typos.ts +0 -121
  218. package/src/lib/cache.ts +0 -57
  219. package/src/lib/prompt-analysis/scoring.ts +0 -235
  220. package/src/lib/prompt-analysis/suggestions.ts +0 -115
  221. package/src/resources/index.ts +0 -7
  222. package/src/resources/prompt-templates/analysis.ts +0 -156
  223. package/src/resources/prompt-templates/coding.ts +0 -302
  224. package/src/resources/prompt-templates/data-extraction.ts +0 -122
  225. package/src/resources/prompt-templates/system-prompts.ts +0 -81
  226. package/src/resources/prompt-templates/writing.ts +0 -176
  227. package/src/resources/prompt-templates.ts +0 -203
  228. package/src/tools/compare-prompts.ts +0 -301
  229. 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/` contains the TypeScript source: server setup, tools, resources, prompts, schemas, and shared utilities.
6
- - `tests/` holds Vitest specs (for example `tests/server.test.ts`).
7
- - `docs/` contains documentation assets (logo, guides). `CONFIGURATION.md` documents environment variables.
8
- - `dist/` is the compiled output (do not edit by hand).
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
- Run commands from the repo root.
13
-
14
- - `npm install` installs dependencies.
15
- - `npm run build` compiles TypeScript and sets the executable bit on `dist/index.js`.
16
- - `npm run dev` runs the server in watch mode; `npm run dev:http` enables HTTP mode.
17
- - `npm start` runs the built server; `npm run start:http` enables HTTP mode.
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 ESM (`"type": "module"`). Prefer explicit return types and `type` imports.
25
- - Prettier enforces 2-space indentation, single quotes, semicolons, 80-char width, LF, and sorted imports.
26
- - ESLint is strict: no `any`, no unused imports, prefer `const`, and avoid floating promises.
27
- - Naming: `camelCase` for variables/functions, `PascalCase` for types/classes, `UPPER_CASE` for constants. Leading `_` is allowed for intentionally unused params.
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
- - Framework: Vitest (node environment). Test files live in `tests/**/*.test.ts`.
32
- - Add or update tests when changing tools, scoring logic, or server behavior.
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
- - Commit subjects in this repo are short, imperative, and sentence case (for example "Refactor cache handling"). Release commits may be version-only (for example "1.0.2").
37
- - PRs should include a clear description, reasoning, and the tests run. Update `README.md` or `CONFIGURATION.md` when changing tools, prompts, or environment variables.
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
- - Configure via environment variables only; do not commit secrets. Set exactly one provider API key for the chosen `LLM_PROVIDER`.
42
- - Be cautious with `INCLUDE_ERROR_CONTEXT=true` since it can include prompt excerpts in errors.
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).