Skip to main content

mcp-gateway

PyPI License Python

Unify multiple MCP servers behind a single endpoint. Lazy loading, auto-cleanup, Python plugins, role-based filtering.

The Problem

If you use Claude Code or any MCP client with 3+ servers, you get:

  • Multiple subprocesses (~50MB each)
  • Duplicated config
  • No centralized control
  • No way to add custom Python tools without a full MCP server

The Solution

mcp-gateway runs one process that proxies N MCP servers on-demand:

Claude Code / MCP Client
  │
  ▼
mcp-gateway (1 process)
  ├─ [plugin] Python @tool functions     ← in-process, 0 overhead
  ├─ [lazy]   filesystem-server          ← subprocess spawned on first call
  ├─ [lazy]   github-server              ← subprocess spawned on first call
  └─ [lazy]   playwright                 ← subprocess spawned on first call
      ↑
      5 min idle → auto-kill

Install

pip install mcp-gateway

Quick Start

1. Create gateway.yaml

servers:
  filesystem:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

  github:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      GITHUB_TOKEN: "${GITHUB_TOKEN}"
    enabled: false

idle_timeout: 300

2. Run

stdio (for Claude Code):

mcp-gateway stdio --config gateway.yaml

SSE (for remote clients):

mcp-gateway serve --config gateway.yaml --port 8765

3. Add to Claude Code

{
  "mcpServers": {
    "gateway": {
      "command": "mcp-gateway",
      "args": ["stdio", "--config", "/path/to/gateway.yaml"]
    }
  }
}

Python Plugins

Add custom tools with zero boilerplate:

from mcp_gateway import tool

@tool(description="Add two numbers")
def add(a: float, b: float) -> float:
    return a + b

Reference in your config:

plugins:
  - module: my_tools.calculator

Or register programmatically:

from mcp_gateway import MCPGateway

gw = MCPGateway()
gw.register_tool(add)
await gw.serve_stdio()

Sync functions run via asyncio.to_thread(). Async functions run natively. Schemas are auto-generated from type hints.

Role-Based Filtering

Control which tools each client sees:

roles:
  admin: null        # all tools
  readonly: ["filesystem_*", "gateway_status"]
  developer: ["github_*", "filesystem_*", "gateway_*"]

Set the role via environment variable:

MCP_GATEWAY_ROLE=readonly mcp-gateway stdio

Uses glob patterns — filesystem_* matches all tools from the filesystem server.

How It Works

  1. Lazy Loading: Servers aren't started until a tool is called. Each server gets a _<name>_connect placeholder tool. Calling it spawns the subprocess and discovers real tool schemas via session.list_tools().

  2. Auto-Cleanup: A background task checks every 60s and kills server subprocesses idle for longer than idle_timeout (default: 5 min).

  3. Real Schemas: Tool schemas are discovered from the actual server via the MCP SDK, not hardcoded. You always get accurate inputSchema.

  4. Plugin Tools: Python functions decorated with @tool run in the gateway process. Type hints are introspected to generate JSON Schema automatically.

API

from mcp_gateway import MCPGateway, tool

# From YAML
gw = MCPGateway.from_config("gateway.yaml")

# Programmatic
gw = MCPGateway()
gw.register_tool(my_function, name="my_tool", description="...")

# Serve
await gw.serve_stdio()    # stdio mode
await gw.serve_sse()      # SSE mode on :8765

# Context manager
async with MCPGateway() as gw:
    await gw.serve_stdio()

CLI

mcp-gateway serve [--config FILE] [--host HOST] [--port PORT]
mcp-gateway stdio [--config FILE]
mcp-gateway list  [--config FILE]

Config discovery: --config > ./gateway.yaml > ./mcp-gateway.yaml

Requirements

  • Python >= 3.10
  • mcp >= 1.0.0
  • starlette >= 0.27.0
  • uvicorn >= 0.23.0
  • pyyaml >= 6.0

License

MIT

Metadata

Release files for mcp-unify 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-unify 0.2.0
File Size Uploaded Provenance
mcp_unify-0.2.0.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-unify 0.2.0
File Interpreter ABI Platform
mcp_unify-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.5 kB

Release files / mcp_unify-0.2.0.tar.gz

Download URL mcp_unify-0.2.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c335556097eb191306dd070ac9739b5faad0a9a4fd07fc91dc5a0cc8dd10192f
BLAKE2b-256 checksum
How to use checksums
8949a686745d40e9e0c75b8dcdc8b1d236bcd0445e63d371a66f81e97575863d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / mcp_unify-0.2.0-py3-none-any.whl

Download URL mcp_unify-0.2.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a6fb65639ab782d84ebd7183153ab790c4081ed43a7b17a1bc092d6ba792f31
BLAKE2b-256 checksum
How to use checksums
bbad9f074a01609f6d2b2f3dae3fa25bf94630f1b57f1c16593281fb1ae021a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Security for mcp-unify 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page