Claude Code / Infrastructure
MCP Gateway for Claude Code: Why Every Serious Session Needs One
Stdio MCP servers break at scale, eat RAM, and stretch Claude Code cold-starts past 40 seconds. An MCP gateway fixes all three. Here is how to wire one up in under five minutes, and why it becomes the default the moment you run more than a single session.
Claude Code ships with the best MCP client we have used: it respects stdio, Streamable HTTP, and SSE transports, it handles auth headers, it surfaces schema errors in-session, and it hot- reloads config changes without a full restart. But the MCP client is only half the equation. The other half is what sits on the other side of that .mcp.jsonentry. Most Claude Code guides tell you to fill it with stdiocommandentries and call it done. For a single session and a few servers, that works. For a real workflow - multiple sessions, dozens of tools, production use - it does not.
An MCP gateway is what goes on the other side. This article is what a gateway does, why it matters specifically for Claude Code, and the exact config changes to adopt one.
The Claude Code-Specific Problem
Claude Code has three design properties that interact badly with pure stdio MCP:
- Long-lived sessions. A Claude Code window stays open for hours. Stdio processes stay resident that entire time.
- Parallel sessions are encouraged. Each project can have its own session. Power users run 5-10 at once.
- Global MCP config.
~/.mcp.jsonentries apply to every session - so adding one server adds it to all of them.
These three in combination are what make stdio MCP collapse. If you run one Claude Code with 10 stdio servers, you spawn about 40 node processes (including dependency sub-processes) consuming roughly 1.5 GB RAM. Fine. Open a second session and both doubles. At eight sessions and 50 servers, you hit the ceiling we hit: 3,624 processes, 128 GB RAM exhausted. Full math is in our stdio vs HTTP hub breakdown.
What an MCP Gateway Adds
A gateway is an HTTP service that:
- Hosts many MCP tools behind one endpoint
- Exposes them via MCP Streamable HTTP (and usually REST / A2A / OpenAI-function flavors)
- Manages per-tool authentication centrally
- Meters usage and (in managed gateways) handles billing
- Runs once - no per-session spawn
For Claude Code specifically, the gateway model means:
| Metric | Stdio .mcp.json | Gateway .mcp.json |
|---|---|---|
| Config lines for 50 tools | ~250 | ~4 |
| Session cold start | 40+ seconds | < 2 seconds |
| RAM at 8 sessions | ~127 GB | ~200 MB |
| API keys in config | 30+ | 1 |
| Adding a new tool | Edit config + restart | No config change |
Five-Minute Setup: Claude Code + ToolRoute Gateway
Here is the exact change. ToolRoute is the MCP gateway we built after breaking our own box with stdio. Other gateways (Composio, Zapier MCP, self-hosted supergateway hubs) use the same pattern.
Step 1: Get an API key
Sign up at toolroute.ai. Free tier includes enough credits to evaluate. Create a key from the keys dashboard.
Step 2: Add to .mcp.json
Open ~/.mcp.json (the global Claude Code MCP config):
{
"mcpServers": {
"toolroute": {
"type": "http",
"url": "https://toolroute.ai/mcp",
"headers": {
"Authorization": "Bearer tr_YOUR_KEY_HERE"
}
}
}
}That is the full config. Restart Claude Code. The session now has access to every tool ToolRoute routes to - 87 at time of writing, covering search, email, voice, payments, databases, browsers, and more.
Step 3: Remove stdio entries you no longer need
The tools your gateway covers can be deleted from .mcp.jsonentirely. Keep stdio for the handful of truly local tools (file watchers, custom internal tooling, in-development servers). For everything networked, go through the gateway.
Step 4: Verify
In a new Claude Code session, type: /mcp. The output lists every tool available. You should see the gateway-backed tools (tavily, resend, stripe, playwright, etc.) plus any stdio entries you kept. One list, one auth layer.
The Comparison Table: Direct Stdio vs Gateway vs Hybrid
Most Claude Code guides leave readers guessing which mode they should be in. Here is the rubric we use across our own fleet:
| Situation | Recommended setup |
|---|---|
| One session, 1-5 MCP tools, solo dev | Pure stdio is fine |
| One session, 10+ tools | Gateway for most, stdio for local-only |
| 2+ parallel sessions | Gateway (stdio process count explodes) |
| Team of devs sharing an MCP stack | Managed gateway (shared auth, shared billing) |
| Security-sensitive workloads | Self-hosted hub + BYOK gateway for 3rd party |
| Developing a new MCP server | Stdio for the one under development |
Claude Code-Specific Gateway Features Worth Using
1. Pre-session capability check
Claude Code encourages agents to verify tool availability before starting work. Gateways expose a GET /api/v1/toolscatalog that an agent can query once and cache in-session. This is the basis of our check-before-build pattern: before writing any new capability, the agent runs a semantic search against the catalog to see if one already exists. Saves hours per session.
2. Unified error format
Claude Code surfaces tool errors in the conversation. Every MCP server returns errors differently (HTTP 500, 200 with error body, silent timeout). A gateway normalizes these to one schema so the agent reasoning stays consistent. See how AI agents handle tool failures.
3. BYOK for accounts you already pay for
If you already have an Anthropic / OpenAI / Stripe account, a gateway should let you bring that key. ToolRoute supports BYOK for all 87 tools - you pay the underlying provider directly and the gateway bills only for routing. Details: Bring Your Own Key (BYOK) guide.
4. Auto-routing
Claude Code agents often know what they want ("search the web for X") but not the exact tool name. A good gateway lets the agent send a description and picks the right tool based on semantic match, historical success, and cost. See MCP auto-routing.
What About Privacy and Control?
A legitimate concern: routing tool calls through a third party means that party sees the request payloads. Mitigations:
- Self-host the gateway. supergateway, mcp-proxy, and open-source ToolRoute deployments all run on your own box.
- Use BYOK. Sensitive providers (your Supabase, your Stripe) stay on your keys; gateway just proxies.
- Network-scope the gateway. Bind to 127.0.0.1 if fully local, or VPC-internal for team deploys.
- Audit logs. Every serious gateway logs every call. You can diff expectations against reality.
For a deeper comparison of the tradeoffs, see our self-hosted vs cloud MCP servers breakdown.
The Minimum Viable Migration
If you are on pure stdio today and do not want to adopt the full gateway pattern, the cheapest incremental win is:
- Count your
.mcp.jsonstdio entries. - If over 10, wrap them with supergateway on local ports 18901-18925.
- Keep every tool, gain back ~90% of the RAM and 95% of the cold-start time.
- When you are tired of maintaining that, swap the local hub for a managed gateway.
The gateway path is a migration, not a rewrite. You can move one tool at a time.
Frequently Asked Questions
What is an MCP gateway for Claude Code?
A single HTTP endpoint that hosts many MCP tools behind one API key. Configured once in .mcp.json astype: http. The session gets every tool without spawning per-tool processes or managing per-tool credentials.
Why not just use stdio MCP servers directly?
Stdio works until it does not. Each server becomes a child process per session. At ~15 servers across 3+ sessions you hit 500+ node processes and multi-GB RAM. Cold starts stretch past 40 seconds. A gateway replaces that with one HTTP connection per session regardless of tool count.
Do MCP gateways work with Claude Code?
Yes. Claude Code supports MCP Streamable HTTP natively. Any gateway that speaks that transport (ToolRoute, Composio, Zapier MCP, custom hubs) plugs in as a single config entry.
How is a gateway different from Claude Code plugins?
Plugins (slash commands, hooks, skills) run inside the harness. A gateway is external tool execution over HTTP. Gateways scale across sessions and machines; plugins scale per-install. Use both.
What does an MCP gateway cost vs self-hosting?
Self-hosting costs are RAM, cold-start time, and ops time. Managed gateways use prepaid credits (roughly $1 per 100 search queries). Break-even is about 10 hours of ops time per month.
Related Articles
ToolRoute is an MCP gateway built for exactly this use case. One line in .mcp.json, 87 tools, no RAM overhead. Browse the catalog or read the Claude Code setup doc.