🤖 AI-MCP编排器
使用17+MCP工具的下一代代理AI系统
    
*一个集成了ChatGPT风格的生产就绪系统 LangChain, LangGraph, FastMCP,以及 谷歌双子座2.0 Flash 拥有17个以上强大的MCP工具、智能路由、持久内存和漂亮的反应式UI。*
______________________________________________________________________
📋 目录
______________________________________________________________________
🌟 概述
AI-MCP编排器 是一个复杂的代理人工智能系统,它结合了谷歌Gemini 2.0 Flash模型的强大功能和一套广泛的模型上下文协议(MCP)工具。它基于LangChain和LangGraph构建,提供智能工具路由、多步推理以及与外部服务的无缝集成。
是什么让它特别?
- 🎯 17+MCP工具 -从网络搜索到系统监控,从天气到翻译
- 🧠 智能路由 -为每个查询自动选择正确的工具
- 🔄 LangGraph管道 -具有状态管理的多代理编排
- 💾 持久存储器 -对话历史和上下文保留
- 🎨 漂亮的UI -具有实时更新功能的现代响应式界面
- ⚡ 实时WebSocket -流式响应和实时工具执行
- 🔧 可切换工具 -动态启用/禁用工具
- 📊 分析仪表板 -监控系统性能和工具使用情况
______________________________________________________________________
✨ 特性
🤖 人工智能能力
- 多回合对话 具有情境意识
- 工具链 -在单个查询中组合多个工具
- 智能回退 -工具发生故障时性能下降
- 流媒体响应 -实时逐个令牌输出
- 内存管理 -短期和长期背景
🛠️ MCP工具套件
- 网页搜索 -DuckDuckGo集成
- 文件管理 -读取、写入、组织文件
- 数据库操作 -MongoDB CRUD操作
- 电子邮件自动化 -发送和管理电子邮件
- Google 云端硬盘 -云存储集成
- 工作流程自动化 -安排和执行任务
- 知识库 -存储和检索信息
- 分析 -数据分析和可视化
- API集成 -连接到外部API
- 天气/气候 -实时天气数据
- 维基百科 -百科全书检索
- Python执行 -安全代码执行沙盒
- 屏幕监控 -屏幕截图和显示信息
- 系统监控 -CPU、内存、磁盘指标
- 计算器 -数学运算和单位转换
- 翻译员 -多语言翻译
🎨 用户界面
- ChatGPT风格接口 -熟悉且直观
- 工具状态卡 -可视化工具管理
- 动画粒子 -动态背景效果
- 深色主题 -眼睛友好的设计
- 响应布局 -适用于所有设备
- 消息历史 -滚动浏览过去的对话
- 打字指示器 -实时反馈
______________________________________________________________________
🏗️ 建筑
高级系统设计
┌─────────────────────────────────────────────────────────────────┐
│ FRONTEND (React) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Chat UI │ │ Tool Panel │ │ Analytics │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └──────────────────┴──────────────────┘ │
│ │ │
│ WebSocket / REST API │
└────────────────────────────┼────────────────────────────────────┘
│
┌────────────────────────────┼────────────────────────────────────┐
│ BACKEND (FastAPI) │
│ ┌──────────────────────────┴──────────────────────────┐ │
│ │ API Layer (Routes) │ │
│ │ • Chat Routes • MCP Routes • Memory Routes │ │
│ └──────────────────────┬──────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┴──────────────────────────────┐ │
│ │ LangGraph Orchestration Pipeline │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Router │→ │ Executor │→ │ Aggregator│ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └──────────────────────┬──────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┴──────────────────────────────┐ │
│ │ Tool Registry (17 Tools) │ │
│ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │
│ │ │Web Srch│ │File Mgr│ │Database│ │ Email │ ... │ │
│ │ └────────┘ └────────┘ └────────┘ └────────┘ │ │
│ └──────────────────────┬──────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┴──────────────────────────────┐ │
│ │ Services & Integrations │ │
│ │ • Database Service (MongoDB) │ │
│ │ • Gemini AI Service (Google) │ │
│ │ • Memory Service (Context Management) │ │
│ └──────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
│
┌────────────────────────────┼────────────────────────────────────┐
│ EXTERNAL SERVICES │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Gemini │ │ MongoDB │ │ Google │ │ APIs │ │
│ │ 2.0 Flash│ │ │ │ Drive │ │ │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└──────────────────────────────────────────────────────────────────┘LangGraph管道流量
User Query
↓
┌───────────────┐
│ Query Router │ ← Analyzes query and selects appropriate tools
└───────┬───────┘
↓
┌───────────────┐
│ Tool Executor │ ← Executes selected MCP tools in parallel/sequence
└───────┬───────┘
↓
┌───────────────┐
│ Aggregator │ ← Combines results from multiple tools
└───────┬───────┘
↓
┌───────────────┐
│ Response Gen │ ← Generates natural language response
└───────┬───────┘
↓
User Response数据流架构
┌──────────────┐
│ User Input │
└──────┬───────┘
↓
┌──────────────────────────────────────┐
│ 1. WebSocket Connection Established │
└──────┬───────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ 2. Query Preprocessing │
│ • Tokenization │
│ • Context Injection │
│ • Memory Retrieval │
└──────┬───────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ 3. Tool Selection (Router) │
│ • Keyword Matching │
│ • Semantic Analysis │
│ • Multi-tool Detection │
└──────┬───────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ 4. Tool Execution │
│ • Parallel Execution │
│ • Error Handling │
│ • Result Caching │
└──────┬───────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ 5. Response Generation │
│ • Result Aggregation │
│ • Gemini 2.0 Processing │
│ • Streaming Output │
└──────┬───────────────────────────────┘
↓
┌──────────────────────────────────────┐
│ 6. Memory Update │
│ • Conversation Storage │
│ • Context Update │
└──────┬───────────────────────────────┘
↓
┌──────────────┐
│ User Response│
└──────────────┘______________________________________________________________________
🧰 MCP工具(17)
1. 网页搜索 🔍
- 供应商: 鸭鸭搜
- 行动: 搜索网页、获取片段、提取网址
- 使用案例: 研究、事实核查、时事
2. 文件管理器 📁
- 行动: 读取、写入、删除、列出文件
- 支持: 文本、JSON、CSV、Markdown
- 使用案例: 文件管理、数据处理
3. 数据库 🗄️
- 供应商: MongoDB
- 行动: CRUD操作、查询、聚合
- 使用案例: 数据存储、检索、分析
4. 电子邮件 📧
- 协议: SMTP
- 行动: 发送电子邮件、附件、模板
- 使用案例: 通知、报告、沟通
5. Google 云端硬盘 ☁️
- 行动: 上传、下载、分享、整理
- 使用案例: 云存储、协作
6. 自动化 ⚡
- 行动: 安排任务、工作流、触发器
- 使用案例: 重复任务、批处理
7. 记忆 🧠
- 行动: 存储、召回、搜索上下文
- 使用案例: 对话历史、用户偏好
8. 分析 📊
- 行动: 数据分析、可视化、趋势
- 使用案例: 商业智能、报告
9. 知识库 📚
- 行动: 存储文章、搜索、分类
- 使用案例: 文档、维基、常见问题解答
10. API集成 🔗
- 行动: REST调用、webhooks、OAuth
- 使用案例: 第三方集成
11. 气候/天气 🌤️
- 供应商: Python Weather API
- 行动: 当前天气、预报、气候数据
- 使用案例: 旅行计划、天气警报
12. 维基百科 📖
- 行动: 搜索、摘要、全文
- 使用案例: 研究、定义、学习
13. Python代码 💻
- 行动: 执行代码、验证语法、分析
- 使用案例: 计算、数据处理、自动化
14. 屏幕监视器 🖥️
- 行动: 屏幕截图、显示信息、分辨率
- 使用案例: 文档、故障排除
15. 系统监视器 📈
- 行动: CPU、内存、磁盘、网络统计数据
- 使用案例: 性能监测、诊断
16. 计算器 🔢
- 行动: 数学运算、单位转换
- 使用案例: 计算、转换、方程式
17. 翻译员 🌐
- 行动: 翻译文本,检测语言
- 支持: 12+种语言
- 使用案例: 多语言交流
______________________________________________________________________
🔧 技术栈
后端
- 框架: FastAPI 0.120.0
- AI/ML:
- 谷歌双子座2.0 Flash - LangChain(最新) - LangGraph(最新)
- 数据库: MongoDB(电机异步驱动程序)
- Websocket: FastAPI WebSockets
- 验证: Pydantic v2
前端
- 框架: 反应18
- 构建工具: 维特
- 造型: 尾风CSS
- 动画: 帧运动
- 图标: Lucide反应
- HTTP客户端: 阿西奥斯
开发运维
- 环境: Python 3.13+
- 包管理器: pip,npm
- 流程经理: Uvicorn
- 登录中: 带颜色的Python日志记录
______________________________________________________________________
📦 安装
先决条件
- Python 3.13+
- Node.js 18+
- MongoDB (本地或云端)
- Git
步骤1:克隆存储库
git clone https://github.com/yourusername/ai-mcp-orchestrator.git
cd ai-mcp-orchestrator步骤2:后端设置
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt步骤3:前端设置
cd frontend
# Install dependencies
npm install步骤4:环境配置
创建 .env 文件在 backend/ 目录:
# API Keys
GEMINI_API_KEY=your_gemini_api_key_here
OPENAI_API_KEY=
# Model Configuration
GEMINI_MODEL=gemini-2.0-flash-exp
TEMPERATURE=0.7
MAX_TOKENS=8192
# Database
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=ai_mcp_orchestrator
# Server
HOST=0.0.0.0
PORT=8000
DEBUG=True
# CORS (comma-separated)
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
# MCP Configuration
MCP_TIMEOUT=30
MAX_CONCURRENT_TOOLS=5步骤5:启动MongoDB
# Windows (if installed as service)
net start MongoDB
# Linux/Mac
sudo systemctl start mongod
# Or use MongoDB Atlas (cloud)______________________________________________________________________
🚀 使用指南
启动应用程序
选项1:手动启动
终端1-后端:
cd backend
python main.py2号航站楼-前端:
cd frontend
npm run dev选项2:使用启动脚本
窗户:
start.batLinux/Mac:
chmod +x start.sh
./start.sh访问应用程序
- 前端: http://localhost:3000
- 后端API: http://localhost:8000
- API文件: http://localhost:8000/docs
- 健康检查: http://localhost:8000/health
使用聊天界面
- 打开 http://localhost:3000
- 启用工具 -点击“MCP工具”按钮,切换所需工具
- 开始聊天 -在输入框中键入您的查询
- 查看结果 -查看AI响应和工具执行详细信息
查询示例
🔍 Web Search:
"Search for latest AI news"
🌤️ Weather:
"What's the weather in Tokyo?"
📖 Wikipedia:
"Tell me about quantum computing"
💻 Python Code:
"Run this code: print('Hello World')"
📊 System Monitor:
"Show me my CPU usage"
🔢 Calculator:
"Calculate 25 * 4 + 10"
🌐 Translator:
"Translate 'Good morning' to Spanish"
🔗 Multi-Tool:
"Search for Python tutorials and save the results to a file"______________________________________________________________________
📚 API文档
REST端点
聊天API
发布 /api/chat/message
{
"message": "Your query here",
"session_id": "optional-session-id",
"active_tools": ["web_search", "calculator"]
}答复:
{
"response": "AI generated response",
"tools_used": ["web_search"],
"execution_time": 1.23,
"session_id": "session-123"
}MCP工具API
获取 /api/mcp/tools
{
"tools": [
{
"name": "web_search",
"description": "Search the web",
"enabled": true
}
]
}发布 /api/mcp/tools/{tool_name}/toggle
{
"enabled": true
}内存API
获取 /api/memory/history?session_id=123&limit=10
删除 /api/memory/clear?session_id=123
Websocket API
连接: ws://localhost:8000/api/ws/chat
发送消息:
{
"type": "message",
"content": "Your query",
"session_id": "session-123"
}接收响应:
{
"type": "response",
"content": "AI response",
"tools_used": ["web_search"],
"done": true
}______________________________________________________________________
📁 项目结构
ai-mcp-orchestrator/
├── backend/
│ ├── config.py # Configuration settings
│ ├── main.py # FastAPI application entry
│ ├── requirements.txt # Python dependencies
│ │
│ ├── routes/ # API route handlers
│ │ ├── chat_routes.py
│ │ ├── mcp_routes.py
│ │ ├── memory_routes.py
│ │ └── websocket_routes.py
│ │
│ ├── services/ # Business logic services
│ │ ├── db_service.py
│ │ ├── gemini_service.py
│ │ └── memory_service.py
│ │
│ ├── mcp_tools/ # 17 MCP tool implementations
│ │ ├── web_search_mcp.py
│ │ ├── file_manager_mcp.py
│ │ ├── climate_mcp.py
│ │ ├── wikipedia_mcp.py
│ │ └── ... (13 more)
│ │
│ ├── langgraph_pipeline/ # LangGraph orchestration
│ │ ├── graph_builder.py
│ │ ├── router.py
│ │ ├── executor.py
│ │ └── aggregator.py
│ │
│ └── utils/ # Utility functions
│ ├── tool_registry.py
│ └── helpers.py
│
├── frontend/
│ ├── package.json
│ ├── vite.config.js
│ ├── tailwind.config.js
│ │
│ ├── src/
│ │ ├── App.jsx # Main application
│ │ ├── main.jsx # Entry point
│ │ │
│ │ ├── components/ # React components
│ │ │ ├── ChatInterface.jsx
│ │ │ ├── MCPToolPanel.jsx
│ │ │ ├── MCPCard.jsx
│ │ │ └── ParticleBackground.jsx
│ │ │
│ │ ├── context/ # React context
│ │ │ └── MCPContext.jsx
│ │ │
│ │ ├── services/ # API services
│ │ │ └── api.js
│ │ │
│ │ └── styles/ # CSS styles
│ │ └── index.css
│ │
│ └── public/ # Static assets
│
├── README.md # This file
├── UPDATE_SUMMARY.md # Recent updates
└── .gitignore______________________________________________________________________
🛠️ 发展
添加新的MCP工具
- 创建工具文件:
backend/mcp_tools/your_tool_mcp.py
class YourTool:
def __init__(self):
self.name = "your_tool"
self.description = "Tool description"
self.enabled = True
async def execute(self, action: str, **kwargs):
# Implementation
return {"success": True, "data": "result"}
def get_schema(self):
return {
"name": self.name,
"description": self.description,
"parameters": {...}
}- 注册
__init__.py:
from .your_tool_mcp import YourTool
__all__ = [..., "YourTool"]- 添加到工具注册表:
utils/tool_registry.py
- 添加关键字:
langgraph_pipeline/router.py
- 添加前端图标:
frontend/src/components/MCPCard.jsx
运行测试
# Backend tests
cd backend
pytest
# Frontend tests
cd frontend
npm test代码格式化
# Backend
black backend/
flake8 backend/
# Frontend
npm run lint
npm run format______________________________________________________________________
🐛 故障排除
常见问题
1. CORS错误
Error: CORS policy blocked解决方案: 检查 CORS_ORIGINS 在 .env 匹配您的前端URL
2. MongoDB连接失败
Error: Could not connect to MongoDB解决方案:
- 确保MongoDB正在运行
- 检查
MONGODB_URL在.env - 尝试:
mongodb://localhost:27017或MongoDB Atlas URL
3. Gemini API错误
Error: Invalid API key解决方案:
- 从获取API密钥https://ai.google.dev
- 更新
GEMINI_API_KEY在.env
4. 未找到模块
ModuleNotFoundError: No module named 'fastapi'解决方案:
cd backend
pip install -r requirements.txt5. 端口已在使用中
Error: Address already in use解决方案:
- 改变
PORT在.env - 或终止进程:
lsof -ti:8000 | xargs kill -9(Mac/Linux)
日志位置
- 后端: 带有彩色日志记录的控制台输出
- 前端: 浏览器控制台(F12)
- MongoDB: 检查MongoDB日志
______________________________________________________________________
🤝 贡献
我们欢迎捐款!请按照以下步骤操作:
- 分叉 存储库
- 创建 特征分支(
git checkout -b feature/amazing-feature) - 提交 您的更改(
git commit -m 'Add amazing feature') - 推 分支机构(
git push origin feature/amazing-feature) - 打开 拉取请求
贡献指南
- 遵循现有代码样式
- 为新功能添加测试
- 更新文档
- 保持提交原子性和良好的描述
______________________________________________________________________
📄 许可证
该项目根据 MIT许可证 -看看 许可证 文件以获取详细信息。
______________________________________________________________________
🙏 致谢
- 谷歌 -Gemini 2.0 Flash API
- LangChain -AI编排框架
- 快速API -现代Python web框架
- 反应 -UI库
- MongoDB -数据库解决方案
______________________________________________________________________
📞 支持
- 问题:
- 讨论:
- 电子邮件: your.email@example.com
______________________________________________________________________
🗺️ 路线图
- \[\]添加更多MCP工具(20+目标)
- \[\]语音输入/输出支持
- \[\]多用户身份验证
- \[\]工具市场
- \[\]移动应用程序(React Native)
- \[\]Docker容器化
- \[\]Kubernetes部署
- \[\]高级分析仪表板
- \[\]自定义工具插件系统
- \[\]RAG(检索增强生成)
______________________________________________________________________
内置❤️ AI-MCP团队
⭐ 如果你觉得这很有用,请在GitHub上给我们加星!
