一个MCP代理服务器,通过单一接口聚合并提供多个MCP资源服务器的服务。该服务器作为中心枢纽可以:
服务器需要一个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
安装依赖项:
npm install
构建服务器:
npm run build
对于带有自动重建功能的开发:
npm run watch
对于持续运行的开发:
# Stdio
npm run dev
# SSE
npm run dev:sse

要在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代理时非常有用。由于MCP服务器通过stdio通信,调试可能具有挑战性。我们建议使用MCP Inspector,它作为一个包脚本可用:
npm run inspector
Inspector将提供一个URL,以便您在浏览器中访问调试工具。