MCP Gateway
MCP Gateway — MCP 지능형 게이트웨이
여러 MCP Server를 통합 관리하는 엔터프라이즈급 도구 게이트웨이: 상위 LLM Agent는 게이트웨이 하나의 진입점만 연결하면, 뒤에 있는 여러 MCP Server가 제공하는 도구를 호출할 수 있으며, 인증, 속도 제한, 로깅, 메트릭을 전반적으로 지원합니다.
아키텍처
┌─────────────────────────────┐
│ 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
기술 스택
Python 3.12 · FastAPI · MCP 공식 SDK (stdio / SSE / Streamable HTTP) · pydantic-settings + YAML · structlog · Prometheus · SQLite (인터페이스 계층 추상화, PostgreSQL로 교체 가능) · pytest · Docker · GitHub Actions · uv
빠른 시작
uv sync # 安装依赖(自动准备 Python 3.12)
uv run uvicorn app.main:app --reload # 启动开发服务器
uv run pytest # 运行测试
uv run ruff check . # lint
docker compose up --build # 一键启动시작 후 접속:
GET /health— 상태 확인GET /metrics— Prometheus 메트릭 (도구 호출 횟수/소요 시간 포함:mcp_gateway_tool_calls_total,mcp_gateway_tool_call_duration_seconds)GET /docs— OpenAPI 대화형 문서
호출 예시 (데모 키는 config/gateway.yaml의 auth 섹션 참조):
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는 내장 미니 전자상거래 데이터베이스(customers / products / orders)를 포함하며, 4개의 도구를 제공합니다:
ask (중국어 질문 → 자동 생성 및 읽기 전용 SQL 실행), run_sql (직접 읽기 전용 SQL 실행),
list_tables (테이블 구조), echo (링크 디버깅). NL2SQL은 규칙 템플릿 엔진으로,
오프라인에서 의존성 없이 작동하며, 인터페이스와 LLM 구현이 분리되어 있어 원활하게 교체 가능합니다.
설정
config/gateway.yaml (우선순위: 코드 기본값 < YAML < 환경 변수 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는 config/gateway.docker.yaml을 사용합니다: demo_sql은 독립 컨테이너로
Streamable HTTP를 실행하고, 게이트웨이는 http://demo_sql:9001/mcp를 통해 연결합니다.
프로젝트 구조
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/ # 单元测试개발 로드맵
1단계: 엔지니어링 스켈레톤 + CI (/health, /metrics, 설정 센터, 구조화된 로깅)
2단계: 프로토콜 계층 연결 (stdio/SSE/HTTP 세 가지 전송 클라이언트 + 도구 등록 센터 + 데모 서버)
3단계: 통합 API (GET /tools, POST /tools/{name}/call) + API Key 인증 + 토큰 버킷 속도 제한
4단계: 도구 호출 메트릭 + demo_sql_server NL2SQL 업그레이드 + docker-compose 이중 컨테이너 (공개 배포 및 데모 녹화는 추후 보완)
5단계: Agent 호출 예시 + 오픈소스 홍보
엔터프라이즈 확장 경로
멀티 테넌트 + RBAC · 모델 라우팅 (One-API 유사) · 감사 컴플라이언스 · K8s 자동 확장/축소 · OpenTelemetry 트레이싱 · 서킷 브레이커 / 캐싱
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