MCP RAG和计算器测试指南
🚀 快速开始
1.设置环境(仅限首次)
运行安装脚本:
.\runme.ps1或手动:
# Create virtual environment
python -m venv .venv
# Activate it
.\.venv\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txt2.启动MCP服务器
在1号航站楼:
# Activate venv if not already activated
.\.venv\Scripts\Activate.ps1
# Start MCP server
python mcp_server.pyMCP服务器将在 http://localhost:8000
3.启动Web UI
在2号航站楼(新航站楼):
# Activate venv
.\.venv\Scripts\Activate.ps1
# Start Flask UI
python app.py用户界面将在 http://localhost:5000
4.测试工具
打开浏览器并导航到:
http://localhost:5000🧪 测试示例
RAG检索工具
尝试以下查询:
- “德国可再生能源政策”
- “减缓气候变化”
- “可再生能源目标”
计算器工具
试试这些表达:
250 * (1.1 ** 7)-计算7年内的增长(250 * 1.1**7 - 250) / 250 * 100-增长百分比math.sqrt(144)-平方根math.pi * 10**2-圆形区域
📁 项目结构
mcp_rag_cal/
├── mcp_server.py # MCP server with RAG and calculator tools
├── app.py # Flask web UI server
├── templates/
│ └── index.html # Web UI interface
├── utils/
│ ├── retrieval.py # RAG retrieval logic
│ └── generation.py # Answer generation
├── requirements.txt # Python dependencies
├── runme.ps1 # Windows setup script
└── README.md # This file🔧 建筑
- MCP服务器 (
mcp_server.py):
- 显示两个工具: rag_retrieve 和 calculator - 使用FastMCP框架 - 在端口8000上运行
- Web用户界面 (
app.py):
- 提供REST API的Flask服务器 - 漂亮的现代界面 - 在端口5000上运行
- 工具集:
- retrieval.py:模拟文档检索(替换为真实矢量数据库) - generation.py:答案生成实用程序
🎯 特性
- ✅ RAG文档检索
- ✅ 具有数学功能的安全计算器
- ✅ 实时服务器状态监控
- ✅ 美观、响应迅速的用户界面
- ✅ 快速测试的示例查询
- ✅ 错误处理和验证
🔄 故障排除
MCP服务器显示“未运行”
- 确保你已经开始了
mcp_server.py在单独的终端中 - 检查端口8000是否可用
- 查找MCP服务器终端中的错误
端口已在使用中
# Find process using port 5000 or 8000
netstat -ano | findstr :5000
netstat -ano | findstr :8000
# Kill the process (replace PID with actual process ID)
taskkill /PID
/F导入错误
确保已激活虚拟环境并安装了依赖项:
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt📝 后续步骤
- 替换模拟数据:更新
utils/retrieval.py使用真实矢量数据库 - 添加LLM集成:连接到Ollama或其他LLM以生成答案
- 添加更多工具:用附加功能扩展MCP服务器
- 部署:使用像Gunicorn这样的生产WSGI服务器
🤝 贡献
请随时增强工具、添加新功能或改进UI!
