# rest_call_mcp **Repository Path**: drx000/rest_call_mcp ## Basic Information - **Project Name**: rest_call_mcp - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-31 - **Last Updated**: 2026-01-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MCP REST Gateway 一个使用 FastAPI 实现的 MCP (Model Context Protocol) 客户端,提供 REST API 接口来访问 MCP 服务器的 tools。 ![输入图片说明](image.png) ## 功能特性 - 通过 HTTP 连接 MCP 服务器 - 列出所有可用的 tools - 调用具体的 tool 接口 - RESTful API 设计 ## 安装依赖 ```bash pip install -r requirements.txt ``` ## 配置 1. 复制 `.env.example` 为 `.env` 2. 修改 `MCP_URL` 为你的 MCP 服务器地址 ```bash cp .env.example .env ``` ## 启动服务 ### 方式一:使用启动脚本 Windows: ```bash start.bat ``` ### 方式二:直接运行 Python ```bash python main.py ``` ### 方式三:使用 uvicorn ```bash uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` ## API 接口 ### 1. 获取 API 信息 ```bash GET / ``` 返回 API 基本信息。 ### 2. 健康检查 ```bash GET /health ``` 返回服务健康状态。 ### 3. 列出所有 tools ```bash GET /tools ``` 返回所有可用的 tools 列表。 **响应示例:** ```json { "success": true, "tools": [ { "name": "example_tool", "description": "这是一个示例工具", "input_schema": { "type": "object", "properties": { "param1": {"type": "string"} } } } ] } ``` ### 4. 调用 tool ```bash POST /tools/call Content-Type: application/json { "tool_name": "example_tool", "arguments": { "param1": "value1" } } ``` **响应示例:** ```json { "success": true, "result": { "output": "tool 执行结果" } } ``` ## 使用示例 ### 使用 curl ```bash # 获取所有 tools curl http://localhost:8000/tools # 调用 tool curl -X POST http://localhost:8000/tools/call \ -H "Content-Type: application/json" \ -d '{"tool_name": "example_tool", "arguments": {"param1": "value"}}' ``` ### 使用 Python requests ```python import requests # 获取所有 tools response = requests.get("http://localhost:8000/tools") tools = response.json() print(tools) # 调用 tool response = requests.post( "http://localhost:8000/tools/call", json={ "tool_name": "example_tool", "arguments": {"param1": "value"} } ) result = response.json() print(result) ``` ## 项目结构 ``` rest_call_mcp/ ├── main.py # FastAPI 主应用 ├── mcp_client.py # MCP 客户端实现 ├── requirements.txt # 项目依赖 ├── .env.example # 环境变量示例 ├── start.bat # Windows 启动脚本 └── README.md # 项目说明 ``` ## 注意事项 - 确保 MCP 服务器地址正确且可访问 - 默认端口为 8000,可在启动时修改 - 调用 tool 时需要确保参数符合 tool 的 input_schema