MCP protocol

How the Agent Gateway handles Model Context Protocol traffic across the session-based revisions (2024-11-05 to 2025-11-25) and 2026-07-28, including transport, methods, authorization server discovery, agent identity, OpenAPI proxying, and tool-level access control.

MCP (Model Context Protocol) is Anthropic’s standard for exposing tools, resources, and prompts to AI models. The Agent Gateway supports MCP as a first-class protocol: it proxies MCP traffic to upstream tool servers and can convert REST APIs into MCP-compatible tool endpoints. Set up an MCP surface →

What MCP enables

MCP enables AI models and applications to:

  • Discover available tools with their schemas.
  • Execute tool invocations with structured parameters.
  • Read data sources and file-like resources.
  • Retrieve pre-built prompt templates.
  • Receive notifications when the server’s tools, prompts, or resources change.

MCP transport

MCP messages are JSON-RPC 2.0 over HTTP or HTTPS. The gateway serves two kinds of MCP protocol revision, and each uses HTTP differently:

  • Session revisions (2024-11-05, 2025-03-26, 2025-06-18, and 2025-11-25): the client opens a session with initialize, and the Mcp-Session-Id header identifies the session on later requests. A response can stream back as Server-Sent Events (SSE), and the client can open a GET notification stream on the same URL. Clients that use the older SSE pattern, opening GET /sse and posting messages to a separate endpoint, also work through an Access Point, and MCP Proxies serve that pattern themselves.
  • 2026-07-28: each request is a self-contained POST, with no session and no initialize handshake. The request carries its protocol revision and client capabilities in params._meta, and repeats the revision and method in the MCP-Protocol-Version and Mcp-Method headers. A tools/call, prompts/get, or resources/read request also names its tool, prompt, or resource in the Mcp-Name header. The response is either JSON or an SSE stream, and a client that wants change notifications calls subscriptions/listen.

Between connected gateways, 2026-07-28 traffic travels as streamed Fabric messages. Session traffic travels as single forwarded requests, and a streamed response arrives at the caller as one final response.

MCP surfaces

An MCP surface forwards MCP JSON-RPC methods to its target tool server whatever their name, so a method the server adds reaches it with the gateway configuration unchanged. Common methods are tools/list, tools/call, resources/list, resources/read, prompts/list, and prompts/get.

The opening exchange depends on the revision. A client using a session revision starts with initialize. A 2026-07-28 client calls server/discover instead, and the gateway narrows the result to the protocol revisions and capabilities the surface supports. A 2026-07-28 client receives change notifications by calling subscriptions/listen.

An MCP Proxy answers a smaller set of methods itself, because it serves tools generated from an OpenAPI specification:

  • Session revisions: initialize, tools/list, and tools/call. An MCP Proxy answers initialize with 2024-11-05.
  • 2026-07-28: server/discover, tools/list, tools/call, and subscriptions/listen for changes to its tool list.

The surface applies the same inbound and outbound processing as other surface types, including identity extraction, OPA policy evaluation, rate limiting, and metadata injection, before and after forwarding.

Which MCP protocol revisions the gateway accepts

Every MCP endpoint on the gateway accepts the session revisions 2024-11-05, 2025-03-26, 2025-06-18, and 2025-11-25, and the sessionless revision 2026-07-28, with no setting to choose between them. This covers Access Points, Transit Points, MCP Proxies, and traffic between connected gateways over Fabric.

The gateway forwards a request that uses a session revision as session traffic, with its MCP-Protocol-Version header unchanged. An initialize that asks for one of the session revisions reaches the upstream MCP server unchanged, so the client and the server settle the revision between them. An initialize whose body asks for a revision outside this list is forwarded asking for 2024-11-05 instead.

A session request may also carry the Mcp-Method and Mcp-Name headers, as some clients send them on every request. The gateway checks them the same way as on a 2026-07-28 request: Mcp-Method must name the request’s method, and Mcp-Name must match the tool, prompt, or resource the request names. A mismatch returns HTTP 400.

When a request’s MCP-Protocol-Version header names any other revision, the gateway refuses the request, an initialize included, with HTTP 400 and JSON-RPC error -32022 (Unsupported protocol version). The error’s data shows the revision the client requested and lists the revisions the endpoint supports. A 2026-07-28 client calling server/discover gets the same list, narrowed to what the upstream supports. When an MCP Proxy answers server/discover, its list holds at most 2024-11-05 and 2026-07-28, because it runs its sessions at 2024-11-05. See Troubleshooting for how to resolve each error.

When a client sends a 2026-07-28 request to a surface whose upstream server supports only session revisions, the upstream refuses it for lacking a session. The gateway answers with -32022 and lists only the session revisions as supported, so the client can fall back to opening a session. Other upstream errors that the gateway can’t match to the request, such as an outage, still return HTTP 502. An MCP Proxy serves both kinds of revision itself. See MCP Proxy for the case where it can serve only 2026-07-28.

