使用说明
主MCP编排器
一个中央MCP服务器,连接到多个MCP服务器,智能地将用户查询路由到适当的MCP工具,然后聚合并返回响应。
🚀 快速入门(交互式CLI)
最简单的入门方法是使用我们的交互式CLI:
python src/cli.py
CLI将指导您完成以下操作:
- API密钥设置
- MCP服务器发现
- MCP选择
- 交互式查询界面
看 CLI_QUICKSTART.md 详细说明。
特性
- 🔌 多MCP连接:同时连接到多个MCP服务器
- 🤖 AI驱动的路由:使用LLM智能路由查询(默认)
- 🧠 智能路由:分析查询以确定要调用哪些MCP
- 🔍 工具发现:自动从连接的MCP中发现可用工具
- 📊 响应聚合:在需要时合并多个MCP的响应
- ⚡ 异步执行:并行执行以实现更快的响应
- 🎯 查询分析:了解查询意图,以路由到正确的MCP
- 🔄 后备支援:如果AI失败,则自动退回到基于规则的路由
建筑
User Query
│
▼
┌─────────────────────┐
│ Master MCP Server │
│ ┌───────────────┐ │
│ │ Query Analyzer│ │
│ └───────┬───────┘ │
│ │ │
│ ▼ │
│ ┌───────────────┐ │
│ │ MCP Router │ │
│ └───────┬───────┘ │
│ │ │
└──────────┼──────────┘
│
┌──────┴──────┐
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ MCP #1 │ │ MCP #2 │
│ Router │ │ Coding │
└────┬────┘ └────┬────┘
│ │
└─────┬──────┘
│
▼
┌──────────┐
│ Response │
│ Aggregator│
└─────┬────┘
│
▼
User Response
安装
cd master-mcp
pip install -r requirements.txt
AI路由设置(可选)
主MCP工作 不带API密钥的开箱即用 使用基于规则的路由。
对于增强的AI供电路由,请设置API密钥:
# Option 1: OpenAI (default)
export OPENAI_API_KEY=your_key_here
# Option 2: Anthropic
export ANTHROPIC_API_KEY=your_key_here
export MASTER_MCP_AI_PROVIDER=anthropic
export MASTER_MCP_AI_MODEL=claude-3-5-haiku
路由模式:
| 模式 | 需要API密钥 | 速度 | 智能 |
|---|---|---|---|
| 基于规则 (默认) | ❌ 否 | ⚡ 快速 | 良好 |
| AI驱动 | ✅ 是 | 🔄 +200ms | 优秀 |
即使设置了API密钥,也要禁用AI路由:
export MASTER_MCP_USE_AI=false
配置
创建一个 config.json 注册MCP服务器的文件:
{
"mcp_servers": {
"mcp-router": {
"command": "python3",
"args": ["/path/to/mcp-router/src/mcp_server.py"],
"env": {}
},
"mcp-coding-agent": {
"command": "python3",
"args": ["/path/to/mcp-coding-agent/src/main.py"],
"env": {}
}
}
}
用法
作为MCP服务器(游标集成)- 推荐
主MCP现已与Cursor集成!看 CURSOR_SETUP.md 详细说明。
快速入门:
- 主MCP已添加到您的
~/.cursor/mcp.json - 重新启动游标
- 使用它:
@master-mcp query_mcp "What model should I use for debugging?" @master-mcp list_mcps
优点:
- 🎯 自动发现您现有的所有MCP
- 🤖 智能查询路由(人工智能或基于规则)
- 📊 聚合来自多个MCP的响应
- 🔌 开箱即用(基于规则的路由不需要API密钥)
独立MCP服务器
添加到任何MCP客户端的配置中:
{
"version": "1.0",
"mcpServers": {
"master-mcp": {
"command": "python3",
"args": ["/path/to/master-mcp/src/master_mcp_server.py"],
"env": {
"MASTER_MCP_USE_AI": "true"
}
}
}
}
CLI使用情况
python src/master_mcp_server.py --query "What model should I use for debugging?"
运作原理
- 查询分析:分析用户查询以确定意图
- MCP选择:根据查询选择适当的MCP
- 工具选择:从选定的MCP中选择正确的工具
- 执行:调用MCP工具(尽可能并行)
- 聚合:将响应合并为统一的结果
- 响应:向用户返回格式化的响应
