Skip to main content
Glama

MCP Gateway

Tests Release PyPI version Python License Code Style: Ruff PyPI Downloads MCP Protocol Code Mode Local-First Security Observability Built-in Sponsor

One endpoint for every MCP server your agent needs — fetch tool schemas on demand instead of loading everything upfront.

MCP Gateway aggregates multiple MCP servers behind a single headless HTTP/SSE endpoint. Its Code Mode exposes five MCP meta-tools (listToolFiles, readToolFile, getToolDocs, executeTool, callManyTool) so agents discover signatures lazily and fan out bounded parallel calls without leaving the MCP surface. The host-side Python call_many helper remains available for direct code use, but the MCP contract exposes callManyTool as the fifth meta-tool.

Why MCP Gateway

  • Fewer wasted tokens — Agents fetch only the schemas they need, when they need them.

  • One connection to manage — Add, remove, or refresh servers in a single registry; agents connect to one endpoint.

  • Safe local-first defaults — Binds to 127.0.0.1 by default, screens local commands via an allowlist, masks secrets, and CSRF-protects the admin dashboard.

Related MCP server: MCPHub

Who It's For

  • Agent developers wiring Pi, Antigravity, Claude Desktop, Cursor, or any MCP-compatible client to multiple MCP servers through one gateway.

  • Operators running local-first infrastructure who want a CLI and dashboard with health probes, Prometheus metrics, and structured JSON logs.

Quick Start

  1. Install: pip install mcp-gway

  2. Add a server: mcp-gway add files --type local --command "npx -y @modelcontextprotocol/server-filesystem /path/to/dir"

  3. List servers: mcp-gway list

  4. Serve HTTP: mcp-gway serve --transport http

  5. Connect: Point your agent to http://127.0.0.1:8080/mcp

For more examples and transports, see the CLI Reference and Integrations.

