AI提示优化工具

一个基于OTA框架的MCP服务器,用于自动分析和优化AI提示,提高提示的清晰度和安全性。

  • by grandinh
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 grandinh/mcp-prompt-optimizer

使用说明

MCP提示优化器

使用OTA(Optimize Then Answer)框架自动分析和优化AI提示的MCP服务器

🎯 它做什么

此MCP服务器提供 optimize_prompt 该工具:

  • 📊 分析提示 -计算清晰度分数(0-100%)并确定域
  • 🔍 检测风险 -标记安全、隐私、政策、安全和合规问题
  • ❓ 提出聪明的问题 -当清晰度<60%时,生成1-3个有针对性的问题
  • ✨ 增强提示 -添加特定领域的要求(代码测试、用户体验可访问性等)
  • 📋 提供结构 -返回经过优化的提示,可供人工智能处理

🚀 快速开始

安装

克劳德代码:

# Clone the repository
git clone https://github.com/grandinh/mcp-prompt-optimizer.git
cd mcp-prompt-optimizer

# Install dependencies
npm install

# Build
npm run build

添加到 .mcp.json:

{
  "mcpServers": {
    "prompt-optimizer": {
      "command": "node",
      "args": ["/path/to/mcp-prompt-optimizer/dist/index.js"],
      "description": "Optimizes prompts using the OTA Framework"
    }
  }
}

重新启动MCP客户端 (克劳德代码、光标等)

用法

选项1:直接使用MCP工具

安装后,使用 optimize_prompt 工具:

Use the optimize_prompt tool to analyze: "build a dashboard"

选项2:使用 /ori 斜线命令(克劳德代码)

这 /ori (优化研究实施)命令提供了一个具有智能多模型选择的自主工作流程:

/ori add JWT authentication to the Express API

这将: 0. 战略(Opus) -设计最优研究方案,选择最佳模型

  1. 研究(动态) -自动搜索文档、最佳实践和代码库
  2. 验证(Sonnet) -交叉验证发现并检查风险
  3. 实施(十四行诗/俳句) -应用更改并进行错误处理
  4. 文档(俳句) -更新README、CHANGELOG和其他文档

多型号优势:

  • 与所有Opus相比,成本降低40%
  • 执行速度提高30%
  • 每个模型都在其最佳区域中使用

看 /ori命令文档 了解详情。

输出:

[OPTIMIZED] Domain: code | Clarity: 30% | Risks: none

⚠️ Clarification Needed (Clarity: 30%)

Please answer these questions before I proceed:
1. What programming language or framework are you using?
2. What specific features or components are you building?
3. Do you need tests, validation, or specific security considerations?

回答后:

Use optimize_prompt tool: "build a React dashboard with user analytics,
chart visualizations using Chart.js, and real-time data updates.
Need responsive design and accessibility compliance."

输出:

[OPTIMIZED] Domain: code | Clarity: 85% | Risks: none

✓ Ready to Process (Clarity: 85%)

[Shows enhanced prompt with code-specific requirements including
security, testing, accessibility, and structured output format]

📊 特性

域检测

自动识别您的请求的域:

  • 代码 -编程、API、调试
  • 用户体验 -UI设计、界面、可访问性
  • 数据 -分析、统计、计算
  • 写作 -内容、文件、文章
  • 研究 -研究、调查、分析
  • 金融 -投资回报率、预算、定价
  • 产品 -特点、路线图、战略

清晰度评分

根据以下内容计算0-1的清晰度分数:

因素 重量 度量
目标清晰度 30% 目标是否明确且可衡量?
上下文完整性 25% 是否提供了输入/约束?
格式规范 15% 是否定义了输出格式?
成功标准 20% 是否规定了验收标准?
技术细节 10% 包括堆栈、版本和细节吗?

风险检测

标记潜在问题:

  • 安全 -身份验证、密码、令牌、漏洞
  • 隐私 -个人身份信息、电子邮件、电话、GDPR
  • 政策 -假冒、绕过、非法活动
  • 安全 -危害、危险内容
  • 合规 -医疗/法律/财务建议

聪明的问题

当清晰度<60%时,生成有针对性的问题:

代码域:

  • 什么编程语言或框架?
  • 什么具体特征/组件?
  • 测试/安全需求?

用户体验领域:

  • 目标用户是谁?
  • 什么平台(网络/移动)?

数据域:

  • 数据结构是什么?
  • 哪些具体指标?

领域特定增强

根据域添加要求:

代码:

- Include code summary and complexity notes
- Add security considerations
- Provide test plan and example I/O
- Include error handling

