返回市场
MCP网关

MCP网关

作者:lightconetech145 星标更新:2024-12-08

项目介绍

MCP Server Gateway

一个网关服务,用于连接基于stdio的模型上下文协议(MCP)实现与基于HTTP/Server-Sent Events(SSE)的MCP服务器。这解决了当前协议兼容性的问题,因为Claude Desktop目前仅支持基于stdio的MCP服务器。详情讨论请参见这里

为什么需要这个网关?

Claude Desktop应用程序目前仅支持基于stdio的MCP服务器协议,而许多MCP服务器使用HTTP与Server-Sent Events(SSE)传输。此网关充当协议转换器,允许Claude Desktop与任何HTTP/SSE MCP服务器通信,通过以下步骤:

  1. 接受来自Claude Desktop的stdio输入
  2. 将请求转换并转发给HTTP/SSE MCP服务器
  3. 将SSE响应转换回stdio格式供Claude Desktop使用

安装

使用npm全局安装网关:

npm install -g @mcphub/gateway

配置

1. 查找网关路径

安装后,使用以下命令查找npm安装网关的位置:

# 显示全局包的根目录
npm root -g

# 网关位于:
<npm_global_root>/@mcphub/gateway/dist/src/mcphub-gateway.js

常见的全局包位置:

  • macOS (Homebrew Node): /opt/homebrew/lib/node_modules/@mcphub/gateway/dist/src/mcphub-gateway.js
  • macOS (默认): /usr/local/lib/node_modules/@mcphub/gateway/dist/src/mcphub-gateway.js
  • Windows: %AppData%\npm\node_modules\@mcphub\gateway\dist\src\mcphub-gateway.js

验证安装和路径:

npm list -g @mcphub/gateway

2. 配置Claude Desktop

创建或更新你的Claude Desktop配置文件:

在macOS上

位置:~/Library/Application Support/Claude Desktop/config.json

在Windows上

位置:%APPDATA%\Claude Desktop\config.json

添加如下配置(使用你在步骤1中找到的路径):

{
  "mcpServers": {
    "server-name": {
      "command": "node",
      "args": ["/opt/homebrew/lib/node_modules/@mcphub/gateway/dist/src/mcphub-gateway.js"]
    }
  }
}

注意:请用你在步骤1中找到的实际路径替换args中的路径。

3. 配置MCP服务器连接

网关使用环境变量来指定要连接的MCP服务器:

# 设置MCP服务器URL(可选)
export MCP_SERVER_URL=https://your-mcp-server.com/api/mcp

默认情况下,网关连接到位于https://server.mcphub.ai/api/mcp的MCP Hub服务器,该服务器提供对各种预配置的MCP服务的访问。

4. 启动Claude Desktop

启动或重启Claude Desktop以应用更改。

故障排除

  1. 如果找不到网关路径:

    # 列出所有全局包并查找@mcphub/gateway
    npm list -g
    
    # 或者专门检查网关
    npm list -g @mcphub/gateway
    
  2. 验证Node.js安装:

    # 检查Node版本
    node --version
    
    # 检查npm版本
    npm --version
    
  3. 常见问题:

    • 如果在macOS上使用Homebrew,请确保Node.js正确链接:
      brew doctor
      brew link node
      
    • 如果遇到权限错误,可能需要使用sudo进行安装

许可证

Apache 2.0 License

支持

如果你遇到任何问题或有疑问:

  • 在GitHub上提交问题

贡献

欢迎贡献!请随时提交Pull Request。