Token导航 LogoToken导航TokenDH.com
Agent Gateway MCP logo
运维云端未说明官方级别未说明来源级核验

Agent Gateway MCP

MCP Server

一个统一的路由网关服务器,将MCP(模型上下文协议)请求路由到多个后端MCP服务器,支持多种传输类型和代码模式验证。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
边缘计算TypeScriptClaudeClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

rock9u

提供方

rock9u

最后核验

2026/5/17 20:23

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP统一网关

一个统一的网关服务器,将MCP(模型上下文协议)请求路由到多个后端MCP服务器。内置于 荣誉 并可部署到 Cloudflare员工.

特性

  • 多服务器路由:自动将工具调用路由到相应的MCP服务器
  • 多种运输方式:支持stdio、HTTP和SSE(服务器发送事件)后端
  • 代码模式验证:内置代码模式的验证和执行
  • 时间戳跟踪:所有请求和响应的自动时间戳
  • 边缘就绪:在Cloudflare Workers或支持Hono的任何边缘运行时上运行

建筑

网关充当反向代理:

  1. 接收来自客户的MCP请求(如Claude Code)
  2. 根据工具名称模式确定哪个后端服务器应处理请求
  3. 将请求路由到相应的后端服务器(stdio进程、HTTP端点或SSE流)
  4. 将响应返回给客户端
┌─────────────┐          ┌──────────────────┐          ┌─────────────────┐
│ MCP Client  │  HTTP    │  Unified Gateway │  stdio   │  Serena MCP     │
│ (Claude)    │─────────▶│  (Hono Server)   │─────────▶│  Server         │
└─────────────┘          │                  │          └─────────────────┘
                         │                  │  HTTP    ┌─────────────────┐
                         │                  │─────────▶│  Figma MCP      │
                         │                  │          │  Server         │
                         │                  │          └─────────────────┘
                         │                  │  HTTP    ┌─────────────────┐
                         │                  │─────────▶│  Context7 MCP   │
                         └──────────────────┘          │  Server         │
                                                        └─────────────────┘

快速开始

1.安装依赖项

npm install

2.启动网关

npm start
# Server runs on http://localhost:3000

3.测试网关

# Check status
curl http://localhost:3000/gateway/status

# Health check
curl http://localhost:3000/health

网关端点

主要终点

端点方法描述
/获取欢迎信息和API文档
/mcpPOST带自动路由的主MCP端点
/gateway/:serverPOST路由到特定服务器
/gateway/statusGET查看所有已配置的服务器
/healthGET健康检查

/mcp 端点(推荐)

/mcp 端点根据工具名称模式自动将请求路由到适当的后端服务器。

MCP请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "mcp__serena__find_symbol",
    "arguments": {
      "name_path_pattern": "MyClass"
    }
  }
}

网关将自动检测到 mcp__serena__* 工具应该被路由到Serena服务器。

与MCP客户端集成

Claude代码集成

将网关添加到您的Claude代码配置中:

macOS/Linux:

# Edit: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
# Or: ~/.config/Claude/claude_desktop_config.json (Linux)

窗户:

# Edit: %APPDATA%\Claude\claude_desktop_config.json

配置:

{
  "mcpServers": {
    "unified-gateway": {
      "url": "http://localhost:3000/mcp",
      "transport": "streamable-http"
    }
  }
}

保存后,重新启动Claude Code。网关将自动将工具调用路由到相应的后端服务器。

其他MCP客户端

任何支持Streamable HTTP传输的MCP客户端都可以连接到网关:

// Example using MCP SDK
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const transport = new StreamableHTTPClientTransport({
  url: 'http://localhost:3000/mcp'
});

添加新的MCP服务器

要添加新的后端MCP服务器,请编辑 servers 对象在 src/index.ts:

示例1:HTTP服务器

const servers: Record = {
  // ... existing servers ...

  'my-custom-server': {
    type: 'http',
    url: 'https://my-server.example.com/mcp',
    tools: ['custom_*'], // Match all tools starting with "custom_"
    apiKey: 'optional-api-key' // Optional authentication
  }
};

示例2:Stdio服务器

const servers: Record = {
  // ... existing servers ...

  'python-tools': {
    type: 'stdio',
    command: 'python',
    args: ['-m', 'my_mcp_server'],
    tools: ['python_analyze', 'python_format']
  }
};

