MCP host use 是一个基于 Node.js 的 Model Context Protocol (MCP) 主机应用程序,用于连接和管理多个 MCP 服务器。主机提供了一个统一的接口,允许客户端通过 HTTP API 与多个 MCP 服务器进行交互,访问和调用工具(或资源)。您可以使用它快速测试和运行您的 MCP 服务器。
graph TD
Client[客户端] -->|HTTP 请求| HostServer[MCP 主机服务器]
HostServer -->|管理| ConnectionManager[连接管理器]
ConnectionManager -->|创建/管理| MCPClient1[MCP 客户端 1]
ConnectionManager -->|创建/管理| MCPClient2[MCP 客户端 2]
ConnectionManager -->|创建/管理| MCPClientN[MCP 客户端 N]
MCPClient1 -->|STDIO/SSE/StreamableHTTP| MCPServer1[MCP 服务器 1]
MCPClient2 -->|STDIO/SSE/StreamableHTTP| MCPServer2[MCP 服务器 2]
MCPClientN -->|STDIO/SSE/StreamableHTTP| MCPServerN[MCP 服务器 N]
json 文件同时连接多个 MCP 服务器STDIO|SSE|StreamableHTTP 多种传输方式mcp-host-use/
├── src/ # 源代码目录
│ ├── main.ts # 主入口文件
│ ├── host.ts # MCP 连接管理器
│ ├── client.ts # MCP 客户端实现
│ ├── server.ts # HTTP 服务器实现
│ ├── types.ts # 类型定义
│ └── utils.ts # 工具函数
npx 或 uvx 系统的操作环境。
npx 依赖于 Nodejs (>=18)uvx 依赖于 Python (UV)npm 包,无需本地构建(推荐)npx mcp-host-use
git clone https://github.com/liujilongObject/mcp-host-use.gitnpm installnpm run devnpm run build
production_node.exe dist/index.jsnode dist/index.jsmcp-host-use 可以读取当前工作目录下的 mcp_servers.config.json 文件,其格式如下:
{
"mcp_servers": [
{
"enabled": true, // 是否启用 server
"type": "stdio", // 'stdio' | 'sse' | 'streamableHttp'
"server_name": "server-puppeteer", // 自定义 name
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-puppeteer"
]
},
{
"enabled": true,
"type": "sse",
"server_name": "server-everything-sse",
"sse_url": "http://localhost:3001/sse"
},
{
"enabled": true,
"type": "stdio",
"server_name": "github",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": { // 支持配置环境变量
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
}
}
]
}
npxuvxGET http://localhost:17925/api/tools
{
"code": 200,
"data": [
{
"server_name": "服务器1",
"tools": [
{
"name": "工具名称",
"description": "工具描述",
"inputSchema": { ... }
}
]
}
]
}
POST http://localhost:17925/api/tools/toolCall
Content-Type: application/json
{
"server_name": "服务器名称",
"tool_name": "工具名称",
"tool_args": { ... }
}
{
"code": 200,
"data": {
"result": "工具执行结果"
}
}
GET http://localhost:17925/api/resources
{
"code": 200,
"data": [
{
"server_name": "服务器1",
"resources": [
{
"uri": "资源URI",
"mimeType": "资源类型",
"name": "资源名称"
}
]
}
]
}
POST http://localhost:17925/api/resources/read
Content-Type: application/json
{
"server_name": "服务器名称",
"resource_uri": "资源URI"
}
{
"code": 200,
"data": [
{
"mimeType": "资源类型",
"text": "text 类型资源",
"blob": "blob 类型资源"
}
]
}
调用此 API 后,主机将主动读取配置文件,并根据更新后的配置创建/重启/删除服务器连接。无需重启主机服务,继续调用
/api/tools等 API 即可获取更新后的服务器信息。
POST http://localhost:17925/api/connections/update
Content-Type: application/json
{"code":200,"message":"成功更新服务器连接"}
MIT