使用说明
项目简介
FastMCP-HTTP 提供了一套基于 HTTP 协议的 Model Context Protocol (MCP) 服务器解决方案。它包含以下几个核心组件:
- FastMCPHttpServer: 独立的 HTTP MCP 服务器,可以单独运行,提供工具、资源和 Prompt 模板的 HTTP 接口。
- FastMCPHttpClient: 用于与 FastMCPHttpServer 或 MCP Registry Server 交互的客户端库,支持同步和异步调用。
- MCP Registry Server: MCP 注册中心服务器,用于集中管理多个 FastMCPHttpServer,提供服务注册、健康监控和统一的工具访问入口。
- MCP Explorer: 一个图形界面工具,用于浏览和调用 MCP 服务器的功能。
主要功能点
- MCP 服务器核心功能: 支持注册和执行工具 (Tools)、托管和访问资源 (Resources)、以及定义和渲染 Prompt 模板 (Prompts)。
- HTTP 协议: 使用 HTTP RESTful API 作为 MCP 服务器的通信协议。
- 独立服务器模式: FastMCPHttpServer 可以作为独立的 MCP 服务器运行。
- 注册中心模式: MCP Registry Server 可以管理多个 FastMCPHttpServer,提供统一的服务入口和工具发现。
- 工具统一访问: 通过 MCP Registry Server,客户端可以访问注册到中心的所有 MCP 服务器上的工具。
- 健康监控: MCP Registry Server 监控已注册服务器的健康状态。
- 动态端口分配: MCP Registry Server 可以为注册的 MCP 服务器动态分配端口。
- 权限管理: 包含一个简单的权限服务器 (PermissionServer),用于处理权限请求(通过弹窗,需要图形界面环境)。
- MCP Explorer GUI: 提供图形界面来浏览和调用 MCP 服务器的功能。
安装步骤
- 克隆仓库到本地:
git clone https://github.com/ARadRareness/mcp-registry.git cd mcp-registry - 安装 Python 依赖:
pip install -r requirements.txt
服务器配置
1. 独立 FastMCPHttpServer 配置 (Standalone Mode):
如果你想运行一个独立的 MCP 服务器,可以使用 'FastMCPHttpServer'。MCP 客户端需要配置连接到这个独立服务器的信息。以下是一个可能的 MCP 客户端配置示例 (JSON 格式):
{ "server_name": "MyStandaloneMCP", "command": "python", "args": ["example/server_example.py"] }
参数说明:
- 'server_name': 自定义的服务器名称,用于在客户端标识服务器。
- 'command': 启动服务器的命令,这里使用 'python' 解释器。
- 'args': 命令参数列表,'example/server_example.py' 是服务器示例脚本的路径。服务器默认监听 '5000' 端口,可以通过修改脚本或 'run_http' 方法的参数来指定端口。
2. MCP Registry Server 和 FastMCPHttpServer 配置 (Registry Mode):
如果你想使用 MCP 注册中心来管理多个 MCP 服务器,你需要先启动 'MCP Registry Server',然后启动 'FastMCPHttpServer' 并将其注册到注册中心。MCP 客户端需要配置连接到 'MCP Registry Server' 的信息。
MCP Registry Server 配置: MCP 客户端配置 (JSON 格式) 连接到注册中心:
{ "server_name": "MCPRegistry", "command": "python", "args": ["start_registry_server.py"] }
参数说明:
- 'server_name': 自定义的注册中心服务器名称。
- 'command': 启动注册中心服务器的命令,使用 'python' 解释器。
- 'args': 命令参数列表,'start_registry_server.py' 是注册中心服务器启动脚本的路径。注册中心服务器默认监听 '31337' 端口。
FastMCPHttpServer 配置 (注册到 Registry): 启动 'FastMCPHttpServer' 时,默认会自动注册到运行在 'http://127.0.0.1:31337' 的注册中心。无需额外的客户端配置,但需要确保注册中心先启动。
基本使用方法
1. 启动 MCP Registry Server (可选): 如果你需要使用注册中心,首先启动 'MCP Registry Server'。
python start_registry_server.py
2. 启动 FastMCPHttpServer:
- Standalone 模式: 运行 'example/server_example.py' 启动一个独立的 MCP 服务器。
python example/server_example.py - Registry 模式: 同样运行 'example/server_example.py',服务器会自动注册到注册中心 (如果注册中心已启动)。
python example/server_example.py
3. 运行客户端: 运行 'example/client_example.py' 或 'MCP Explorer (src/mcp_explorer/mcp_explorer.py)' 来测试客户端功能。
python example/client_example.py # 或 python -m src.mcp_explorer.mcp_explorer
- Standalone 客户端: 修改 'example/client_example.py' 中的 'FastMCPHttpClient' 初始化参数,指向独立服务器的地址 (例如 '"http://127.0.0.1:15151"' 如果你修改了独立服务器的端口)。
- Registry 客户端: 'example/client_example.py' 默认连接到注册中心 ('"http://127.0.0.1:31337"'), 无需修改即可测试注册中心模式。
4. 使用 MCP Explorer (GUI 客户端): 运行 'src/mcp_explorer/mcp_explorer.py' 启动图形界面客户端,可以方便地浏览和调用注册到 MCP Registry 或独立 MCP 服务器的工具。
python -m src.mcp_explorer.mcp_explorer
信息
分类
网页与API