MCP Gateway

MCP Gateway

A multiplexing gateway that aggregates multiple MCP servers into a single port, significantly reducing context token usage through a Meta-MCP discovery system. It enables dynamic tool discovery and invocation across various transport protocols including stdio, HTTP, and SSE.

Category
访问服务器

README

MCP Gateway

Crates.io Rust License: MIT

Universal Model Context Protocol (MCP) Gateway - Single-port multiplexing with Meta-MCP for ~95% context token savings.

The Problem

MCP is powerful, but scaling to many servers creates problems:

Without Gateway With Gateway
100+ tool definitions in context 4 meta-tools
~15,000 tokens overhead ~400 tokens
Multiple ports to manage Single port
Session loss on reconnect Persistent proxy
No resilience Circuit breakers, retries, rate limiting

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     MCP Gateway (:39400)                         │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Meta-MCP Mode: 4 Tools → Access 100+ Tools Dynamically  │    │
│  │  • gateway_list_servers    • gateway_search_tools        │    │
│  │  • gateway_list_tools      • gateway_invoke              │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                   │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Failsafes: Circuit Breaker │ Retry │ Rate Limit        │    │
│  └─────────────────────────────────────────────────────────┘    │
│                              │                                   │
│         ┌────────────────────┼────────────────────┐             │
│         ▼                    ▼                    ▼             │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐         │
│  │   Tavily    │    │  Context7   │    │   Pieces    │         │
│  │  (stdio)    │    │   (http)    │    │   (sse)     │         │
│  └─────────────┘    └─────────────┘    └─────────────┘         │
└─────────────────────────────────────────────────────────────────┘

Features

Meta-MCP Mode (~95% Token Savings)

Instead of loading 100+ tool definitions, Meta-MCP exposes 4 meta-tools:

Meta-Tool Purpose
gateway_list_servers List available backends
gateway_list_tools List tools from a specific backend
gateway_search_tools Search tools by keyword across all backends
gateway_invoke Invoke any tool on any backend

Token Math:

  • Traditional: 100 tools × 150 tokens = 15,000 tokens
  • Meta-MCP: 4 tools × 100 tokens = 400 tokens
  • Savings: 97%

Production Failsafes

Failsafe Description
Circuit Breaker Opens after 5 failures, half-opens after 30s
Retry with Backoff 3 attempts with exponential backoff
Rate Limiting Per-backend request throttling
Health Checks Periodic ping to detect failures
Graceful Shutdown Clean connection termination
Concurrency Limits Prevent backend overload

Protocol Support

  • MCP Version: 2025-11-25 (latest)
  • Transports: stdio, Streamable HTTP, SSE
  • JSON-RPC 2.0: Full compliance

Quick Start

Installation

cargo install mcp-gateway

Usage

# Start with configuration file
mcp-gateway --config servers.yaml

# Override port
mcp-gateway --config servers.yaml --port 8080

# Debug logging
mcp-gateway --config servers.yaml --log-level debug

Configuration

Create servers.yaml:

server:
  port: 39400

meta_mcp:
  enabled: true

failsafe:
  circuit_breaker:
    enabled: true
    failure_threshold: 5
  retry:
    enabled: true
    max_attempts: 3

backends:
  tavily:
    command: "npx -y @anthropic/mcp-server-tavily"
    description: "Web search"
    env:
      TAVILY_API_KEY: "${TAVILY_API_KEY}"

  context7:
    http_url: "http://localhost:8080/mcp"
    description: "Documentation lookup"

Client Configuration

Point your MCP client to the gateway:

{
  "mcpServers": {
    "gateway": {
      "type": "http",
      "url": "http://localhost:39400/mcp"
    }
  }
}

API Reference

Endpoints

Endpoint Method Description
/health GET Health check with backend status
/mcp POST Meta-MCP mode (dynamic discovery)
/mcp/{backend} POST Direct backend access

Health Check Response

{
  "status": "healthy",
  "version": "1.0.0",
  "backends": {
    "tavily": {
      "name": "tavily",
      "running": true,
      "transport": "stdio",
      "tools_cached": 3,
      "circuit_state": "Closed",
      "request_count": 42
    }
  }
}

Configuration Reference

Server

Field Type Default Description
host string 127.0.0.1 Bind address
port u16 39400 Listen port
request_timeout duration 30s Request timeout
shutdown_timeout duration 30s Graceful shutdown timeout

Meta-MCP

Field Type Default Description
enabled bool true Enable Meta-MCP mode
cache_tools bool true Cache tool lists
cache_ttl duration 5m Cache TTL

Failsafe

Field Type Default Description
circuit_breaker.enabled bool true Enable circuit breaker
circuit_breaker.failure_threshold u32 5 Failures before open
circuit_breaker.success_threshold u32 3 Successes to close
circuit_breaker.reset_timeout duration 30s Half-open delay
retry.enabled bool true Enable retries
retry.max_attempts u32 3 Max retry attempts
retry.initial_backoff duration 100ms Initial backoff
retry.max_backoff duration 10s Max backoff
rate_limit.enabled bool true Enable rate limiting
rate_limit.requests_per_second u32 100 RPS per backend

Backend

Field Type Required Description
command string * Stdio command
http_url string * HTTP/SSE URL
description string Human description
enabled bool Default: true
timeout duration Request timeout
idle_timeout duration Hibernation delay
env map Environment variables
headers map HTTP headers
cwd string Working directory

*One of command or http_url required

Environment Variables

Variable Description
MCP_GATEWAY_CONFIG Config file path
MCP_GATEWAY_PORT Override port
MCP_GATEWAY_HOST Override host
MCP_GATEWAY_LOG_LEVEL Log level
MCP_GATEWAY_LOG_FORMAT text or json

Metrics

With --features metrics:

curl http://localhost:39400/metrics

Exposes Prometheus metrics for:

  • Request count/latency per backend
  • Circuit breaker state changes
  • Rate limiter rejections
  • Active connections

Building

git clone https://github.com/MikkoParkkola/mcp-gateway
cd mcp-gateway
cargo build --release

License

MIT License - see LICENSE for details.

Credits

Created by Mikko Parkkola

Implements Model Context Protocol version 2025-11-25.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选