Spaces:
Sleeping
Sleeping
| # MCP 服务器说明 | |
| 本项目现在包含三个MCP(Model Context Protocol)服务器,它们替代了原来的FastAPI HTTP服务。 | |
| ## 🚀 MCP 服务器概览 | |
| ### 1. RequestProcessor (service1) | |
| **功能**: 通用请求处理和数据分析 | |
| **工具**: | |
| - `process_request`: 处理各种类型的请求和响应 | |
| - `get_service_info`: 获取服务信息 | |
| - `validate_data`: 验证数据结构 | |
| **使用示例**: | |
| ```python | |
| # 处理请求 | |
| result = await process_request( | |
| message="analyze this data", | |
| data={"key": "value"} | |
| ) | |
| # 验证数据 | |
| validation = await validate_data({"name": "test", "value": 123}) | |
| ``` | |
| ### 2. DataAnalyzer (service2) | |
| **功能**: 数据分析和统计计算 | |
| **工具**: | |
| - `analyze_data`: 执行数据分析 | |
| - `get_data_statistics`: 计算数值统计 | |
| - `get_service_statistics`: 获取服务统计信息 | |
| **使用示例**: | |
| ```python | |
| # 分析数据 | |
| analysis = await analyze_data( | |
| input_data={"scores": [85, 90, 78, 92, 88]}, | |
| operation="statistics" | |
| ) | |
| # 计算统计 | |
| stats = await get_data_statistics([1, 2, 3, 4, 5]) | |
| ``` | |
| ### 3. MathComputer (service3) | |
| **功能**: 数学计算和统计函数 | |
| **工具**: | |
| - `compute_operation`: 基本数学运算 | |
| - `get_supported_operations`: 获取支持的操作 | |
| - `advanced_math_operations`: 高级数学运算 | |
| **使用示例**: | |
| ```python | |
| # 基本计算 | |
| result = await compute_operation( | |
| numbers=[1, 2, 3, 4, 5], | |
| operation="average" | |
| ) | |
| # 高级运算 | |
| percentile = await advanced_math_operations( | |
| operation="percentile", | |
| numbers=[1, 2, 3, 4, 5], | |
| percentile=75 | |
| ) | |
| ``` | |
| ## 🔧 配置说明 | |
| 这些MCP服务器已在 `config.json` 中配置: | |
| ```json | |
| { | |
| "request_processor": { | |
| "command": "python", | |
| "args": ["./python-services/service1/mcp_server.py"], | |
| "transport": "stdio" | |
| }, | |
| "data_analyzer": { | |
| "command": "python", | |
| "args": ["./python-services/service2/mcp_server.py"], | |
| "transport": "stdio" | |
| }, | |
| "math_computer": { | |
| "command": "python", | |
| "args": ["./python-services/service3/mcp_server.py"], | |
| "transport": "stdio" | |
| } | |
| } | |
| ``` | |
| ## 🚀 启动方式 | |
| ### 方式1: 通过主应用启动 | |
| 主Streamlit应用会自动启动这些MCP服务器: | |
| ```bash | |
| python app.py | |
| ``` | |
| ### 方式2: 独立启动 | |
| ```bash | |
| # 启动RequestProcessor | |
| python python-services/service1/mcp_server.py | |
| # 启动DataAnalyzer | |
| python python-services/service2/mcp_server.py | |
| # 启动MathComputer | |
| python python-services/service3/mcp_server.py | |
| ``` | |
| ## 📋 依赖要求 | |
| 每个MCP服务器需要以下依赖: | |
| ``` | |
| mcp | |
| fastmcp | |
| pydantic | |
| ``` | |
| ## 🔄 从HTTP服务迁移 | |
| 原来的三个FastAPI HTTP服务已被MCP服务器替代: | |
| | 原HTTP服务 | 新MCP服务器 | 功能对比 | | |
| |-----------|------------|----------| | |
| | service1 (8001) | RequestProcessor | 请求处理 → 通用MCP工具 | | |
| | service2 (8002) | DataAnalyzer | 数据分析 → 数据分析MCP工具 | | |
| | service3 (8003) | MathComputer | 数学计算 → 数学计算MCP工具 | | |
| ## 💡 优势 | |
| 1. **统一协议**: 所有服务都使用MCP协议 | |
| 2. **更好的集成**: 与LangChain等框架无缝集成 | |
| 3. **工具发现**: 自动工具发现和注册 | |
| 4. **类型安全**: 更好的参数类型定义和验证 | |
| 5. **异步支持**: 原生异步操作支持 | |
| ## 🐛 故障排除 | |
| 如果MCP服务器启动失败: | |
| 1. 检查依赖是否正确安装:`pip install mcp fastmcp` | |
| 2. 确认Python版本兼容性(建议3.8+) | |
| 3. 检查文件路径是否正确 | |
| 4. 查看错误日志获取详细信息 | |
| ## 🔮 扩展建议 | |
| 可以基于这些MCP服务器模板创建更多专用服务: | |
| - 文件处理服务 | |
| - 数据库查询服务 | |
| - 外部API集成服务 | |
| - 机器学习推理服务 |