MCP-Host-CLI

MCP-Host-CLI

site icon
2025.04.16 3
TypeScriptMCP 主机管理HTTP API 接口开发效率
MCP-Host-CLI 是一个基于 Node.js 的 Model Context Protocol (MCP) 主机应用程序,用于连接和管理多个 MCP 服务器。它提供统一的 HTTP API 接口,允许客户端与多个 MCP 服务器进行交互,访问及调用工具或资源。支持 STDIO 和 SSE 两种传输方式,适用于快速测试及运行 MCP Servers。
View on GitHub

Overview

基本能力

产品定位

MCP-Host-CLI 是一个 MCP 主机应用程序,用于连接和管理多个 MCP 服务器,提供统一的 HTTP API 接口。

核心功能

  • 支持同时连接多个 MCP 服务器,通过 JSON 文件管理多个 MCP 服务器。
  • 支持 STDIO 和 SSE 两种传输方式。
  • 提供统一的 HTTP API 接口,用于:
  • 获取所有服务器的工具列表。
  • 调用特定服务器上的工具。
  • 获取所有服务器的资源列表。
  • 获取特定服务器上的资源。
  • 触发 Host 主动更新 Server 连接。

适用场景

  • 快速测试及运行 MCP Servers。
  • 管理多个 MCP 服务器的工具和资源。
  • 通过统一的 HTTP API 接口与多个 MCP 服务器交互。

工具列表

  • 获取所有工具列表:通过 GET http://localhost:17925/api/tools 获取所有服务器的工具列表。
  • 调用工具:通过 POST http://localhost:17925/api/tools/toolCall 调用特定服务器上的工具。
  • 获取所有资源列表:通过 GET http://localhost:17925/api/resources 获取所有服务器的资源列表。
  • 读取特定资源:通过 POST http://localhost:17925/api/resources/read 读取特定服务器上的资源。
  • 更新 Server 连接:通过 POST http://localhost:17925/api/connections/update 主动更新 Server 连接。

常见问题解答

  • 服务器默认运行在 17925 端口。
  • 确保配置文件中的服务器信息正确。
  • 对于 STDIO 传输方式,需要确保 npxuvx 命令可执行。
  • 对于 SSE 传输方式,需要确保 URL 可访问。

使用教程

使用依赖

  • 连接 STDIO MCP Server,需要 npxuvx 的系统运行环境。
  • npx 依赖 Node.js (>=18)。
  • uvx 依赖 Python (uv)。

安装教程

1. 使用 npm 包,无须本地构建 (推荐)

npx mcp-host-cli

2. 本地构建

git clone https://github.com/liujilongObject/mcp-host-cli.git
cd mcp-host-cli
npm install

开发模式

npm run dev

生产模式

npm run build
  • 生产环境使用:
  • 使用自定义的 Node.js 环境: bash production_node.exe dist/index.js
  • 使用宿主机的 Node.js 环境: bash node dist/index.js

调试方式

  • 确保服务器运行在 17925 端口。
  • 使用以下 API 进行调试:
  • 获取所有工具列表: bash GET http://localhost:17925/api/tools
  • 调用工具: ```bash POST http://localhost:17925/api/tools/toolCall Content-Type: application/json

    { "server_name": "服务器名称", "tool_name": "工具名称", "tool_args": { ... } } - 获取所有资源列表:bash GET http://localhost:17925/api/resources - 读取特定资源:bash POST http://localhost:17925/api/resources/read Content-Type: application/json

    { "server_name": "服务器名称", "resource_uri": "资源URI" } - 更新 Server 连接:bash POST http://localhost:17925/api/connections/update Content-Type: application/json ```

许可证

该项目遵循 MIT 开源许可条款。