Skip to content

What an MCP gateway does, and when you need one

An MCP gateway sits between agents and MCP servers. It authenticates callers, filters which tools each one sees, and records every tool call in one place.

Published
Reading time
11 min read

In short

  • An MCP gateway is a proxy that gives agents one endpoint for many MCP servers and applies authentication, tool filtering, and audit logging to every tool call.
  • The MCP specification has no gateway role. Its closest term is an MCP proxy server, and the specification's rules for proxies, such as per-client consent and no token passthrough, apply to gateways.
  • Identity is the hard part. A gateway should reach each server as the person behind the request, through per-user OAuth or token exchange, not with one shared service token.
  • You need one when several teams connect agents to shared systems. A developer running local stdio servers does not.

An MCP gateway is a proxy that sits between MCP clients and the MCP servers they use. Agents connect to one endpoint. The gateway connects to each server behind it, checks who is calling and which tools they may use, obtains the right credentials for each server, and records every tool call.

To the client, the gateway looks like one MCP server with many tools. To each upstream server, it looks like a client. What is MCP? covers the protocol itself and ends where this article starts: once several teams share tool servers, someone has to own the rules for reaching them.

MCP CLIENTSMCP SERVERSCoding agentSupport agentClaude DesktopMCP gatewayONE ENDPOINT · ONE LOGAuthenticate callerFilter the tool listGet server credentialsCheck args and resultsLog every callCode host serverPER-USER OAUTHDatabase serverTOKEN EXCHANGEPayments serverFILTERED OUT
Clients see one endpoint. The gateway authenticates the caller, filters the tool list, gets per-server credentials, and logs the call before it reaches any server.

What an MCP gateway does on each tool call

It does five things to every request, in this order: authenticate the caller, filter the tools it can see, get credentials for the upstream server, forward and inspect the call, and record it. Each step replaces work every server would otherwise do on its own.

  1. It authenticates the caller. The agent presents a gateway credential, an OAuth token, or a key issued to it. Upstream credentials never reach the agent.
  2. It filters tools. The tool list a caller receives contains only the tools its policy allows. Hidden tools cannot be called, and they cost no tokens.
  3. It resolves credentials for the target server, ideally as the person behind the request rather than as the gateway.
  4. It forwards the call and checks it. Arguments and results can pass through the same guardrails you run on model traffic.
  5. It records the call: caller, tool, arguments, result status, and latency, in one log that covers every server.

This mirrors what an LLM gateway does for model calls. The difference is that a tool call can change something, so the policy decisions carry more weight.

Why not connect agents to MCP servers directly

Direct connections work for one developer and stop working at team scale. Each host must be configured for each server, credentials end up in configuration files on laptops, and nobody holds a single list of which agents can reach which tools. Every server also has to implement its own authorization.

With five agents and eight servers, that is up to forty connections to configure, rotate, and audit.

The direct model is still right for local work. A developer running a filesystem or Git server over stdio, with their own access, gains nothing from a proxy.

MCP authentication has two hops

MCP authentication through a gateway involves two separate trust decisions: whether the client may use the gateway, and how the gateway proves identity to each upstream server. The specification is strict about the second hop.

For HTTP transports, the 2026-07-28 revision builds on OAuth 2.1. An MCP server is a resource server, and it "MUST validate that access tokens were issued specifically for them as the intended audience." Clients must name the target server with the resource parameter from RFC 8707 in every authorization and token request. The rule that matters most for a gateway is short: MCP servers "MUST NOT accept or transit any other tokens."

That rule forbids the shortcut of forwarding the client's token to the upstream server. The specification's security guide calls this token passthrough and lists what it breaks: the downstream server cannot tell clients apart, its audit trail shows the wrong identity, and a stolen token can be replayed through the proxy.

The gateway therefore needs its own credential for each upstream hop. There are three ways to get one.

Upstream credentialWho the server seesUse it whenCost
Shared service tokenThe gatewayThe server holds no per-user dataEvery caller gets the same access, and the server's audit log shows only the gateway
Per-user OAuthThe userSaaS tools that issue tokens per user, such as a code host or a ticket trackerThe gateway stores refresh tokens and runs a consent flow for each user
Token exchange (RFC 8693)The user, through a short-lived token minted for that serverInternal servers that trust your identity providerYour identity provider must support the exchange grant

