多MCP服务器代理

一个连接多个MCP服务器并提供统一工具访问接口的代理服务,支持多种配置文件和运行模式。

  • by amirilovic
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 amirilovic/mcp-server-proxy

使用说明

MCP服务器代理

连接到多个MCP服务器并为工具访问提供统一接口的代理服务器。

特性

  • 同时连接到多个MCP服务器
  • 支持多种配置文件
  • 工具名称前缀为服务器名称
  • 在stdio或SSE模式下运行
  • 基于配置文件的配置管理

配置

按以下格式为每个配置文件创建配置文件 config.<profile>.json例如:

// config.developer.json
{
  "mcpServers": {
    "kubernetes": {
      "command": "npx",
      "args": ["mcp-server-kubernetes"]
    }
  }
}
// config.personal.json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/mirilale/Desktop"
      ]
    }
  }
}

安装

npm install

用法

命令行选项

可以使用各种命令行选项启动服务器:

# Start with default settings
node dist/server.js

# Start with a specific profile
node dist/server.js --profile developer
# or
node dist/server.js -p developer

# Start in SSE mode
node dist/server.js --mode sse
# or
node dist/server.js -m sse

# Start in SSE mode with custom port and host
node dist/server.js --mode sse --port 8080 --host 0.0.0.0

# Combine options
node dist/server.js --profile developer --mode sse --port 8080

可用选项:

  • -p, --profile <name>:指定要使用的配置文件(默认为“默认”)
  • -m, --mode <mode>:在“stdio”或“sse”模式之间进行选择(默认为“stdio“)
  • --port <number>:设置SSE模式的端口(默认为3000)
  • --host <host>:将主机设置为SSE模式(默认为“localhost”)

获取帮助:

node dist/server.js --help

工具命名约定

工具以其服务器名称作为前缀。例如:

  • 一个名为 read_file 从 filesystem 服务器变成 filesystem_read_file
  • 一个名为 get_pods 从 kubernetes 服务器变成 kubernetes_get_pods

SSE模式端点

在SSE模式下运行时,服务器会公开以下端点:

  • GET /sse:建立SSE连接
  • POST /messages:处理工具请求(需要 sessionId 查询参数)

SSE客户端使用示例:

const eventSource = new EventSource("http://localhost:3000/sse");
eventSource.onmessage = (event) => {
  console.log("Received:", event.data);
};

错误处理

服务器提供详细的错误消息,包括:

  • 配置文件加载错误
  • 服务器连接失败
  • 工具未找到错误
  • 服务器断开连接错误

为了更好地理解上下文,所有错误都包括当前配置文件名称。

发展

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev:stdio:developer
# or
npm run dev:sse:developer
# Run with mpc inspector
npm run inspect

许可证

麻省理工学院