mcp-gway
This server is an MCP Gateway that aggregates multiple MCP servers behind one endpoint and provides Code Mode meta-tools for lazy discovery and bounded execution.
Aggregate local/remote MCP servers behind one HTTP/SSE/stdio endpoint.
List virtual
.pyitool stubs per server/tool withlistToolFiles.Read authoritative tool signatures from stubs with
readToolFile.Fetch detailed tool docs, parameter descriptions, and examples with
getToolDocs.Execute Starlark code in a hermetic sandbox to call MCP tools as
Server.tool_name(...)withexecuteTool.Fan out up to 50 independent tool calls in parallel, 8 concurrent, with per-call results via
callManyTool.Manage servers through CLI/admin dashboard and use OAuth, local-first security, metrics, JSON logs, and health probes.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-gway list all connected MCP servers"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Gateway
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.
CLI:
mcp-gway(canonical) ormgw(alias)Admin UI:
mcp-gway serve --transport http→ http://127.0.0.1:8080/
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.1by 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
Install:
pip install mcp-gwayAdd a server:
mcp-gway add files --type local --command "npx -y @modelcontextprotocol/server-filesystem /path/to/dir"List servers:
mcp-gway listServe HTTP:
mcp-gway serve --transport httpConnect: 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/*.jsonkeeps 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-resourcediscovery 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
Configuration & Usage — add servers, transports, and OAuth
CLI Reference — commands, options, and the admin dashboard
Code Mode — lazy-discovery meta-tools and the sandbox
Security — local-first controls and command allow-lists
Observability — JSON logs, Prometheus metrics, health probes
Integrations — Claude Desktop, Pi, Antigravity, OpenCode
Architecture — system diagram and transports
Development — tests, lint, and pre-commit
Development
uv sync --all-groups
uv run pytest -v # 690 testsSee 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 -dEnvironment — 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 8080License
Available Tools
5 toolscallManyToolA
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
Scored across 5 tools
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.
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.
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.
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
Related MCP Connectors
One MCP server for all your MCP servers: code mode, per-tool permissions, approvals and audit.
Host any HTTP API as a standard MCP server; auto-distribute to 12+ mainstream agent platforms.
MCP gateway and cloud hosting for MCP servers, agents and apps like RAG, managed from your agent.
One OAuth connector for your team's remote MCP servers, with Tool Packs, guardrails and logs.
Related MCP Servers
- AlicenseBqualityDmaintenanceAggregates multiple MCP servers via a single interface with token optimization and multiple operating modes (Gateway, Meta, Proxy, Search, Code).78MIT
- AlicenseNot gradedqualityCmaintenanceCentralized management and routing of multiple MCP servers via unified Streamable HTTP/SSE endpoints, with granular group visibility, smart routing, and authentication.Apache 2.0
- AlicenseNot gradedqualityAmaintenanceAggregates and routes requests across multiple backend MCP servers, exposing their combined tools and resources through unified SSE, Streamable HTTP, or Stdio endpoints. Supports optional Web UI management, granular tool control, and endpoint authentication.120 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables 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 npmMIT