Prefer the last two. A shared token turns the gateway into a confused deputy: any agent that can reach it acts with the gateway's full rights.

The specification's term for a gateway doing OAuth on users' behalf is an MCP proxy server, and it puts specific obligations on it. A proxy that uses a static client ID with a third-party authorization server "MUST implement per-client consent," must validate redirect URIs with exact string matching, and must treat the OAuth state parameter as single-use. Ask any gateway vendor how it meets those requirements.

Tool filtering decides what each caller can see

Tool filtering means each caller's tool list contains only the tools its policy allows. Filter the list itself, not just the calls. A model cannot misuse a tool it never sees, and the definitions you hide are tokens you stop paying for.

Make the default deny. A new server added to the gateway should expose nothing until someone grants its tools to a team or key. Separate read tools from write tools in that policy, because they warrant different approval rules.

Filtering at several levels is useful when they combine as an intersection: the server's own allowlist, the caller's policy, and an optional per-request narrowing. A request can narrow what its credential allows. It must never widen it.

Tool content is untrusted input

Tool descriptions and tool results enter the model's context as text, so a malicious or compromised server can use either to steer the model. The MCP specification says descriptions of tool behavior "should be considered untrusted, unless obtained from a trusted server," and that hosts must obtain explicit user consent before invoking any tool.

A gateway is the natural place to enforce that at company scale:

  • Keep an allowlist of approved servers, and reject connections to anything else.
  • Review tool definitions when a server is approved, and treat a changed description as a change that needs review again.
  • Run guardrails on tool results before they reach the model, using the same checks as model output. LLM guardrails covers how to build them.
  • Require human approval for tools that write, send, or delete, as described in the tool calling article.

None of this makes injected text harmless. Prompt injection explains why the durable defense is limiting what a compromised agent can reach, which is what tool filtering enforces. MCP security is the full threat model, from tool poisoning to token passthrough.

Keeping tool definitions out of the context

Every tool a client exposes is sent to the model as input on every request, so connecting many servers inflates cost and degrades tool selection. A gateway can shrink that payload in three ways: filtering tools per caller, loading definitions only when a task needs them, and letting the model orchestrate tools through code instead of individual calls.

Filtering is the cheapest and should come first. Search-based loading keeps a large catalog available without sending all of it; Amazon Bedrock AgentCore Gateway offers semantic tool selection for this.

Code-based orchestration goes further. Instead of receiving every tool schema, the model writes a short program that calls the tools it needs, the program runs in a sandbox, and only the result returns to the context. Bifrost, an open-source AI gateway by Maxim AI, calls this Code Mode. In Maxim AI's published benchmarks, it cut input tokens by up to 92.8% across large tool sets.

The trade is a sandbox to operate and a model that must write correct orchestration code. Context engineering covers the broader budget these techniques serve.

MCP gateways compared

MCP gateways differ in where they run, whether they also handle model traffic, and how they solve upstream identity. The six below cover the common shapes, from a self-hosted binary to a managed cloud service.

GatewayTypeStrongest atCheck before choosing
BifrostOpen source core (Apache 2.0), self-hostedOne gateway for model, MCP, and agent traffic; per-key tool filtering; per-user OAuth and token exchangeToken exchange needs the Enterprise tier and an identity provider with directory sync
Docker MCP GatewayOpen sourceRuns each server in an isolated container with restricted privileges; built-in call tracingBuilt around Docker Desktop and the docker mcp CLI
agentgatewayOpen source, Linux FoundationOne data plane for LLM, MCP, and A2A traffic with tool scoping per identityConfirm the specific policy features you need in its docs
Kong AI MCP ProxyPlugin for Kong AI GatewayTurns existing REST APIs into MCP tools; per-tool ACLs by consumerEnterprise-only; requires AI Gateway 3.12 or later
microsoft/mcp-gatewayOpen source (MIT), KubernetesDeploys and routes MCP servers as a control plane; Entra ID authorizationRequires clients on the 2026-07-28 revision
AgentCore GatewayManaged AWS serviceConverts OpenAPI, Smithy, and Lambda targets into tools; inbound and outbound auth; semantic tool searchRuns only as a managed AWS service