UX:

- Evaluate against usability heuristics
- Include accessibility checklist (WCAG 2.1 AA)
- Consider mobile responsiveness
- Address error and loading states

数据:

- Describe dataset shape and structure
- Show calculation steps explicitly
- Validate data and identify edge cases
- Make results reproducible

📖 例子

示例1:模糊请求

输入:

optimize_prompt: "help me with my app"

输出:

[OPTIMIZED] Domain: code | Clarity: 25% | Risks: none

⚠️ Clarification Needed

1. What programming language or framework are you using?
2. What specific feature or component are you building?

示例2:带安全性的清除请求

输入:

optimize_prompt: "Create a REST API for user authentication in Express.js.
Need endpoints for register, login, logout. Use JWT tokens with refresh
token rotation. Store passwords with bcrypt."

输出:

[OPTIMIZED] Domain: code | Clarity: 90% | Risks: security

✓ Ready to Process

**Domain:** code

**Requirements:**
- Include code summary and complexity notes
- **CRITICAL:** Address security concerns (auth, validation, token storage)
- Provide test plan and example I/O
- Include error handling

**Risk Flags:** security
Please address these concerns in your response.

示例3:UX请求

输入:

optimize_prompt: "Review my checkout flow for usability issues"

输出:

[OPTIMIZED] Domain: UX | Clarity: 70% | Risks: none

✓ Ready to Process

**Requirements:**
- Evaluate against usability heuristics
- Include accessibility checklist (WCAG 2.1 AA)
- Consider mobile responsiveness
- Address error and loading states

🔧 配置

调整清晰度阈值

编辑 src/index.ts:

const needsClarification = clarityScore < 0.6; // Change to 0.7 for stricter

更改问题限制

在 generateQuestions():

return questions.slice(0, 3); // Change to 2 for fewer questions

添加自定义域

添加到 detectDomain():

if (/(your|custom|keywords)/i.test(prompt)) {
  return 'your_domain';
}

然后添加处理 generateQuestions() 和 createOptimizedPrompt().

🏗️ 发展

构建

npm run build

观看模式

npm run dev

项目结构

mcp-prompt-optimizer/
├── src/
│   └── index.ts          # Main server code
├── dist/                 # Built output (git-ignored)
├── package.json
├── tsconfig.json
├── README.md
├── LICENSE
└── .gitignore

🎓 运作原理

OTA(优化然后应答)循环

1. Parse & Classify
   ├── Detect domain
   ├── Calculate clarity score
   └── Identify risk flags

2. Generate Questions (if clarity < 60%)
   └── Max 3 targeted questions

3. Create Optimized Prompt
   ├── Add domain-specific requirements
   ├── Include risk warnings
   └── Specify output format

4. Return Analysis
   ├── Optimization header
   ├── Questions (if needed)
   └── Enhanced prompt (if ready)

基于关键字的检测

服务器对以下内容使用关键字匹配:

  • 域名分类 -快速、确定性
  • 清晰度评分 -基于启发式
  • 风险检测 -图案匹配

注: 这是有意的简单和快速。没有ML模型,没有API调用,可以脱机工作。

🤝 贡献

欢迎投稿!需要改进的地方:

  • []基于ML的领域分类
  • []多语言支持
  • []从用户反馈中学习
  • []与自定义知识库集成
  • []自动提示重写(不仅仅是增强)

📄 许可证

MIT许可证-请参阅 许可证 详细信息文件

🔗 相关

⭐ 支持

如果这个工具能帮助你获得更好的人工智能响应,那就给它一颗星吧!

📝 更新日志

v1.1.0版本(2025-11-08)

  • 添加 /ori 用于自主研究实施工作流的slash命令
  • 智能多模型选择 (Opus→ 十四行诗→ 俳句)
    • 第0阶段:Opus制定研究策略
    • 第一阶段:基于复杂性的动态模型选择
    • 第2-4阶段:每个阶段优化模型(节省40%的成本)
  • optimized_prompts.md中集成OTA-循环的OODA框架
  • 添加了自动网络搜索和文档研究
  • 实施了错误处理和回滚机制
  • 添加了自动文档更新(README、CHANGELOG)
  • 通过创建可配置的工作流 .claude/ori-config.json

v1.0.0(2025-11-08)

  • 初始版本
  • 域检测(7个域)
  • 清晰度评分(0-1分)
  • 风险检测(5类)
  • 智能问题生成(最多3个)
  • 特定领域的提示增强

由以下材料制成❤️ 更好的AI交互