MCP Gateway
MCP Gateway – MCP-Agent-Gateway
Einheitliches Gateway für den Zugriff und die Verwaltung mehrerer MCP-Server auf Unternehmensebene: Der übergeordnete LLM-Agent verbindet sich nur mit dem Gateway als einem einzigen Einstiegspunkt und kann dann die Tools aller dahinter liegenden MCP-Server aufrufen, wobei Authentifizierung, Ratenbegrenzung, Protokollierung und Metriken abgedeckt sind.
Architektur
┌─────────────────────────────┐
│ LLM Agent / 应用 │
│ (LangChain / OpenAI 等) │
└──────────────┬──────────────┘
│ 统一 REST API
┌──────────────▼──────────────┐
│ MCP Gateway (FastAPI) │
│ ┌────────────────────────┐ │
│ │ 鉴权 (API Key) │ │
│ │ 限流 (令牌桶) │ │
│ │ 日志 / 指标 (横切层) │ │
│ └───────────┬────────────┘ │
│ ┌───────────▼────────────┐ │
│ │ 工具注册中心 registry │ │
│ │ (聚合所有 server 工具) │ │
│ └───────────┬────────────┘ │
│ ┌───────────▼────────────┐ │
│ │ MCP 客户端 (多传输) │ │
│ └────────────────────────┘ │
└───────┬───────────┬───────────┘
stdio ──┤ ├── Streamable HTTP / SSE
┌──────────────▼──┐ ┌────▼───────────────┐
│ MCP Server #1 │ │ MCP Server #2 ... │
│ (demo_sql_server)│ │ (数据库/内部API等) │
└─────────────────┘ └─────────────────────┘Related MCP server: Peta Core
Technologie-Stack
Python 3.12 · FastAPI · MCP Official SDK (stdio / SSE / Streamable HTTP) · pydantic-settings + YAML · structlog · Prometheus · SQLite (Schnittstellenabstraktion, austauschbar mit PostgreSQL) · pytest · Docker · GitHub Actions · uv
Schnellstart
uv sync # 安装依赖(自动准备 Python 3.12)
uv run uvicorn app.main:app --reload # 启动开发服务器
uv run pytest # 运行测试
uv run ruff check . # lint
docker compose up --build # 一键启动Nach dem Start aufrufen:
GET /health— GesundheitscheckGET /metrics— Prometheus-Metriken (Tool-Aufrufanzahl/-dauer:mcp_gateway_tool_calls_total,mcp_gateway_tool_call_duration_seconds)GET /docs— OpenAPI-Interaktionsdokumentation
Aufrufbeispiel (Demo-Key siehe Abschnitt auth in config/gateway.yaml):
curl -H "X-API-Key: dev-key-please-change" http://localhost:8000/tools
curl -X POST http://localhost:8000/tools/demo_sql__ask/call \
-H "X-API-Key: dev-key-please-change" -H "Content-Type: application/json" \
-d '{"arguments": {"question": "有多少客户?"}}'demo_sql_server enthält eine Mini-E-Commerce-Bibliothek (customers / products / orders) und stellt 4 Tools bereit: ask (chinesische Frage → automatisch generiertes und ausgeführtes schreibgeschütztes SQL), run_sql (direktes Ausführen von schreibgeschütztem SQL), list_tables (Tabellenstruktur), echo (Link-Debugging). NL2SQL ist eine Regel-Template-Engine, offline ohne Abhängigkeiten, die Schnittstelle ist von der LLM-Implementierung entkoppelt und kann nahtlos ersetzt werden.
Konfiguration
config/gateway.yaml (Priorität: Standardwerte im Code < YAML < Umgebungsvariablen GATEWAY_*):
gateway:
port: 8000
log_level: INFO
auth: # API Key 鉴权(SQLite 存储,启动种子写入)
db_path: data/gateway.db
api_keys:
- { key: dev-key-please-change, name: demo, rate_limit_per_minute: 60 }
servers: # MCP Server 声明式接入,无需改代码
- name: demo_sql
transport: stdio # stdio / sse / http
command: python
args: ["servers/demo_sql_server/server.py"]Docker Compose verwendet config/gateway.docker.yaml: demo_sql läuft als separater Container mit Streamable HTTP, das Gateway verbindet sich über http://demo_sql:9001/mcp.
Projektstruktur
app/
├── main.py # FastAPI 入口
├── config.py # 配置中心(pydantic-settings + YAML)
├── core/ # 横切层:security / rate_limit / logging / metrics
├── mcp/ # 协议层:registry / client / transports / schemas
├── api/ # 接口层:deps.py + routes/
└── schemas/ # Pydantic 模型
servers/demo_sql_server/ # 示例 MCP Server(自然语言→SQL,阶段 2/4)
examples/ # LLM Agent 调用示例(阶段 5)
tests/ # 单元测试Entwicklungs-Roadmap
Phase 1: Framework + CI (/health, /metrics, Konfigurationszentrum, strukturiertes Logging)
Phase 2: Protokollebene (stdio/SSE/HTTP-Client für drei Transporte + Tool-Registrierungszentrum + Demo-Server)
Phase 3: Einheitliche API (GET /tools, POST /tools/{name}/call) + API-Key-Authentifizierung + Token-Bucket-Ratenbegrenzung
Phase 4: Tool-Aufrufmetriken + Upgrade von demo_sql_server auf NL2SQL + docker-compose mit zwei Containern (öffentliche Bereitstellung und Demo-Bildschirmaufzeichnung noch ausstehend)
Phase 5: Agent-Aufrufbeispiele + Open-Source-Promotion
Erweiterungspfade für Unternehmen
Multi-Tenancy + RBAC · Modell-Routing (analog zu One-API) · Audit-Compliance · Automatische Skalierung in K8s · OpenTelemetry-Tracing · Circuit Breaker / Caching
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
An MCP gateway for teams deploying AI tools at scale to employee-facing and headless agents.
MCP gateway: one connection for your AI apps, with tool policies, PII redaction and audit logs.
MCP gateway with runtime security policy, tool-call-level control, and audit of agent actions.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA production-ready unified entry point for AI agents that implements the Model Context Protocol (MCP). It provides a secure gateway with rate limiting, authentication, and observability for managing and proxying requests to multiple downstream APIs.MIT
- FlicenseNot gradedqualityCmaintenanceA production-ready MCP gateway and control plane that provides credential vault, policy engine, audit logging, and managed runtime for routing tool calls between AI agents and downstream MCP servers.60-
- FlicenseNot gradedqualityBmaintenanceSingle gateway that aggregates dozens of upstream MCP servers, enabling AI clients to connect once and access all tools.-
- AlicenseNot gradedqualityCmaintenanceA unified MCP gateway that aggregates multiple MCP servers and API plugins behind a single endpoint with authentication, rate limiting, audit logging, REST API bridge, and web dashboard.8MIT