示例3:SSE服务器

const servers: Record = {
  // ... existing servers ...

  'streaming-server': {
    type: 'sse',
    url: 'https://streaming.example.com/mcp',
    tools: ['stream_*']
  }
};

工具匹配模式

tools array支持两种模式:

  1. 精确匹配: 'ping' 仅匹配名为“ping”的工具
  2. 统配符匹配: 'mcp__serena__*' 匹配以“mcp_sena\_”开头的所有工具

预配置服务器

网关附带了几个预配置的服务器:

服务器类型工具描述
serena站立mcp__serena__*代码分析和重构工具
figma-remotehttpfigma_*Figma设计工具
cloudflare-docshttpmcp__cloudflare-docs__*Cloudflare文档
context7httpmcp__context7__*图书馆文献查询
my-mcphttpping, start-notification-stream本地服务器示例

查看所有已配置的服务器:

curl http://localhost:3000/gateway/status

代码模式验证

网关包括对常见模式的内置验证:

  1. 参数必须是对象:确保工具参数结构正确
  2. 相对路径强制:Serena工具需要相对路径,而不是绝对路径
  3. 所需参数:验证特定工具所需的参数
  4. 时间戳元数据:自动添加验证时间戳

发展

本地开发

npm run dev
# Server runs on http://localhost:3000 with hot reload

使用MCP示例客户端进行测试

在一个终端中:

npm start

在另一个终端中:

node node_modules/@modelcontextprotocol/sdk/dist/esm/examples/client/simpleStreamableHttp.js

示例客户端中的命令:

> connect http://localhost:3000/mcp
> list-tools
> call-tool ping

部署

部署到Cloudflare Workers

npm run deploy

部署后,更新您的MCP客户端配置以使用Cloudflare Workers URL:

{
  "mcpServers": {
    "unified-gateway": {
      "url": "https://your-worker.workers.dev/mcp",
      "transport": "streamable-http"
    }
  }
}

Cloudflare Workers的配置

wrangler.jsonc 文件包括:

  • 入口点: src/index.ts
  • 兼容性: nodejs_compat Node.js流API的标志
  • 捆绑优化:别名未使用的依赖项以减小捆绑包大小

监控与调试

所有请求都会记录时间戳:

[2025-01-15T10:30:45.123Z] [Gateway] Request received
[2025-01-15T10:30:45.125Z] Matched tool 'mcp__serena__find_symbol' to server 'serena'
[2025-01-15T10:30:45.126Z] [stdio] Spawning uvx --from git+https://github.com/oraios/serena...
[2025-01-15T10:30:45.789Z] [stdio] Process completed with code 0
[2025-01-15T10:30:45.790Z] [Gateway] Request completed

检查日志:

  • 本地:终端中的控制台输出
  • Cloudflare员工:在Cloudflare仪表板的Workers&Pages下查看→ 您的员工→ Logs

故障排除

找不到服务器

错误: No server found for tool 'my_tool'

解决方案:将工具模式添加到服务器的 tools 数组in src/index.ts:

'my-server': {
  type: 'http',
  url: 'http://localhost:3000/mcp',
  tools: ['my_tool', 'other_tool']
}

验证失败

错误: Code pattern validation failed: Serena tools require relative paths

解决方案:使用相对路径而不是绝对路径:

// ❌ Wrong
{ relative_path: '/Users/name/project/file.ts' }

// ✅ Correct
{ relative_path: 'src/file.ts' }

Stdio服务器超时

错误: Request timeout

解决方案:

  • 检查stdio命令是否正确且可执行
  • 确保服务器在30秒内响应
  • 检查stderr日志中的错误

API 参考

服务器配置界面

interface ServerConfig {
  type: 'stdio' | 'http' | 'sse';
  command?: string;      // For stdio: command to execute
  args?: string[];       // For stdio: command arguments
  url?: string;          // For http/sse: endpoint URL
  apiKey?: string;       // Optional: API key for authentication
  tools?: string[];      // Tool name patterns to match
}

许可证

麻省理工学院

贡献

欢迎投稿!请确保您的更改:

  1. 遵循现有代码样式
  2. 包括适当的错误处理
  3. 添加调试日志
  4. 更新文档

资源

目录标签

目录标签

边缘计算TypeScriptClaude路由网关本地部署协议代理多服务器支持代码验证

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

api-key

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明api-key部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP