MCP Cloudflare网关
基于Cloudflare Workers的网关,将MCP(模型上下文协议)服务器请求从Gemini CLI路由到本地或远程MCP服务器。
特性
- 🌐 Cloudflare Workers 托管-无服务器、自动扩展
- 🔄 反向代理 用于本地MCP服务器
- 🔐 安全 环境变量管理
- 📊 基于HTTP MCP服务器支持
- 🚀 快速 边缘计算的响应时间
- 🧹 简单 牧马人部署
支持的MCP服务器
- GitHub -GitHub Copilot MCP
- 火爬 -网络抓取和爬行
- 苏巴酶 -数据库操作
- netlify -部署管理
- 困惑度 -网络搜索
- 双子座-形象 -图像生成
- 以及更多基于HTTP的MCP服务器
设置
先决条件
- 18+
- 牧马人CLI
- 启用Workers的Cloudflare帐户
- MCP服务器的API密钥
安装
# Clone the repository
git clone https://github.com/elwrush/mcp-cloudflare-gateway.git
cd mcp-cloudflare-gateway
# Install dependencies
npm install
# Configure Wrangler
wrangler login部署
# Deploy to Cloudflare Workers
wrangler deploy您的员工将住在 https://mcp-gateway..workers.dev
配置
环境变量
将API密钥添加到 wrangler.toml:
[env.production]
bindings = [
{ name = "GITHUB_TOKEN", text = "your-github-token" },
{ name = "FIRECRAWL_API_KEY", text = "your-firecrawl-key" },
{ name = "SUPABASE_TOKEN", text = "your-supabase-token" },
# ... add more as needed
]Gemini CLI配置
更新您的 .gemini-cli/config.json:
{
"mcpServers": {
"github": {
"httpUrl": "https://mcp-gateway..workers.dev/proxy/github",
"headers": {
"Authorization": "Bearer YOUR_GITHUB_TOKEN"
}
},
"firecrawl-remote": {
"httpUrl": "https://mcp-gateway..workers.dev/servers/firecrawl/call",
"headers": {
"x-api-key": "YOUR_FIRECRAWL_KEY"
}
}
}
}用法
在Gemini CLI会话中,您现在可以使用任何配置的MCP服务器:
gemini
> use-mcp github
> list-tools
> call github_search {"query": "your query"}建筑
Gemini CLI
|
v
[HTTPS Request]
|
v
Cloudflare Worker Gateway
|
+----> HTTP MCP Server (github, firecrawl, etc.)
|
+----> Local MCP Server (via reverse proxy)
|
v
[HTTPS Response]
|
v
Gemini CLIAPI终点
健康检查
GET /health退货 {"status": "ok"}
列出服务器
GET /servers返回可用MCP服务器的列表
获取服务器架构
GET /servers/:name/schema?auth=返回MCP服务器架构和可用工具
呼叫服务器工具
POST /servers/:name/call
Content-Type: application/json
{
"method": "tools/call",
"jsonrpc": "2.0",
"params": { ... },
"id": 1
}代理终结点
POST /proxy/:name/*直接代理到基于HTTP的MCP服务器
发展
局部测试
# Start development server
wrangler dev
# Test health endpoint
curl http://localhost:8787/health
# List servers
curl http://localhost:8787/servers添加新的MCP服务器
- 增添
MCP_SERVERS注册表在src/index.ts - 将环境变量添加到
wrangler.toml - 部署:
wrangler deploy
安全考虑
- API密钥存储为Cloudflare环境变量(在静止时加密)
- 仅使用HTTPS进行通信
- 在生产中实施请求速率限制
- 为敏感服务器添加身份验证中间件
故障排除
404未找到
确保服务器名称与您的配置完全匹配
502网关故障
检查MCP服务器是否正在运行且可访问
401未经授权
验证API密钥是否在环境变量中正确设置
许可证
麻省理工学院
支持
对于问题或疑问,请在GitHub上打开问题。
