Back to MCP directory
publicPublicdnsLocal runtime

mcp-proxy-server

MCP代理服务器是一个聚合多个MCP资源服务器的中心枢纽

article

README

🚀 MCP 代理服务器

MCP 代理服务器是一个强大的工具,它可以聚合并通过单个接口提供多个 MCP 资源服务器的服务。作为中心枢纽,它能高效连接和管理多个 MCP 资源服务器,通过统一接口展示综合功能,精准处理请求路由,并聚合多来源的响应,大大提升了资源管理和使用的效率。

🚀 快速开始

MCP 代理服务器是一个聚合并通过单个接口提供多个 MCP 资源服务器的代理服务器。它主要具备以下功能:

  • 连接和管理多个 MCP 资源服务器
  • 通过统一接口暴露其综合功能
  • 处理请求到适当后端服务器的路由
  • 聚合来自多个来源的响应

✨ 主要特性

资源管理

  • 能够自动发现并连接到多个 MCP 资源服务器。
  • 聚合所有已连接服务器的资源,方便统一管理。
  • 维持服务器之间一致的 URI 方案,确保资源访问的规范性。
  • 精准处理资源路由和解析,提高资源获取效率。

工具聚合

  • 暴露所有连接服务器的工具,用户可通过统一接口调用。
  • 将工具调用准确路由到适当的后端服务器。
  • 维护工具状态并及时处理响应,保障工具使用的流畅性。

提示处理

  • 聚合所有服务器的提示信息,便于用户获取全面信息。
  • 将提示请求路由到合适的后端服务器。
  • 高效处理多服务器提示响应,提升用户体验。

📦 安装指南

配置服务器

该服务器需要一个 JSON 配置文件来指定要连接的 MCP 服务器。你可以复制示例配置并根据实际需求进行修改:

cp config.example.json config.json

示例配置结构如下:

{
  "servers": [
    {
      "name": "Server 1",
      "transport": {
        "command": "/path/to/server1/build/index.js"
      }
    },
    {
      "name": "Server 2",
      "transport": {
        "command": "server2-command",
        "args": ["--option1", "value1"],
        "env": ["SECRET_API_KEY"]
      }
    },
    {
      "name": "Example Server 3",
      "transport": {
        "type": "sse",
        "url": "http://localhost:8080/sse"
      }
    }
  ]
}

在运行服务器时,必须提供配置文件:

MCP_CONFIG_PATH=./config.json mcp-proxy-server

与 Claude Desktop 集成

与 Claude Desktop 一起使用时,需要添加服务器配置:

  • 在 MacOS 上:~/Library/Application Support/Claude/claude_desktop_config.json
  • 在 Windows 上:%APPDATA%/Claude/claude_desktop_config.json

配置示例如下:

{
  "mcpServers": {
    "mcp-proxy": {
      "command": "/path/to/mcp-proxy-server/build/index.js",
      "env": {
        "MCP_CONFIG_PATH": "/absolute/path/to/your/config.json",
        "KEEP_SERVER_OPEN": "1"
      }
    }
  }
}

⚠️ 重要提示

KEEP_SERVER_OPEN 会在客户端断开时保持 SSE 运行,对于多个客户端连接到 MCP 代理很有用。

💻 使用示例

开发环境使用

安装依赖项

npm install

构建服务器

npm run build

带有自动重建的开发

npm run watch

带有连续运行的开发

# 标准输入输出
npm run dev
# SSE
npm run dev:sse

调试

由于 MCP 服务器通过 stdio 通信,调试可能具有挑战性。我们建议使用 MCP Inspector,它作为包脚本可用:

npm run inspector

Inspector 将提供访问浏览器中的调试工具的 URL。

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