part…
Building governance for MCP?
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
An MCP gateway has well-defined points in the message flow where it can observe, validate, transform or block. This lesson enumerates them together with the spec rules that constrain them.
flowchart LR
H[Host] -->|1 discover| G[Gateway]
H -->|2 list| G
H -->|3 call/read/get| G
G -->|4 result| H
G <-->|5 MRTR| H
G -->|6 listen/notifications| H
G <-->|7 tasks| H
H <-->|8 OAuth| G
G --> S[Servers]
server/discover)Filter the capabilities and extensions you expose; rewrite instructions; pin the supportedVersions you translate; your own ttlMs. Limit: do not advertise what you do not implement.
tools/list, resources/list, prompts/list, resources/templates/list)Filter by approval and by user/scope; prefix names per server; exclude tools with an invalid x-mcp-header; validate schemas (no network $ref, composition limits); detect changes by hash; decide cacheScope (if you filter by user → private) and ttlMs (≤ the server's); deterministic order. Limit: do not change descriptions in a misleading way; do not alter inputSchema without also altering the validation you perform.
tools/call, resources/read, prompts/get, completion/complete)Validate arguments against inputSchema (validation errors as isError: true); authorisation per tool, user, scope and server; human confirmation according to policy and annotations (without trusting them); rate limiting and quotas; timeouts; translate ids and tokens; add Mcp-* and Mcp-Param-* headers towards modern HTTP servers; propagate traceparent. Limit: the host's _meta is preserved except for keys your policy removes; requestState intact.
Dispatch by resultType; validate structuredContent against outputSchema; redact PII and secrets in content; truncate; handle resource_link and embedded resources under the resource policy; log isError; translate errors between eras (-32002 → -32602); never turn an input_required into complete without resolving it.
Inspect every inputRequests entry: type allowed according to policy and the host's capabilities; form elicitation (no secrets, flat schema) and URL elicitation (allow-listed domain, no PII in the URL, HTTPS); sampling (blocked by default; otherwise token and iteration limits); roots (answer from configuration). Count rounds and cut loops. Preserve requestState.
One subscription per server with the union of filters; fan-out per host; translate subscriptionId; reconnect with backoff; audit list_changed and trigger re-indexing and hash comparison.
Transparent or materialising; translate ids; bind taskId to the user; apply policy to the inputRequests of tasks/get; per-user task limits.
Validate host tokens (signature, exp, aud, iss, scopes); emit 401/403 with precise challenges; obtain and refresh tokens per server (PKCE, resource, iss, CIMD); never pass through.
Model each point as a chain of validators and mutators configurable per server, host and user, with an audit mode (observe without blocking) to roll out new policies without breaking flows.
1. If the gateway filters tools/list by user, which cacheScope must it publish?
The result now depends on the authorisation context.
2. May the gateway modify requestState when forwarding an MRTR retry?
It is opaque to the client and to any intermediary; the gateway uses its own _meta.