How the gateway checks each MCP request

Before tool gating, tool policies, or credential injection run, the gateway checks that each MCP request has a shape every component reads the same way. A request that fails a check is refused before it reaches the upstream server:

  • A POST body must be exactly one JSON-RPC object. Invalid JSON returns JSON-RPC error -32700, valid JSON other than an object returns -32600, and the gateway refuses a JSON-RPC batch.
  • Each key appears once per object, and keys that differ only in letter case count as the same key. Fields the gateway reads use their exact case, such as method and params.name rather than Method or params.Name. A body that breaks either rule returns -32600.
  • Access Points, Transit Points, and Fabric traffic accept the HTTP methods POST, GET, DELETE, HEAD, and OPTIONS. Any other method returns HTTP 405 with an Allow header listing them. A request with a body on any method other than POST returns HTTP 400 with -32600. A 2026-07-28 request uses POST only, so a GET or DELETE that declares that revision returns HTTP 405 with Allow: POST.
  • Legacy Server-Sent Events (SSE) sessions opened with GET /sse, on MCP Proxies and on surfaces whose target is an MCP Proxy or a connected gateway, are limited to 10,000 at once across the gateway. A request beyond that limit returns HTTP 429 with the message Too many active SSE sessions.

These checks keep tool gating and tool-scoped credentials reliable: the tool name the gateway checks is the same tool name the upstream server runs.

How MCP clients find where to sign in

An MCP Access Point that validates JWT bearer tokens from your identity provider can tell MCP clients where to get a token, through authorization server discovery. With it on, the gateway publishes a protected resource metadata document (RFC 9728) that names your authorization server, and answers a request with a missing or refused token with HTTP 401 and a WWW-Authenticate challenge that points at the document. An MCP client follows the challenge, signs the user in at your authorization server, and retries with a token issued for the Access Point.

The gateway accepts a token only when its audience (aud) is the resource URL the Access Point advertises, as the MCP authorization specification requires. The caller’s token stays at the gateway and is not passed on to the managed agent. Each variant advertises a resource of its own. Enable authorization server discovery for MCP clients →

MCP proxies (OpenAPI to MCP)

The gateway can convert any REST API into an MCP-compatible tool server by importing its OpenAPI specification. This lets AI models call existing REST APIs as if they were MCP tools, without modifying the API.

The gateway parses the OpenAPI specification and generates MCP tool definitions for each API endpoint. Clients discover and call these tools via standard MCP protocol. A surface serves an MCP Proxy by using it as its target, with the via MCP Proxy endpoint type.

Tool-level access control

OPA Rego policies can be scoped to individual MCP methods and tool names. This allows fine-grained control over which agents or roles can call specific tools.

For example, a policy can allow all MCP methods except tools/call for specific tool names, while allowing administrator-role agents full access. Policy input includes the MCP method, tool name, surface context, and JWT claims if bearer authentication is configured.

Filtering MCP tools by pattern, not by name

The per-tool policies above bind one Rego rule to one exact tool name, which works well when the full set of tool names is known in advance and each one needs its own logic. That approach does not scale as well when many tools share a naming convention, or when a tool server adds new tools over time, because each new tool needs its own rule added by hand.

MCP Tool Gating solves this by matching tool names against a regex pattern instead of an exact name, so one allow or deny rule can cover a whole family of tools at once, and by making a rule conditional on an OPA policy rather than always active. Where per-tool policies ask “does this exact tool’s policy allow the call?”, MCP Tool Gating asks “does this tool name match a pattern, and, if the gate has a condition, does that condition currently hold?”.

For example, an MCP proxy generated from a large OpenAPI specification can expose dozens of similarly named tools. A single Deny gate with a pattern such as ^admin_.*$ hides every admin-prefixed tool without a policy per tool, and a Deny gate whose Condition checks the caller’s organisation claim can hide the same family only for external callers, leaving it visible internally.

See MCP Tool Gating element for the field-level reference, and Control MCP tool access with per-tool policies for configuring the exact-name mechanism.

Identity in MCP

The gateway can derive an agent’s identity from MCP requests. With the Identity element’s extraction type set to From Payload (identity metadata), the gateway reads the identity object from the request’s _meta, under the field named in Identity Meta Field Name (agentIdentity by default). It reads that field on every MCP request, tool calls included:

  • 2026-07-28: the identity object goes in params._meta.
  • Session revisions: the identity object goes in params._meta, or in a top-level _meta object for older clients.

The gateway hashes the payload fields you mark as identity fields into a DID for the agent, and that DID follows the same identity lifecycle as on other protocols. When the field is missing, the gateway refuses the request with HTTP 422. The Identity element can also derive identity From API Key or From JWT Claims, with no _meta field involved.