Topic 1 of 4 · 5 min read
MCP gateways for routing, policy and audit
Goal: Decide which checks belong in an MCP gateway versus each server and write the policy for a described set of servers.
An MCP gateway is one chokepoint in front of many MCP servers where you enforce who may call which tool, and where you record every call. It does not replace checks inside a server. It makes the checks that should be identical everywhere live in one place.
Check yourself · 1 of 3
Which two request headers let an MCP gateway apply a per-tool allowlist over Streamable HTTP without parsing the body?
Why it matters
Ten teams each run an MCP server. Without a gateway, each server has its own login code, its own idea of an allowlist and its own logs, and an agent can reach any of them directly. One server forgets to check scopes, and that server is the one an attacker finds. A gateway gives you one place to answer "which agents can reach what" and one audit trail. Open-source gateways such as the Docker MCP Gateway put several servers behind a single endpoint for the same reason.
What a gateway can see cheaply
Over Streamable HTTP, the 2026-07-28 spec requires two request headers that a gateway can read without parsing the JSON body: Mcp-Method (for example tools/call) and Mcp-Name (the tool name, or the resource URI or prompt name). That is enough to route and to apply a per-tool allowlist. Servers must also validate the Origin header to block DNS rebinding, so the gateway should do the same on its own edge.
What belongs where
- In the gateway: authenticate the caller, check the token's audience and scopes, allowlist servers and tools per client, rate limit, write the audit log, strip or block unknown methods.
- In each server: the checks that need business knowledge. Can this user read this invoice? Is this row theirs? A gateway cannot know that.
- In both: least privilege. Give the gateway a policy that denies by default, and give each server credentials that can only do what its tools do.
A gateway that forwards the caller's own token to the server keeps the server's per-user checks working. A gateway that swaps it for one powerful service token removes them, and every user then acts as that service. Avoid that unless the server never makes per-user decisions.
Before and after
Before: agents hold direct URLs for the billing, wiki and deploy servers. Any agent token reaches deploy_to_production.
After, a policy the gateway loads:
servers:
billing:
allow_tools: [get_invoice, list_invoices]
wiki:
allow_tools: ["*"]
deploy:
allow_tools: [get_status]
require_scope: deploy:read
default: deny
audit: { log: all_calls, redact: [arguments.token, arguments.password] }
The agent can read invoices and check deploy status. deploy_to_production is blocked because it is not on the list, and the default is deny.
What goes wrong
- Trusting a header the client can fake. Identity must come from the verified token, not from a header like
X-User. - Allowlisting servers but not tools. One allowed server can still expose a dangerous tool added next month.
- The gateway as a single point of failure with no limits. It needs its own timeouts and capacity, or one slow server stalls every agent.
- Logging full arguments. The audit trail becomes a store of secrets.
Examples
A tool added next month
The wiki server ships a new tool, delete_page. The gateway policy allowlists servers only, so every agent can now call it. With allow_tools per server and default: deny, the new tool stays blocked until someone adds it on purpose.
Service token versus passthrough
A gateway replaces each caller's token with one service token. The billing server's rule 'users see only their own invoices' now sees the same identity for everyone, and list_invoices returns all customers. Passing the caller's token through, or forwarding a verified user id, restores the rule.
Key points
- A gateway centralises the checks that must be identical for every server: authentication, allowlists, rate limits and audit.
- Over Streamable HTTP the Mcp-Method and Mcp-Name headers let a gateway route and allowlist tools without parsing the request body.
- Checks that need business knowledge, such as whether this user owns this record, stay inside each server.
- Default to deny: list the tools each client may call instead of listing the ones to block.
- Identity must come from a verified token, never from a header the client sets itself.
Common mistakes
- Allowlisting whole servers instead of individual tools.
- Moving every check into the gateway and removing per-user checks from the servers.
- Reading identity from a client-supplied header instead of a verified token.
- Logging full tool arguments, so the audit log holds passwords and tokens.
Check yourself · 2 of 3
A gateway allows the 'wiki' server for all agents. The wiki team ships a new delete_page tool. What does the gateway policy do?
Check yourself · 3 of 3
Which check should stay inside the invoice server instead of moving into the gateway?
Practice items, not counted towards your mastery.
Start here
- MCP specification: Streamable HTTP transport (opens in a new tab)StandardFree
Defines the Mcp-Method and Mcp-Name request headers and the Origin check a gateway can rely on.
- MCP specification: Caching (opens in a new tab)StandardFree
Defines ttlMs and cacheScope, which results must carry them, and the rule against sharing caches across authorization contexts.
- MCP specification: Versioning and Compatibility (opens in a new tab)StandardFree
How clients and servers negotiate a revision, and how one server can serve old and new clients.
More for this topic
- Docker MCP Gateway (opens in a new tab)ToolFree
An open-source gateway that puts several MCP servers behind one endpoint, with secrets handling, logging and call tracing.