Back to MCP directory
publicPublicdnsLocal runtime

mcp-server-and-gw

该项目是一个连接Claude Desktop与远程服务器的桥接工具,通过Node.js实现stdio到HTTP SSE的协议转换,支持MCP协议的服务发现和工具调用。

article

README

🚀 MCP 门控网关、服务器及客户端

本项目提供了一种解决方案,在 Claude 桌面版尚未支持连接远程服务器时,可通过脚本实现从标准输入输出(stdio)到 HTTP 服务器发送事件(Server - Sent Events, SSE)端点的桥接。它基于模型上下文协议,能帮助您更灵活地使用相关服务。

🚀 快速开始

📦 安装指南

安装 mcp - server - and - gw

您可以通过以下两种方式安装和运行 mcp-server-and-gw

# 1. 安装
npm install -g mcp-server-and-gw
# 2. 或直接使用 npx 运行
npx mcp-server-and-gw http://localhost:8808/
# ...或者通过环境变量配置
MCP_HOST=localhost MCP_PORT=8808 npx mcp-server-and-gw

在 Claude 中添加配置

⚠️ 重要提示

该桥接脚本是基于 Node.js,但您的服务器代码可以使用任何语言。

这是一个从 stdioHTTP SSE 的传输的 模型上下文协议 门控网关 src/mcp-server-and-gw.ts。按照以下步骤在 Claude 中添加配置:

## 1. 构建
yarn install
yarn build

## 2. 复制代码或更新 claude_desktop_config.json
##    注意:确保 npx 在 PATH 中,或使用完整路径如 /opt/homebrew/bin/npx
echo '{
  "mcpServers": {
    "Claude Gateway Example": {
      "command": "npx",
      "args": [
        "mcp-server-and-gw", "http://localhost:8808/"
      ]
    }
  }
}' > ~/Library/Application\ Support/Claude/claude_desktop_config.json

## 3. 启动服务器以便 Claude 可以连接并发现资源、工具等
PORT=8808 node examples/server.js

## 4. 启动 Claude 桌面版

💻 使用示例

示例服务器和客户端

您也可以独立于 Claude 桌面版开发 SSE 服务器,以便更快地进行迭代。例如,运行 src/server.ts 并使用 src/client.ts 作为客户端。 启动服务器后,在另一个终端中启动客户端时,您将看到服务器的输出。

% node examples/server.js
服务器在 8808 端口上运行

--> 收到连接:/sse
新建 SSE 连接

示例输出(部分)

以下是客户端运行的示例输出,展示了接收消息、处理请求和发送响应的过程:

% node examples/client.js
连接到服务器...
接收数据:message from server
处理完成

使用 MCP Inspector 测试

同时运行以下命令以启动 Inspector 和桥接工具,通过此方式,您可以监控和调试模型上下文协议的交互流程:

node ./build/mcp-server-and-gw.js
npx mcp-inspector
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client