Skip to main content

Overview

Stop spawning. Start sharing.

MCP Gateway is a process-sharing layer that sits between your AI client (Claude Code, Cursor, etc.) and your MCP servers. Instead of each terminal spawning its own server processes, all terminals share a single set of backend processes through the gateway.

The Problem

Traditional MCP spawns separate server processes per terminal:

Terminal 1 → github (50MB) + supabase (60MB) + filesystem (40MB)
Terminal 2 → github (50MB) + supabase (60MB) + filesystem (40MB)
Terminal 3 → github (50MB) + supabase (60MB) + filesystem (40MB)
─────────────────────────────────────────────────────────────────
Total: 9 processes consuming 450MB RAM

With 10-15 terminals across multiple workspaces, that's 30-45 separate Node processes eating RAM.

The Solution

MCP Gateway shares server processes across all terminals:

Terminal 1 ─┐
Terminal 2 ─┼──→ MCP Gateway (20MB) ──→ github (50MB)
Terminal 3 ─┘ │ supabase (60MB)
└──────────────→ filesystem (40MB)
─────────────────────────────────────────────────────────────────
Total: 4 processes consuming 170MB RAM (62% reduction)

Scale it up: 20 terminals × 5 servers = 100 processes → just 6 processes. That's 94% fewer processes.

Features

FeatureDescription
Hot ConfigurationAdd/remove servers without restarting your AI session
Project-Aware CredentialsEach project's .env isolates its API keys
Lazy Tool DiscoveryTools load on-demand, saving context tokens
Intelligent Process SharingServers shared globally, per-workspace, or per-credential
Flexible AuthBearer tokens, API keys, or localhost trust
Scope ProtectionGlobal config changes require explicit confirmation
Instant AvailabilityNew servers available immediately—no restart required
Self-HealingCrashed servers auto-restart with exponential backoff

Key Benefits

MetricTraditionalWith GatewayImprovement
Processes (7 terminals)284-6↓ 78%
Memory usage~1.1 GB~235 MB↓ 79%
Tokens per message~67,500~800↓ 99%
Startup (new terminal)2-4 sec<100ms↓ 95%

Architecture

Process sharing modes:

  • Global — Single instance shared by all terminals (Context7)
  • Per-workspace — One instance per project directory (Supabase)
  • Per-credential — One instance per unique API token (GitHub)

Hot Configuration

The gateway watches configuration files and automatically reloads when they change:

  • Instant availability: Add a new server to your config and it's immediately available to all connected terminals—no restart required.
  • No session interruption: Existing terminal sessions continue working while new servers come online.
  • Lazy spawning: Server processes aren't started until you actually use a tool from that server.
Practical example

You're in the middle of a Claude Code session and realize you need the Playwright MCP server. Run mcpg install playwright in another terminal, and within seconds the browser automation tools are available in your current session—without restarting anything.

Environment Variables

The gateway supports per-project credentials through .env files:

# /my-project/.env
SUPABASE_PROJECT_REF=abc123xyz
SUPABASE_ACCESS_TOKEN=sbp_xxxxxxxxxxxxx
GITHUB_TOKEN=ghp_xxxxxxxxxxxxx

Different projects can use different credentials for the same server. The gateway resolves credentials based on the cwd context passed with each request.

Resolution Order

PrioritySourceExample
1 (highest)Workspace .env file/my-project/.env
2Gateway .env file~/.mcp-gateway/.env
3Profile env: blockInline values in config.yaml
4 (lowest)System environmentexport GITHUB_TOKEN=xxx

Workspace .env files override gateway defaults, allowing shared credentials with per-project overrides.

Security

Never commit .env files to version control. Add .env to your .gitignore.

Process Lifecycle

Backend server processes are managed automatically:

  • Lazy start: Processes spawn on first tool call, not at gateway startup.
  • Health monitoring: The gateway checks process health and automatically restarts crashed servers.
  • Exponential backoff: Failed restarts wait progressively longer to prevent thrashing.
  • Circuit breaker: After repeated failures, servers are temporarily disabled.
  • Graceful shutdown: SIGTERM to all backend processes with clean shutdown wait.

Supported Server Types

TypeDescriptionExample
HTTPPre-hosted MCP servers with HTTP endpointsSupabase MCP, Context7
stdioLocal processes communicating via stdin/stdoutFilesystem, GitHub MCP
DockerContainerized servers for isolationCustom servers, sandboxed tools

See Server Types for detailed configuration examples.

Next Steps