Skip to main content
Glama
MCP Gateway

MCP Gateway

by NightR71

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

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A 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
    • F
      license
      Not graded
      quality
      C
      maintenance
      A 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
      -