Keep secrets out of your config. Point server env vars at {env:NAME} — mcp-gway resolves them at spawn. servers/*.json keeps the reference. Your machine keeps the secret.

Features

  • Multi-Server Aggregation — Connect to multiple MCP servers (local or remote) and expose them through a single endpoint. One URL for every agent; one registry to manage.

  • Code Mode — Five MCP meta-tools let LLMs discover schemas on demand, execute them in a hermetic sandbox, and fan out bounded parallel calls without loading all tool definitions upfront.

  • OAuth 2.0 Support — Built-in OAuth flow with Dynamic Client Registration (RFC 7591), secure token storage, and automated /.well-known/oauth-protected-resource discovery metadata (RFC 8707) for OAuth-capable MCP clients.

  • Hexagonal Architecture — Strict separation between pure domain models/ports, application use cases, and infrastructure adapters for isolated unit testability without running servers.

  • Hermetic Sandbox — Starlark-based sandbox for safe, constrained code execution.

  • MCP Protocol Compliant — Implements the Model Context Protocol over HTTP, SSE, and stdio.

  • Local-First Security — Local-first design with SSRF guards, command allow-lists, and CSRF protection.

  • Built-In Observability — Structured JSON logs, Prometheus metrics, and health probes built in.

Documentation

Development

uv sync --all-groups
uv run pytest -v   # 690 tests

See docs/development.md for checks, probes, and pre-commit.

Container

The gateway ships as a multistage Dockerfile (builder → test → runtime, plus a dev stage) with per-environment compose overrides. The builder, test and dev stages use the official ghcr.io/jdx/mise -debian image and install the toolchain (Python, uv, Node) from mise.toml + mise.lock — the same single source of truth the local dev environment uses. Base images are pinned by digest, and the runtime image runs as a non-root user (uid 1000) with a read-only root filesystem in production. The runtime image is ~270 MB (trimmed standalone CPython + a --no-dev virtualenv; tests/ and dev tooling stay in the test stage).

mise run docker:build   # build the runtime image (mcp-gway:local)
mise run docker:test    # build the test stage and run pytest inside it
mise run docker:dev     # dev override: hot-reload via watchfiles + debugpy (5678)

Or with docker compose directly:

# Base (runtime image, local registry volume, port 8080)
docker compose up --build

# Development — source bind-mounted, hot-reloads on change
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build

# Staging — tagged image, no source mounts
docker compose -f docker-compose.yml -f docker-compose.staging.yml up

# Production — pinned digest, read-only FS, all capabilities dropped
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Environment — copy .env.example to .env and adjust. The container binds 0.0.0.0 so the published host port is reachable, which requires the MCP_GWAY_ALLOW_REMOTE=1 opt-in; without it the gateway exits rather than exposing itself (fail-closed). Secrets and OAuth tokens live in the named mcp-gway-config volume (~/.config/mcp-gway/ inside the container), never in env files (OPS-04 / DENY-13). Per-server environment values can reference the gateway process env with {env:NAME} — only the placeholder persists and the secret resolves in the spawned child; see docs/configuration.md.

Production hardening — the prod override enforces read_only: true, drops all Linux capabilities (cap_drop: [ALL]), sets no-new-privileges, and pins CPU/memory limits. It runs whatever ${MCP_GWAY_IMAGE} points at, defaulting to the locally built mcp-gway:local; set it to a digest-pinned published image (ghcr.io/deuriib/mcp-gway:<tag>@sha256:<digest>) before deploying. Front it with a reverse proxy and auth before exposing it publicly.

Published images — every release pushes ghcr.io/deuriib/mcp-gway tagged <version>, <major>.<minor>, <major>, and latest, with build provenance and an SBOM attestation attached, then smoke-tests the pushed digest before finishing. The digest to pin is printed in the release run summary. Only linux/amd64 is published today; build locally on other architectures.

Debugging — the dev override installs debugpy and publishes port 5678. Attach from your editor or run a one-off debug session with:

docker compose -f docker-compose.yml -f docker-compose.dev.yml exec mcp-gway \
  python -m debugpy --listen 0.0.0.0:5678 -m mcp_gway.cli serve --transport http --host 0.0.0.0 --port 8080

Repobeats analytics

License

MIT

Available Tools

5 tools
callManyToolA

Runs up to 50 tool calls in one bounded fan-out (8 concurrent) and returns results in input order. Use it when several calls are independent - across servers or within one - and you want one round trip instead of N. Each item is {server, tool, arguments}; server and tool names are the ones readToolFile shows. A failed item returns ok=false with its error and never cancels its siblings, so a partial result is still usable. Do NOT use it when one call depends on another call's result: write an executeTool script for that. BUDGET: optional timeout in seconds caps the whole batch; omitted uses MCP_GWAY_EXEC_TIMEOUT, then 120s. Unfinished calls return ok=false with error.type=TimeoutError.

Inputs: calls (required), timeout.

executeToolA

Executes Python-like (Starlark) code in a sandboxed interpreter with MCP tool access as Server.tool_name(param=value) (e.g., Filesystem.read_file(path=".")). Final step of listToolFiles -> readToolFile -> (optional) getToolDocs -> executeTool; read the stub first and use the exact callable name shown. Security: L1 code validation (no imports/classes/file-IO/network primitives), L2 sandboxed runtime (no external modules, no filesystem/network/process access except via MCP tools, memory isolation), L3 bounded execution timeout, L4 Tool ACL (only tools_to_execute-allowed CodeMode servers/tools are visible). CALLS: keyword or positional arguments; positional ones bind in the order the stub declares them (Filesystem.read_file(".")). STARLARK RULES: no try/except/raise, no classes, no imports, no f-strings (use % formatting), no is (use ==), synchronous calls only, dict access via result["key"]. RETURN: assign result, or end the script with an expression and it is returned implicitly; a script that does neither returns null and says so in logs. Each call runs in a FRESH ISOLATED SCOPE (no state persists); print() output is captured to logs. Returns {"result": ..., "logs": [...]}. BUDGET: optional timeout in seconds; omitted uses MCP_GWAY_EXEC_TIMEOUT, then 30s.

Inputs: code (required), timeout.

getToolDocsA

Get detailed documentation for a specific tool including full parameter descriptions, types, and usage examples. Use this when the compact signature from readToolFile is not sufficient to understand how to use a tool. Requires both server name and tool name as parameters (e.g., server="filesystem", tool="read_file").

Inputs: tool (required), server (required).

listToolFilesA

Lists the virtual .pyi stub files for connected CodeMode MCP servers (CodeMode VFS). Default server-level binding returns servers/.pyi per server (e.g., servers/filesystem.pyi); tool-level binding returns servers//.pyi per tool. The filename stem is the exact callable name for executeTool. Workflow: listToolFiles -> readToolFile -> (optional) getToolDocs -> executeTool. In code, call tools as Server.tool_name(param=value) (e.g., Filesystem.read_file(path=".")). CALL THIS FIRST when the user names a server, tool, or capability not in your visible tool list — connected MCP servers are only discoverable here. Do NOT claim a server or capability is unavailable until listToolFiles confirms it is unavailable, then offer the closest alternative from the visible list or explain that it is not connected.

Inputs: no named parameters.

readToolFileA

Reads a virtual .pyi stub: servers/.pyi for the full server signature list, or servers//.pyi for a single tool (both listed by listToolFiles). Matching is case-insensitive and the .pyi extension is optional. Returns the authoritative callable name and arguments for executeTool as Server.tool_name(param=value). If the compact signature is insufficient, use getToolDocs. Workflow: listToolFiles -> readToolFile -> (optional) getToolDocs -> executeTool.

Inputs: fileName (required), endLine, startLine.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 5 tools

    Disambiguation4/5

    The discovery tools have a clear workflow, but readToolFile and getToolDocs both provide tool information and could be confused without the explicit 'optional' guidance. executeTool and callManyTool are distinct in intent, though executeTool can also orchestrate multiple calls, creating minor overlap.

    Naming Consistency4/5

    All names use camelCase and begin with action verbs, giving a predictable feel. The 'Tool' token appears in different positions (readToolFile, listToolFiles, getToolDocs, executeTool, callManyTool), which is readable but slightly uneven.

    Tool Count5/5

    Five tools is well-scoped for a gateway that must discover, document, execute, and batch MCP tools. Each tool has a clear role in the advertised workflow with no obvious redundancy.

    Completeness4/5

    The surface covers discovery (list/read stubs), detailed documentation, single-script execution, and bounded batch calls. Minor gaps might include explicit server metadata inspection or a direct single-tool invocation shortcut, but the existing tools can work around these.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Aggregates multiple MCP servers via a single interface with token optimization and multiple operating modes (Gateway, Meta, Proxy, Search, Code).
      7
      8
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Centralized management and routing of multiple MCP servers via unified Streamable HTTP/SSE endpoints, with granular group visibility, smart routing, and authentication.
      Apache 2.0
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables aggregating and routing multiple backend MCP resource servers so clients can access their combined tools and resources through a unified SSE, Streamable HTTP, or Stdio interface, with optional authentication and web-based management.
      120 npm
      MIT