PromptTuner MCP
](https://www.npmjs.com/package/@j0hanz/prompt-tuner-mcp-server)  ](https://nodejs.org/)
PromptTuner MCP是一个MCP服务器,它使用OpenAI、Anthropic或Google Gemini修复和增强提示。
它的作用
- 验证和修剪输入提示(强制执行
MAX_PROMPT_LENGTH). - 将提示作为JSON封装在哨兵标记(净化标记、双向控制字符和空字节)内。
- 呼叫所选提供商。
- 规范LLM输出(如果存在,则对围栏/标签进行条带编码)。
- 返回人类可读的文本和机器友好的文本
structuredContent.
特性
- 打磨并完善提示,使其清晰流畅(
fix_prompt). - 提高和增强清晰度和有效性的提示(
boost_prompt). - 为复杂任务制定可重用的工作流提示(
crafting_prompt). - 结构简单的输出。
- 针对短暂的提供程序故障,使用指数回退重试逻辑。
快速开始
PromptTuner仅在stdio上运行。这 dev:http 和 start:http 脚本是兼容性别名(还没有HTTP传输)。
克劳德桌面版
添加到 claude_desktop_config.json:
{
"mcpServers": {
"prompttuner": {
"command": "npx",
"args": ["-y", "@j0hanz/prompt-tuner-mcp-server@latest"],
"env": {
"LLM_PROVIDER": "openai",
"OPENAI_API_KEY": "sk-..."
}
}
}
}使用首选LLM替换API密钥和提供程序。仅配置活动提供程序的密钥。
配置
PromptTuner使用最小配置。设置提供程序和API密钥,您就可以开始了。
| 变量 | 默认值 | 描述 |
|---|---|---|
LLM_PROVIDER | openai | openai, anthropic,或 google. |
OPENAI_API_KEY | - | 所有工具在以下情况下都需要 LLM_PROVIDER=openai. |
ANTHROPIC_API_KEY | - | 所有工具在以下情况下都需要 LLM_PROVIDER=anthropic. |
GOOGLE_API_KEY | - | 所有工具在以下情况下都需要 LLM_PROVIDER=google. |
LLM_MODEL | - | 覆盖默认模型。 |
DEBUG | false | 启用调试日志记录。 |
所有工具都支持LLM,并且需要所选提供程序的API密钥。
违约模型
| 提供者 | 默认模型 |
|---|---|
openai | gpt-4o |
anthropic | claude-3-5-sonnet-20241022 |
google | gemini-2.0-flash-exp |
CLI选项
| 标志 | 描述 |
|---|---|
-h, --help | 显示帮助文本。 |
-v, --version | 打印版本。 |
--debug / --no-debug | 启用/禁用调试日志记录。 |
| `--llm-provider | |
| ` | openai, anthropic,或 google. |
--llm-model | 替代默认模型。 |
工具
所有工具都接受纯文本、Markdown或XML提示。回应包括 content (人类可读)和 structuredContent (机器可读)。 输入是严格的:多余的字段被拒绝。对于 fix_prompt/boost_prompt,只有 prompt 字段已被接受。
fix_prompt
在保持意图和结构的同时,打磨和完善提示,使其清晰流畅。
| 参数 | 类型 | 必填 | 备注 |
|---|---|---|---|
prompt | string | 是 | 已修剪,长度已检查;额外字段被拒绝。 |
退货: ok, fixed.
boost_front
优化和增强提示,以提高清晰度和有效性。
| 参数 | 类型 | 必填 | 备注 |
|---|---|---|---|
prompt | string | 是 | 已修剪,长度已检查;额外字段被拒绝。 |
退货: ok, boosted.
手工制作_赠品
基于原始请求和一些设置,为复杂任务生成结构化、可重用的工作流提示。
| 参数 | 类型 | 必填 | 备注 |
|---|---|---|---|
request | string | 是 | 已修剪,长度已检查;严格投入。 |
constraints | string | 否 | 难以执行的要求(建议使用项目符号列表)。 |
mode | string | 否 | general, plan, review, troubleshoot. |
approach | string | 否 | conservative, balanced, creative. |
tone | string | 否 | direct, neutral, friendly. |
verbosity | string | 否 | brief, normal, detailed. |
退货: ok, prompt, settings.
响应格式
content:内容块数组。第一个块是JSONstructuredContent,第二个是简短的人类信息(或Error: ...).structuredContent:机器可解析的结果。- 错误返回
structuredContent.ok=false和aerror对象与code,message,可选context(消毒,最多200个字符),details,以及recoveryHint. - 错误响应还包括
isError: true.
发展
先决条件
- Node.js>=22.0.0
- npm
脚本
| 命令 | 描述 |
|---|---|
npm run build | 编译TypeScript并设置权限。 |
npm run prepare | 基于安装构建(发布助手)。 |
npm run dev | 在监视模式下从源代码运行。 |
npm run dev:http | 别名 npm run dev (还没有HTTP传输)。 |
npm run watch | TypeScript编译器处于监视模式。 |
npm run start | 从以下位置运行编译后的服务器 dist/. |
npm run start:http | 别名 npm run start (还没有HTTP传输)。 |
npm run test | 快跑 node:test 一次。 |
npm run test:coverage | 快跑 node:test 具有实验覆盖率。 |
npm run test:watch | 快跑 node:test 在手表模式下。 |
npm run lint | 运行ESLint。 |
npm run format | 运行Prettier。 |
npm run type-check | TypeScript类型检查。 |
npm run inspector | 运行MCP检查器 dist/index.js. |
npm run inspector:http | 别名 npm run inspector (还没有HTTP传输)。 |
npm run duplication | 运行jscpd复制报告。 |
npm run prepublishOnly | 发布前进行Lint、类型检查和构建。 |
项目结构
src/
index.ts Entry point
cli.ts CLI parsing, logging bootstrap, shutdown handling
server.ts MCP server setup (stdio transport)
tools.ts Tool implementations
schemas.ts Zod input/output schemas
config.ts Configuration and constants
types.ts Shared types and error codes
lib/ Shared utilities (LLM, retry, telemetry, prompt utils)
tests/ node:test suites
dist/ Compiled output (generated)
docs/ Static assets安全
- API密钥只能通过环境变量提供。
- 输入通过Zod和额外的长度检查进行验证。
- 错误上下文包含在调试模式中(经过净化并截断为200个字符)。
- Google安全过滤器始终处于启用状态。
贡献
欢迎拉取请求。请包括一个简短的总结、测试运行,并注意任何配置更改。
许可证
MIT许可证。看 LICENSE 了解详情。
