mcp-gateway-worker
A Cloudflare Worker gateway that aggregates tools from multiple domain workers and exposes them via MCP JSON-RPC and REST endpoints with authentication, scope checks, and guardrails.
README
MCP Gateway Worker
Cloudflare Worker gateway that exposes MCP-compatible JSON-RPC (/mcp) and REST test endpoints (/tools, /tools/:name/call) over a single unified tool registry.
Live deployment
- Worker URL:
https://mcp-gateway-worker.to-jamz.workers.dev - MCP endpoint:
https://mcp-gateway-worker.to-jamz.workers.dev/mcp
Setup
pnpm install
pnpm wrangler secret put DOMAIN_SHARED_SECRET
pnpm dev
Build and verify
pnpm install
pnpm build
pnpm test
Targeted suites:
pnpm test:contract
pnpm test:validation
pnpm test:e2e
Deploy to Cloudflare
pnpm wrangler login
pnpm wrangler secret put DOMAIN_SHARED_SECRET
pnpm wrangler deploy
Production checklist before deploy:
- Replace local values in
wrangler.toml(DOMAIN_A_URL,DOMAIN_B_URL,ALLOWED_ORIGINS). - Replace
CLIENT_AUTH_TOKENand set least-privilegeCLIENT_ALLOWED_SCOPES. - Confirm upstream domain workers are reachable from Cloudflare.
Environment and secrets
wrangler.toml local vars:
ENVIRONMENTDOMAIN_A_URLDOMAIN_B_URLALLOWED_ORIGINSAUTH_MODECLIENT_AUTH_TOKENCLIENT_ALLOWED_SCOPESUPSTREAM_TIMEOUT_MSREQUEST_BODY_MAX_BYTESTOOL_ARGUMENT_MAX_BYTES
Required secret:
DOMAIN_SHARED_SECRET
Authentication model
- Client -> Gateway:
Authorization: Bearer <CLIENT_AUTH_TOKEN>(static-token mode). - Gateway -> Domain workers:
Authorization: Bearer <DOMAIN_SHARED_SECRET>. - Trusted scopes source:
CLIENT_ALLOWED_SCOPES(gateway does not trust raw scope headers directly for authorization).
Trust boundary
- Gateway is the policy enforcement boundary for auth, scope checks, origin checks, and canonical error mapping.
- Domain workers are upstream execution targets and are treated as untrusted for response shape (gateway validates upstream payloads).
Guardrails
- Origin checks apply only when an
Originheader is present. - Request and argument size limits are centralized via env-backed limits.
- Upstream calls use timeout/retry handling and normalize exceptions to canonical
UPSTREAM_ERROR.
Endpoints
GET /health->{ "status": "ok", "environment": "..." }GET /tools-> unified tool catalogPOST /tools/:name/call-> REST tool invocationPOST /mcp-> MCP JSON-RPC (tools/list,tools/call)
Use this MCP from any IDE
Any IDE/editor MCP client that supports HTTP/JSON-RPC can connect to this endpoint:
- URL:
https://mcp-gateway-worker.to-jamz.workers.dev/mcp - Method:
POST - Header:
Authorization: Bearer <CLIENT_AUTH_TOKEN> - Header:
Content-Type: application/json
Generic MCP client config shape:
{
"mcpServers": {
"mcp-gateway-worker": {
"transport": "http",
"url": "https://mcp-gateway-worker.to-jamz.workers.dev/mcp",
"headers": {
"Authorization": "Bearer <CLIENT_AUTH_TOKEN>"
}
}
}
}
Quick connectivity test:
curl -s -X POST https://mcp-gateway-worker.to-jamz.workers.dev/mcp \
-H "Authorization: Bearer <CLIENT_AUTH_TOKEN>" \
-H "content-type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
If your IDE uses a different MCP schema (for example command-based wrappers), map it to the same HTTP endpoint and headers above.
IDE-specific examples
The exact file path/key name can vary by IDE version, but these templates are the common setup patterns.
VS Code (MCP extension/client)
settings.json example:
{
"mcp.servers": {
"mcp-gateway-worker": {
"transport": "http",
"url": "https://mcp-gateway-worker.to-jamz.workers.dev/mcp",
"headers": {
"Authorization": "Bearer <CLIENT_AUTH_TOKEN>"
}
}
}
}
Cursor
.cursor/mcp.json example:
{
"mcpServers": {
"mcp-gateway-worker": {
"transport": "http",
"url": "https://mcp-gateway-worker.to-jamz.workers.dev/mcp",
"headers": {
"Authorization": "Bearer <CLIENT_AUTH_TOKEN>"
}
}
}
}
Windsurf
MCP config example:
{
"mcpServers": {
"mcp-gateway-worker": {
"transport": "http",
"url": "https://mcp-gateway-worker.to-jamz.workers.dev/mcp",
"headers": {
"Authorization": "Bearer <CLIENT_AUTH_TOKEN>"
}
}
}
}
JetBrains AI Assistant / IDE MCP client
MCP server entry example:
{
"name": "mcp-gateway-worker",
"transport": "http",
"url": "https://mcp-gateway-worker.to-jamz.workers.dev/mcp",
"headers": {
"Authorization": "Bearer <CLIENT_AUTH_TOKEN>"
}
}
If your IDE only supports command-based MCP launchers, create a tiny local proxy/wrapper that forwards to this HTTP endpoint with the same Authorization header.
Examples
curl -s http://127.0.0.1:8787/health
curl -s http://127.0.0.1:8787/tools \
-H "Authorization: Bearer replace-me"
curl -s -X POST http://127.0.0.1:8787/tools/sum/call \
-H "Authorization: Bearer replace-me" \
-H "content-type: application/json" \
-d '{"arguments":{"a":5,"b":7}}'
curl -s -X POST http://127.0.0.1:8787/mcp \
-H "Authorization: Bearer replace-me" \
-H "content-type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
Compatibility guard policy
- Canonical MCP error payloads are treated as compatibility contracts.
tests/contract/mcp-errors.snapshot.test.tsenforces stableerror.code,error.data.error_code, and snapshot shape.- Breaking payload changes require explicit contract/versioning updates and corresponding test updates.
Scripts
pnpm devpnpm buildpnpm testpnpm test:contractpnpm test:validationpnpm test:e2epnpm test:snapshots
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。