MCP Hub
Back to servers

mcp-gateway

Universal MCP Gateway - Single-port multiplexing with Meta-MCP for ~95% context token savings

glama
Updated
Jan 25, 2026

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 GatewayWith Gateway
100+ tool definitions in context4 meta-tools
~15,000 tokens overhead~400 tokens
Multiple ports to manageSingle port
Session loss on reconnectPersistent proxy
No resilienceCircuit 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-ToolPurpose
gateway_list_serversList available backends
gateway_list_toolsList tools from a specific backend
gateway_search_toolsSearch tools by keyword across all backends
gateway_invokeInvoke 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

FailsafeDescription
Circuit BreakerOpens after 5 failures, half-opens after 30s
Retry with Backoff3 attempts with exponential backoff
Rate LimitingPer-backend request throttling
Health ChecksPeriodic ping to detect failures
Graceful ShutdownClean connection termination
Concurrency LimitsPrevent 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

EndpointMethodDescription
/healthGETHealth check with backend status
/mcpPOSTMeta-MCP mode (dynamic discovery)
/mcp/{backend}POSTDirect 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

FieldTypeDefaultDescription
hoststring127.0.0.1Bind address
portu1639400Listen port
request_timeoutduration30sRequest timeout
shutdown_timeoutduration30sGraceful shutdown timeout

Meta-MCP

FieldTypeDefaultDescription
enabledbooltrueEnable Meta-MCP mode
cache_toolsbooltrueCache tool lists
cache_ttlduration5mCache TTL

Failsafe

FieldTypeDefaultDescription
circuit_breaker.enabledbooltrueEnable circuit breaker
circuit_breaker.failure_thresholdu325Failures before open
circuit_breaker.success_thresholdu323Successes to close
circuit_breaker.reset_timeoutduration30sHalf-open delay
retry.enabledbooltrueEnable retries
retry.max_attemptsu323Max retry attempts
retry.initial_backoffduration100msInitial backoff
retry.max_backoffduration10sMax backoff
rate_limit.enabledbooltrueEnable rate limiting
rate_limit.requests_per_secondu32100RPS per backend

Backend

FieldTypeRequiredDescription
commandstring*Stdio command
http_urlstring*HTTP/SSE URL
descriptionstringHuman description
enabledboolDefault: true
timeoutdurationRequest timeout
idle_timeoutdurationHibernation delay
envmapEnvironment variables
headersmapHTTP headers
cwdstringWorking directory

*One of command or http_url required

Environment Variables

VariableDescription
MCP_GATEWAY_CONFIGConfig file path
MCP_GATEWAY_PORTOverride port
MCP_GATEWAY_HOSTOverride host
MCP_GATEWAY_LOG_LEVELLog level
MCP_GATEWAY_LOG_FORMATtext 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.

Reviews

No reviews yet

Sign in to write a review