MCP Gateway is a self-hosted MCP gateway and proxy, deployed as a single Rust binary between AI clients and all of their tools. It is free for personal and non-commercial use, including running the full gateway; commercial use requires a commercial license.
Purpose and the problem it solves Each MCP tool connected to an AI client adds roughly 150 tokens of context overhead, and it is loaded on every request whether or not it is used. Connecting 20 servers with 100 tools in total consumes about 15,000 tokens before the conversation even begins. Context limits impose a second cost: you must decide in advance which tools to connect, and the remaining tools cannot be accessed by the agent, which degrades decision quality. MCP Gateway moves the full tool catalog out of the exposed tool list: the agent loads a fixed set of small meta-tools, uses gateway_search_tools to search, and uses gateway_invoke to call backend tools. It should be noted that a small live agent benchmark in the repository did not find that this extra hop yields token savings for completed tasks, so its value lies in catalog capacity, policy, and routing, rather than broad claims of token savings.
Main capabilities
- Compact meta-interface: instead of every backend definition, the agent sees 9 to 17 meta-tools. A minimum of 9 tools is exposed, and in the README benchmark scenario it is 11 (counted from the administrator's perspective); callers without administrator status see four fewer. The base discovery tool group remains fixed, and the rest are listed only when they can answer: stats, cost reports, playbooks, and profile controls appear when the corresponding configuration exists, webhook status appears when a webhook registry is mounted (it never appears for the stdio transport), and a deployment with everything enabled shows 17.
- On-demand discovery and invocation: the gateway dynamically discovers and routes to backend tools internally.
- Fast REST API onboarding: drop in a YAML file, or use mcp-gateway cap import to import an OpenAPI specification; 110+ capabilities are built in. The OpenAPI importer can convert every operation in an OpenAPI 3 specification into a validated capability YAML (for example, the full Swagger Petstore specification generates 19 validated capability YAMLs end to end).
- Hot reload: while the AI keeps its connectionIn this case, the backend and configuration are hot-reloaded within about 8ms, with no restart and no loss of context.
- Multi-tenant identity: a verified end-user identity can be passed to the backend through one of three configuration strategies (a gateway-signed short-lived assertion, forwarding the caller's own token, or performing an RFC 8693 token exchange for an OAuth-native backend), without retaining long-term credentials for anyone; backends marked as required fail closed when there is no verified identity, rather than using a shared secret.
- Security design: the tool poisoning validator scans every backend tool description before the tool description enters the agent context, and HIGH mode fails closed; optional SHA-256 capability hash pinning (unpinned files are still loaded, while pinned files fail closed on load and on every watcher event if they do not match); rug-pull detection is triggered and the capability is quarantined when the on-disk content of a pinned capability changes after approval; a centralized audit surface; credential configuration files should not be set as globally readable. OWASP Agentic AI Top 10 coverage is a self-assessment within the repository, not a certification. Crate setting #![deny(unsafe_code)].
- Production resilience: circuit breakers, retries with backoff, rate limiting, and health checks prevent a single unstable server from dragging down the entire toolchain.
- Dual protocol: MCP plus A2A (agent-to-agent) transport adapters, with the same gateway routing both tool calls and cross-provider agent messages.
How to use Install and configure: you can have an AI assistant read the repository and install it (this approach works for Claude Code, Cursor, Windsurf, Codex, and any AI with terminal access; the assistant will install the binary, run the setup wizard, import existing MCP servers, and complete self-wiring); manual configuration is also possible. setup scans Claude Desktop, Claude Code, Cursor, Zed, Continue.dev, Codex, and running MCP processes, lets you choose which servers to import into gateway.yaml, previews the gateway entries, writes each detected client configuration, verifies the writes, and prints backup and rollback paths when modifying existing client configurations; add --yes to skip prompts and import everything. mcp-gateway add is compatible with claude mcp add and codex mcp add, and pre-registers 48 commonly used MCP servers (with the correct commands,parameters, and environment variable templates); mcp-gateway list shows configured items, and mcp-gateway remove <name> removes one. If there is nothing to import yet, you can use mcp-gateway init --with-examples to generate a usable gateway.yaml with public capabilities to confirm the gateway is alive. setup export can write gateway entries into client configuration files, backing up before modification and printing the exact rollback command next to updated items; the modes are --mode proxy (HTTP), --mode stdio (subprocess), and --mode auto (probe the health endpoint first, then fall back). The web panel is located at http://localhost:39400/ui(serve after running). The /dashboard operations panel requires administrator credentials, and browser navigation cannot send credentials, so serve prints a one-time link for opening it when bound to loopback; a network-bound gateway does not print a link, and instead uses /ui with token management. Code Mode: after setting code_mode.enabled: true, tools/list returns only two tools, gateway_search and gateway_execute, and everything else is accessed through these two; in this mode, the tools listed in meta_mcp.surfaced_tools are not appended, so the count remains two regardless of how many backends are connected. Code Mode is disabled by default. gateway_search returns L0 by default (tool name, one-line purpose, score), and detail=l1 or detail=l2 can be used to get more information, or explain=true to get ranking diagnostics; include_schema=true is deprecated and maps to L2. For the full configuration schema, refer to the annotated examples/gateway-full.yaml, which covers env_files, server, auth, meta_mcp, streaming, failsafe, cache, capabilities, and backends; the remaining top-level configuration sections (playbooks, security, webhooks, routing_profiles, code_mode, mtls, key_server, agent_auth, runtime, marketplace, control_plane, cost_governance) do not yet have textual reference, and the Config struct in src/config/mod.rs is the authoritative list.
Use cases and limitations It is suitable for scenarios that need to connect a large number of MCP servers and REST APIs to Claude, Cursor, Codex, or other MCP clients while also wanting to control context usage, unify security auditing, and support multi-tenant identity and production resilience; it is also suitable for deployments that need to hot-update backend toolchains without downtime, and for scenarios that need dual-protocol routing for MCP and A2A. MCP Gateway is a tool and capability router that routes MCP tools, resources, and prompt trafficto backend MCP servers and REST APIs that support capabilities, and can proxy MCP server-to-client requests such as sampling/createMessage, elicitation/create, and roots/list back to the connected client through the existing session; it is not a chat-completions or embeddings proxy, and when a backend requests sampling/createMessage, the connected client performs the model call rather than the gateway. The OpenAI-compatible prompt caching helper functions are only used to let gateway_invoke preserve prompt_cache_key behavior for backends that internally call the LLM API. Other limitations: the Docker image runs as UID/GID 1001 on Linux, and an owner-only-readable deployment copy should be created rather than changing the ownership of the working configuration (Docker Desktop handles bind-mount identity differently on macOS and Windows); the quantitative claims in the README come from docs/BENCHMARKS.md and the machine-readable benchmarks/public_claims.json, with a CI check to prevent drift; OWASP coverage is self-assessed rather than certified, and hardening items such as SBOM, release signing, live remote attestation discovery, multi-gateway signing, SQL sink defaults, and collusion detection are tracked separately.
Classification note It is categorized as ai-frameworks according to its primary use (MCP gateway/proxy, aggregating and routing MCP tools and REST APIs, development infrastructure for AI clients).