MCP网关服务

MCP网关服务是一个用于爬取、分类和代理2200多个远程MCP服务器的工具,具有智能速率限制和基于Grok的跟踪生成功能。

  • by dako2
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 dako2/mcp-gateway

使用说明

MCP网关

爬取、编目和代理2200+远程MCP服务器,具有智能速率限制和Grok驱动的跟踪生成功能。

里面是什么

目录 目录
data/servers.json 2246个MCP端点(739个健康,需要1507个身份验证)
data/tools.json 267台服务器,包含3356个工具定义(完整的JSON模式)
mcp_servers/ 267 Toucan格式化服务器文件,包括标签、类别和流行度
src/ 爬虫、网关、速率限制器、跟踪生成器
datagen/ 基于Toucan的数据生成管道(为Grok修改)

快速开始

pip install -r requirements.txt

将密钥添加到 .env:

SMITHERY_API_KEY=your-smithery-key
XAI_API_KEY=xai-your-grok-key

命令

1.爬取MCP服务器

# Full crawl: 8 techniques, 10+ sources, health check all
cd src && python -u crawl.py

# Fetch full tool definitions from healthy servers
cd src && python -u list_tools.py

# Probe rate limits (adds rate_limit field to servers.json)
cd src && python -u probe_rate_limits.py

# Convert tools.json to Toucan format (for datagen pipeline)
cd src && python -u convert_to_toucan.py

2.启动网关

cd src && uvicorn gateway:app --host 0.0.0.0 --port 8000

终点:

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

# List healthy servers
curl http://localhost:8000/servers

# Proxy an MCP request (rate-limited per host)
curl -X POST http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "target": "https://mcp.deepwiki.com/mcp",
    "request": {"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}
  }'

# View rate limiter stats
curl http://localhost:8000/stats

3.生成痕迹(使用Grok)

# Direct trace generation (simple, fast)
cd src && python -u trace_gen.py --count 100 --concurrent 20

# High throughput
cd src && python -u trace_gen.py --count 5000 --concurrent 100

# Toucan pipeline (full quality control)
cd datagen

# Step 1.1: Generate question prompts from server tools
python step1.1_gen_questions.py --total_prompts 1000 --sampling_strategy random

# Step 1.2: LLM generates questions (using Grok)
bash run_with_grok.sh completion <file_from_step1.1>

# Step 1.3: Deduplicate and clean
python step1.3_process_completion.py --input_file <file_from_step1.2>

# Step 2.1-2.3: Question quality check
python step2.1_question_quality_check.py --input_file <*_3sanitized.jsonl>
bash run_with_grok.sh completion <file_from_step2.1>
python step2.3_process_completion.py --input_file <file_from_step2.2>

# Step 3.1-3.2: Agent trace generation (calls real MCP tools)
bash run_with_grok.sh trace_gen <*_2prepared.jsonl>
python step3.2_process_completion.py --input_file <file_from_step3.1>

# Step 4.1-4.3: Response quality check
python step4.1_response_quality_check.py --input_file <file_from_step3.2>
bash run_with_grok.sh completion <file_from_step4.1>
python step4.3_process_completion.py --input_file <file_from_step4.2>

# Multi-turn conversations
bash ext_completion_multi_turn.sh <input_file> grok-4-1-fast-reasoning xai 5

4.为服务器配置身份验证

编辑 data/auth_keys.json 为需要身份验证的服务器添加API密钥:

{
  "pattern": "mcp.notion.com",
  "header": "Authorization",
  "value": "Bearer ntn_your_actual_key"
}

爬行源

来源 技术 产量
MCP官方注册 API投票 1069
Smithery注册表 API轮询 700
mcpservers.org HTML抓取 159
Toucan数据集 GitHub克隆+健康检查 126
DNS端点探测 模式猜测 100
出色的远程mcp服务器 Markdown解析 94
mcp.so HTML抓取 28
GitHub API搜索 代码+回购搜索 25
出色的mcp服务器列表 Markdown解析 23

网关功能

  • 每台主机自适应令牌桶速率限制
  • 从响应标头中发现QPS(49台具有已知限制的服务器)
  • 自动429退避学习(速率减半,指数退避)
  • 针对需要身份验证的服务器的API密钥注入(预先配置了24个服务)
  • 学习率持续到 data/rate_limits.json

跟踪生成

  • 用途 grok-4-1-fast-reasoning (每100万代币0.20美元/0.50美元)
  • 内置xAI速率限制器(460 RPM)
  • 工具调用通过网关路由(每个MCP服务器的QPS保护)
  • 支持单轮、多轮、单服务器、多服务器场景
  • 约14000道/小时理论吞吐量