
Prompt-Optimizer-MCP-for-LLMs
A Model Context Protocol (MCP) server that provides intelligent tools for optimizing and scoring LLM prompts using deterministic heuristics.
README
🚀 Prompt Optimizer MCP
A Model Context Protocol (MCP) server that provides intelligent tools for optimizing and scoring LLM prompts using deterministic heuristics.
🎯 Overview
The Prompt Optimizer MCP server offers two powerful tools:
optimize_prompt
- Generate 3 optimized variants of a raw LLM prompt in different stylesscore_prompt
- Evaluate the effectiveness of an improved prompt relative to the original
Perfect for developers, content creators, and AI practitioners who want to improve their prompt engineering workflow.
✨ Features
🎨 Prompt Optimization Styles
- Creative: Enhanced with descriptive adjectives and engaging language
- Precise: Concise and focused, removing redundant words
- Fast: Optimized for quick processing with shorter synonyms
📊 Intelligent Scoring Algorithm
The scoring system evaluates prompts based on:
- Length optimization (40%): Prefers shorter, more concise prompts
- Keyword preservation (30%): Maintains important terms from the original
- Clarity improvement (30%): Reduces redundancy and improves structure
🔧 Technical Features
- ✅ Stateless: No external dependencies or state management
- ✅ Deterministic: Same inputs always produce same outputs
- ✅ Error-free: Comprehensive input validation and error handling
- ✅ Fast: Simple heuristics for quick processing
- ✅ Extensible: Easy to add new styles and scoring metrics
- ✅ Dual Transport: Supports both STDIO (MCP) and HTTP (deployment)
📁 Project Structure
prompt-optimizer-mcp/
├── 📄 README.md # This file
├── 📄 server.py # Main MCP server (STDIO transport)
├── 📄 http_server.py # HTTP server for deployment
├── 📄 start.py # Startup script (auto-detects mode)
├── 📄 requirements.txt # Python dependencies
├── 📄 test_server.py # Test script
├── 📄 deploy.py # Deployment script
├── 📄 Dockerfile # Container configuration
├── 📄 .gitignore # Git ignore rules
├── 📁 tools/
│ ├── 📄 __init__.py # Package initialization
│ └── 📄 optimize.py # Core optimization logic
├── 📁 tests/
│ ├── 📄 __init__.py # Test package initialization
│ └── 📄 test_optimize.py # Unit tests
└── 📁 .github/
└── 📁 workflows/
└── 📄 ci.yml # CI/CD pipeline
🚀 Quick Start
1. Clone the Repository
git clone https://github.com/Mahad-007/Prompt-Optimizer-MCP-for-LLMs.git
cd Prompt-Optimizer-MCP-for-LLMs
2. Install Dependencies
pip install -r requirements.txt
3. Run Tests
python test_server.py
4. Start the Server
# For local development (STDIO mode)
python server.py
# For deployment (HTTP mode)
python start.py
🛠️ Installation
Prerequisites
- Python 3.11 or higher
- pip package manager
Install Dependencies
# Install from requirements.txt
pip install -r requirements.txt
⚙️ Configuration
For Cursor IDE
Create .cursor/mcp.json
:
{
"mcpServers": {
"prompt-optimizer": {
"command": "python",
"args": ["server.py"],
"env": {}
}
}
}
For Other MCP Clients
Configure your MCP client to use:
- Command:
python server.py
- Transport: STDIO (default)
📖 Usage Examples
Using the MCP Server
Once configured, you can use the tools through any MCP client:
Optimize a Prompt
# Generate creative variants
variants = optimize_prompt(
raw_prompt="Write a story about a cat",
style="creative"
)
# Returns: [
# "Craft a compelling story about a cat",
# "Imagine you're an expert in this field. Write a story about a cat",
# "Write a story about a cat. in a way that captivates and inspires"
# ]
# Generate precise variants
variants = optimize_prompt(
raw_prompt="Please write a very detailed explanation about machine learning",
style="precise"
)
# Returns: [
# "Write a detailed explanation about machine learning",
# "• Write a detailed explanation about machine learning",
# "Write a detailed explanation about machine learning Be specific and concise."
# ]
Score a Prompt
score = score_prompt(
raw_prompt="Please write a very detailed explanation about machine learning",
improved_prompt="Write an explanation about machine learning"
)
# Returns: 0.85 (high score due to length reduction and clarity improvement)
HTTP API Usage
When deployed, the server also provides HTTP endpoints:
# Health check
curl http://localhost:8000/health
# Optimize prompt
curl -X POST http://localhost:8000/optimize \
-H "Content-Type: application/json" \
-d '{"raw_prompt": "Write about AI", "style": "creative"}'
# Score prompt
curl -X POST http://localhost:8000/score \
-H "Content-Type: application/json" \
-d '{"raw_prompt": "Write about AI", "improved_prompt": "Write about artificial intelligence"}'
Direct Python Usage
from tools.optimize import optimize_prompt, score_prompt
# Optimize a prompt
variants = optimize_prompt("Write about AI", "creative")
print(f"Optimized variants: {variants}")
# Score a prompt
score = score_prompt("Write about AI", "Write about artificial intelligence")
print(f"Score: {score}")
🧪 Testing
Run the comprehensive test suite:
# Run all tests
python test_server.py
# Run unit tests
python -m unittest tests.test_optimize -v
# Run specific test classes
python -m unittest tests.test_optimize.TestOptimizePrompt
python -m unittest tests.test_optimize.TestScorePrompt
python -m unittest tests.test_optimize.TestIntegration
🚀 Deployment
Automated Deployment
Use the deployment script:
python deploy.py
This will:
- Run all tests
- Install dependencies
- Run linting checks
- Build Docker image (if available)
- Create deployment package
Manual Deployment
Deploy to Smithery
-
Install Smithery CLI:
npm install -g @smithery/cli
-
Authenticate:
smithery auth login
-
Deploy:
# Windows .\deploy.bat # Linux/macOS chmod +x deploy.sh ./deploy.sh
Deploy with Docker
# Build the image
docker build -t prompt-optimizer-mcp:latest .
# Run the container
docker run -p 8000:8000 prompt-optimizer-mcp:latest
Deploy to Other Platforms
The server supports both STDIO (for MCP clients) and HTTP (for web deployment) transports:
- STDIO Mode:
python server.py
(for MCP clients) - HTTP Mode:
python start.py
(for web deployment)
Your MCP server will be available at: https://prompt-optimizer-mcp.smithery.ai
For detailed deployment instructions, see DEPLOYMENT.md.
🔧 Development
Adding New Optimization Styles
- Add the new style to the
Literal
type inserver.py
- Implement the style function in
tools/optimize.py
- Add corresponding tests in
tests/test_optimize.py
Extending the Scoring Algorithm
Modify the score_prompt
function in tools/optimize.py
to include additional metrics or adjust weights.
Running Locally
# Start the MCP server (STDIO mode)
python server.py
# Start the HTTP server (deployment mode)
python http_server.py
# Auto-detect mode based on environment
python start.py
📊 Performance
- Response Time: < 100ms for most operations
- Memory Usage: ~50MB typical
- CPU Usage: Minimal (stateless operations)
- Scalability: Auto-scales from 1-5 replicas on Smithery
🤝 Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
# Clone your fork
git clone https://github.com/yourusername/Prompt-Optimizer-MCP-for-LLMs.git
cd Prompt-Optimizer-MCP-for-LLMs
# Install dependencies
pip install -r requirements.txt
# Run tests
python test_server.py
# Make your changes and test
python demo.py
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Model Context Protocol for the MCP specification
- MCP Python SDK for the server framework
- Smithery for deployment platform
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: DEPLOYMENT.md
⭐ Star History
Made with ❤️ for the AI community
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。