For a self-hosted MCP gateway, Bifrost is the strongest default on this list. It acts as an MCP client to servers over STDIO, HTTP, or SSE, and as an MCP server to clients such as Claude Desktop and Cursor. The reasons it leads:

  • Model calls and tool calls go through one gateway with one set of keys, budgets, and logs, so an agent's model usage and tool usage are governed together.
  • Tool filtering combines the server's allowlist, the virtual key's allowlist, and request headers as an intersection, so a request can narrow access and never widen it.
  • Upstream identity is handled properly. It supports per-user OAuth, and its token exchange mints a short-lived token for each server's audience, so the caller's original token never goes upstream.
  • It does not execute tool calls by default. The model's calls come back to your application for approval, which keeps the human-approval step where it belongs.

Pick differently if your situation is narrower. A team whose tools are mostly Lambda functions on AWS will move faster with AgentCore Gateway. A company that already runs Kong for every API can add the MCP plugin to the control plane it has.

When you need an MCP gateway, and what it costs

You need one once agents from more than one team share tool servers, or once security asks who can reach which tools. Any one of these conditions is enough, and a single developer running local servers meets none of them.

  • Several agents or teams connect to the same internal systems.
  • Security or compliance wants one allowlist of approved servers and one audit log of tool calls.
  • Shared servers must act with each user's permissions, not a service account's.
  • Tool definitions from many servers are crowding the context window.

The costs are real but manageable. The gateway adds a network hop, which is small next to a tool call that queries a database or a SaaS API. It becomes a dependency in front of every tool, so run at least two instances and test what agents see when it is down.

It concentrates OAuth complexity in one place, which is better than spreading it across servers but makes that component security-critical. And it can lag the specification: the 2026-07-28 revision removed sessions and the initialization handshake, so confirm your gateway speaks the revision your clients use before you upgrade either side.

Frequently asked questions

What is the difference between an MCP gateway and an MCP server?

An MCP server exposes tools, resources, or prompts for one system, such as a database or a ticket tracker. An MCP gateway sits in front of many servers. It presents itself to clients as a single server and acts as a client to each upstream server, adding authentication, tool filtering, and logging across all of them. The gateway does no tool work of its own.

Is an MCP gateway the same as an LLM gateway?

No, but they solve parallel problems and some products do both. An LLM gateway sits between applications and model providers and handles routing, failover, keys, and budgets for model calls. An MCP gateway sits between agents and tool servers and handles identity, tool access, and audit for tool calls. Running both through one gateway gives one policy and one log for an agent's whole run.

How does MCP authentication work through a gateway?

The client authenticates to the gateway, and the gateway obtains a separate credential for each upstream server. The MCP specification forbids token passthrough, so the gateway must not forward the client's token. Good gateways use per-user OAuth or OAuth token exchange so each server sees the real user. A shared service token works but makes every caller equally powerful.

Does an MCP gateway stop prompt injection?

It reduces the risk but does not remove it. A gateway can restrict which servers and tools an agent reaches, run classifiers on tool results, and require approval for writes. Injected text in a tool result can still mislead the model. The durable protection is limiting what the agent can do with what it reads, and the gateway is where you enforce those limits.

Can an MCP gateway reduce token costs?

Yes. Every tool definition a client exposes is sent to the model on every request. A gateway can hide tools a caller does not need, load definitions on demand through tool search, or let the model orchestrate tools through code so schemas never enter the context. In Maxim AI's published benchmarks, Bifrost's Code Mode cut input tokens by up to 92.8% on large tool sets.

Do I need an MCP gateway for local stdio servers?

Usually not. A stdio server runs as a child process of the host on the user's own machine, with the user's own access, and the specification says it should take credentials from the environment. A gateway adds value when servers are shared over HTTP, when several teams need different access, or when security needs a central record of tool calls.

Sources

  1. 01Authorization, revision 2026-07-28Model Context Protocol
  2. 02Security best practicesModel Context Protocol
  3. 03Specification, current revisionModel Context Protocol
  4. 04RFC 8693: OAuth 2.0 Token ExchangeIETF
  5. 05MCP GatewayDocker docs
  6. 06agentgatewayLinux Foundation
  7. 07AI MCP Proxy pluginKong docs
  8. 08microsoft/mcp-gatewayGitHub
  9. 09Amazon Bedrock AgentCore GatewayAWS docs
  10. 10MCP gateway overviewBifrost docs
  11. 11BifrostGitHub