AIP-77: MCP-GATEWAY (mcp-gateway/v1): dual-era MCP host gateway, server/discover, and extension negotiation

Specifies how an agentproto host serves its authenticated MCP gateway (/mcp) across both the legacy 2025-11-25 Streamable HTTP era and the stateless 2026-07-28 modern era: authentication-first dispatch, header and single-read body era routing, strict separation of accepted vs advertised protocol versions, server/discover and capabilities.extensions, error status mapping including -32021 (HTTP 400), shared tool-factory discovery modes (deferredTools/tool_search), unified session observability, and configuration rollback. Scope v1 covers /mcp only; /mcp/orchestrator and /mcp/imported/<id> stay on 2025-11-25. It also binds the beta MCP Skills extension (skills/list, skills/get, skill:// resources) and the transport of human input (permissions, questions, approvals, runs) as MRTR elicitation. Host primitives remain specified by their existing AIPs.

FieldValue
AIP77
TitleMCP-GATEWAY (mcp-gateway/v1): dual-era MCP host gateway, server/discover, and extension negotiation
AuthorJeremy André <[email protected]>
StatusDraft
TypeSchema
RequiresAIP-1 (process), AIP-46 (SESSION: host session tools and caller-identity boundaries exposed through the gateway)
Composes withAIP-3 (SKILL), AIP-7 (GOVERNANCE), AIP-20 (WORK), AIP-32 (MCP driver), AIP-45 (HARNESS), AIP-58 (RUN), AIP-76 (EVENT)
Created2026-11-26
Packages (ref-impl)@agentproto/runtime (mcp-modern, http-server, mcp-session-observer)
Prior artModel Context Protocol 2025-11-25 (Streamable HTTP) and 2026-07-28 (server/discover, stateless HTTP, caching hints, error codes)

Abstract

An agentproto host exposes its tools, resources, prompts, and protocol extensions over an authenticated MCP endpoint (/mcp). Existing clients speak the 2025-11-25 Streamable HTTP era (initialize handshake + SSE), while newer clients speak the stateless 2026-07-28 era (server/discover, strict MCP-Protocol-Version / Mcp-Method / Mcp-Name headers, resultType, caching hints, and capabilities.extensions).

MCP-GATEWAY specifies how one authenticated /mcp endpoint serves both eras side by side without breaking existing clients, duplicating authorization, or drifting the tool surface. It fixes the dispatch order, the separation between accepted and advertised protocol versions, the server/discover payload, error status mapping, shared discovery filtering (deferredTools / tool_search), unified observability, and the configuration switch to disable modern-era routing.

It also binds two features served on that era: the MCP Skills extension, which serves the host's skills (AIP-3), and the transport of human input requests as multi-round tool results (InputRequiredResult with elicitation/create).

Motivation

  • Existing MCP clients and embedded SDKs negotiate 2025-11-25 via initialize. Advertising 2026-07-28 from initialize or replacing the legacy transport breaks clients that expect a 2025-11-25 handshake.
  • Modern MCP capabilities (elicitation via multi-round tool requests, task projections, skills catalogs, and event extensions) require server/discover and 2026-07-28 framing on the authenticated /mcp endpoint, not only on a dedicated unauthenticated origin.
  • Splitting the modern era onto a separate URL would duplicate authentication, caller-identity enforcement, tool allow/deny filters, and deferred discovery, creating drift between the two surfaces.

Scope

Version 1 of this specification covers the root authenticated host endpoint /mcp only.

  • /mcp/orchestrator (scoped child-orchestrator sub-gateway) and /mcp/imported/<id> (per-import upstream passthrough) remain on the 2025-11-25 era. Bringing them to the modern era is separate work.
  • /mcp/events/<secret> (the public events origin defined in AIP-76) remains modern-only (supportedVersions: ["2026-07-28"]).
  • Host primitives (sessions, approvals, permissions, workboards, runs, skills, events) remain defined by their existing AIPs; this gateway does not replace or duplicate their semantics.

Design principles

  1. Auth before era. Authentication, origin checks, caller-identity enforcement, surface restrictions, and query-parameter parsing execute once, before deciding which protocol era handles the request.
  2. One tool factory. Both eras construct their server from the exact same factory and query filters (denyTools, allowTools, deferred, profile, surface). A modern tools/list and a legacy tools/list for the same caller and query return the same tool names.
  3. Accepted versions are not advertised versions. The set of protocol versions accepted by the modern handler (protocolVersions) is distinct from the set advertised in server/discover and -32022 errors (advertisedVersions). A request carrying a legacy version on the modern path MUST be rejected with -32022, never answered with 2026-07-28 shapes.
  4. Read the request body once. Routing inspects HTTP headers first. When body inspection is needed, the stream is buffered once (capped at the body limit) and the parsed object is handed directly to whichever era runs.
  5. Additive and reversible. Legacy initialize is unchanged and never advertises 2026-07-28. A host configuration flag (mcp.modernEra: false) disables modern-era routing cleanly.

Specification

Protocol versions

A conformant dual-era /mcp gateway maintains two explicit version lists:

  • Accepted modern versions (protocolVersions): ["2026-07-28"]. Only these versions are accepted by the modern validator.
  • Advertised versions (advertisedVersions): ["2026-07-28", "2025-11-25"]. Returned in server/discover (result.supportedVersions) and in -32022 (error.data.supported).

By contrast, a modern-only origin such as /mcp/events/<secret> (AIP-76) advertises only ["2026-07-28"].

Legacy initialize continues to negotiate 2025-11-25 and MUST NOT advertise 2026-07-28.

Dispatch order on /mcp

Every request arriving at /mcp MUST pass through the following sequence in order:

  1. Authorization and identity. Enforce host auth (loopback or bearer token), Origin validation, caller-identity attestation and enforcement, external session touch, query-parameter parsing (denyTools, allowTools, callerSessionId, origin, deferred, profile, surface), and surface restrictions (such as denying operator-only surfaces to daemon-spawned sessions). If mcp.modernEra is false, skip steps 2–4 and serve the request through the legacy transport.
  2. Non-POST verbs (GET, DELETE, etc.). Route to the modern handler if and only if the MCP-Protocol-Version header names a version in protocolVersions (the modern handler responds 405 Method Not Allowed with Allow: POST). Otherwise serve through the legacy transport (GET SSE stream, DELETE legacy handling).
  3. POST header check (zero body read). If the MCP-Protocol-Version header names a version in protocolVersions, buffer the body (enforcing the 1 MiB body limit with 413) and route directly to the modern handler.
  4. POST single-read body check. Otherwise, buffer the request body once (enforcing the gateway body limit with 413).
    • If the body is not valid JSON: if the request appears to be a modern call or cannot be parsed for dispatch, return HTTP 400 with JSON-RPC -32700 (Parse error, id: null). Never attempt to replay a drained stream into the legacy transport.
    • Route to the modern handler (passing the buffered raw body) when either:
      • body.method is a modern-only method (server/discover, or an extension method added by subsequent gateway bindings that does not exist in 2025-11-25), or
      • body.params._meta["io.modelcontextprotocol/protocolVersion"] names a version in protocolVersions.
  5. Legacy fallback. Otherwise, hand the already-parsed JSON object to the legacy Streamable HTTP transport (handleRequest(req, res, parsedBody)). Legacy header coercion (rewriting newer unknown MCP-Protocol-Version headers down to 2025-11-25 for older SDK compatibility) MUST run only inside this legacy branch, never before step 2.

A request whose MCP-Protocol-Version header is 2025-11-25 while its body _meta["io.modelcontextprotocol/protocolVersion"] is 2026-07-28 enters step 4 and is rejected by the modern validator with HTTP 400 -32020 (header mismatch), never silently downgraded.

A request calling server/discover with both header and _meta set to 2025-11-25 enters step 4 and is rejected by the modern validator with HTTP 400 -32022 (Unsupported protocol version, error.data.supported = ["2026-07-28", "2025-11-25"]), proving that advertisedVersions does not widen the accepted modern set.

server/discover and capabilities.extensions

server/discover builds its response from a fresh server instance produced by the shared factory (so capabilities reflect the caller's actual surface):

  • resultType: "complete".
  • supportedVersions: advertisedVersions (["2026-07-28", "2025-11-25"] on /mcp).
  • capabilities: the server's capabilities with the removed logging key stripped and listChanged withdrawn from tools, resources and prompts (list-change notifications travel over subscriptions/listen, which this gateway does not serve), plus extensions when at least one modern extension is enabled (omitted or empty when none are enabled).
  • _meta["io.modelcontextprotocol/serverInfo"]: { name, version }.
  • ttlMs and cacheScope: required on server/discover and the other five cacheable operations (tools/list, prompts/list, resources/list, resources/templates/list, resources/read), defaulting to { ttlMs: 0, cacheScope: "private" } when no host cache policy is supplied.

Per-request SSE responses

A modern request is normally answered with one application/json body. A method whose answer is a run of messages (today only events/stream, see AIP-76) is answered with a text/event-stream response owned by that request: one data: <json> frame per JSON-RPC message, no id: line, no SSE comment, closed when the method ends or the client goes away. The modern core answers such a method itself, before the in-process server bridge opens (the bridge only keeps replies to its own requests), and does not decorate its final frame with ttlMs, cacheScope or serverInfo. Validation errors are still plain JSON errors, and the method is in the allowed set only while its extension is enabled (else -32601, HTTP 404). There is no shared, session-wide SSE stream in the modern era.

Error mapping

The modern handler maps protocol errors to HTTP status codes as follows:

JSON-RPC codeMeaningHTTP status
-32700Parse error400
-32600Invalid request (batch, response body, wrong verb/Accept/Content-Type)400 / 405 / 406 / 415
-32601Method not found (including removed legacy methods such as initialize, ping, logging/setLevel)404
-32602Invalid params raised by the gateway itself: a malformed request (missing required _meta fields, params not an object, a missing parameter a header must mirror), a refused MRTR input request (forbidden caller, or an altered, expired, replayed or foreign requestState), a Tasks request, a Skills request400
-32020Header mismatch (MCP-Protocol-Version, Mcp-Method, Mcp-Name)400
-32021Missing required client capability (error.data.requiredCapabilities)400
-32022Unsupported protocol version (error.data.supported, error.data.requested)400
Handler errorsTool or extension domain errors not listed above, including a -32602 raised by a tool's own handler (for example an unknown tool or invalid arguments to tools/call) and a deliberate -32603 raised by a handler (for example tasks/cancel on a turn the harness cannot cancel, data.reason: "cancel-unsupported")200
Uncaught internal failureAn exception no handler turned into a JSON-RPC error, answered as -32603 without leaking internal details500

The 400 for -32602 follows the MCP specification only where it gives one: "A request missing any required field is malformed; the server MUST reject it with JSON-RPC error code -32602 (Invalid params). On HTTP, the response status MUST be 400 Bad Request." (MCP 2026-07-28, Base Protocol, Per-request protocol fields). This AIP reads params that is not an object, and a missing parameter that a header must mirror, as malformed requests of the same kind. The Skills page fixes -32602 without an HTTP status, and the MRTR page names neither a code nor a status (it asks only for "an appropriate error code"); this AIP fixes both at -32602 with 400, as for a Tasks request. Every other -32602, in particular one raised by a tool's handler on tools/call (the Tools page's own example is "Unknown tool: invalid_tool_name"), keeps HTTP 200, as the legacy era answers it.

Discovery modes and filtering

Query parameters that narrow or shape the tool catalog (?denyTools=, ?allowTools=, ?deferred=1, ?profile=, ?surface=) apply identically on both eras because both invoke the same server factory. Deferred tool discovery (deferredTools / tool_search) behaves identically on 2026-07-28 and 2025-11-25 so large tool surfaces do not bloat modern clients' context.

Observability

When the host records per-session MCP observations (keyed by the trusted caller session id), the modern branch MUST feed the same observation store as the legacy branch:

  • Successful and failed server/discover and tools/list results are recorded with the client's MCP-Protocol-Version.
  • HTTP-level rejections (status >= 400) on modern requests that never reach method execution are recorded as HTTP errors against the caller session.

Rollback configuration

Hosts expose a boolean configuration option mcp.modernEra (default true). When set to false, /mcp bypasses the modern dispatch path completely and serves all requests through the 2025-11-25 transport, including legacy version header coercion.

Skills binding

This section binds the MCP Skills extension (io.modelcontextprotocol/skills, beta) to the host. The skill format itself stays AIP-3; this binding only says how skills the host already holds are served over the modern era of /mcp.

  • Declaration. When the binding is enabled, the host announces capabilities.extensions["io.modelcontextprotocol/skills"] = {} in server/discover and also declares resources (files are read through resources/read). The optional directoryRead capability is not declared, and resources/directory/read is not served.
  • Source. Only the host's imported-skills registry is served. Files are read from the host's durable copy of each skill, not from the original source folder. Skills a host delivers to a session at spawn are unaffected by this binding.
  • skills/list returns { skills, nextCursor? }. Each entry is { uri, frontmatter, resources }: uri is skill://<name>/SKILL.md, frontmatter is the parsed frontmatter of SKILL.md encoded as JSON (every key kept, no key renamed; YAML-only forms such as dates or anchors arrive as their JSON values), and resources lists every file of the skill as { uri, digest, size }. The cursor is opaque.
  • skills/get takes { uri: "skill://<name>/SKILL.md" } and returns { skill } with the same entry shape. Any other path is -32602.
  • Files. skill://<name>/<path> is read through resources/read, as text when the bytes are valid UTF-8 without a NUL byte, otherwise as a base64 blob.
  • Caching hints. skills/list and skills/get carry ttlMs and cacheScope, like the other cacheable operations. skills/get requires no Mcp-Name header; resources/read keeps its uri one.
  • Naming. The <name> segment is the skill's frontmatter name (its registry id), never a display alias. A skill whose frontmatter name differs from its registry id, or whose description is missing or empty, is not served.
  • Manifest and digests. digest is sha256:<hex> over the raw bytes of the file. It lets a client detect drift; it is not a trust anchor (it is unsigned and comes from the same server). A file whose bytes no longer match the manifest is re-checked against a rebuilt manifest before it is served.
  • Ceilings. A skill of more than 512 files or more than 16 MiB is not served, and skills/get says why.
  • Path confinement. A skill:// path is split without URL normalization; empty, ., .., or encoded separator segments are -32602. A file that is not in the manifest is -32602. The real path of every file is checked to stay inside the skill folder before any byte is read, so a symbolic link that leaves the folder is neither listed nor readable.
  • Rollback. The binding has its own switch, mcp.extensions.skills (default true); false stops announcing and serving it.

Human input over MRTR

A host that already parks work on a human (an AIP-45 permission or question, an AIP-7 approval, an AIP-58 run waiting for input) MAY expose that request to a 2026-07-28 client as an InputRequiredResult (resultType: "input_required") carrying one elicitation/create request. This is only a transport: the existing judge of each primitive still decides, and an elicitation never replaces it.

The host projects four surfaces:

SurfaceObserved onElicitation modeWho is asked
Held permissionpermissions_list, session_monitor, tasks/get of the session's turn (AIP-78)formthe operator, or a session resolving one of its own descendants
Session questionsame as aboveformsame as above
Pending approvalapproval_get, approval_waiturlthe caller of approval_get / approval_wait
Run waiting for inputworkflow_statusformthe operator only

Rules:

  • Capability first. A surface is projected only to a client that declared the matching elicitation mode. A client that declared neither mode, or a surface that cannot be expressed, gets the tool's ordinary result. Nothing is ever lost: the primitive stays answerable through its own tools.
  • Flat forms, no secrets. A form is only produced from the flat requestedSchema subset. A field whose key or prompt points at a secret, a credential or payment data is never put in a form; such a request is not projected.
  • Approvals. The url is the host's configured approval page plus the approval id. Without a configured page, no approval elicitation is produced. A base that could carry a credential (userinfo, fragment, credential-like query key) is refused. An accept from the client only records that the page was shown: it neither decides nor consumes the approval.
  • No self-resolution. A session is never asked to resolve its own permission or question, and a spawned session can only resolve requests of sessions in its own subtree. Runs are observed by the operator only.
  • Replay token. The requestState is signed by the host and binds the caller, the tool, a hash of the original arguments (without _meta, requestState and inputResponses), the entity kind and id, an expiry and a single-use 128-bit nonce. A retry whose token is altered, expired, already used, issued to another caller, for another tool or for other arguments, or that names an unknown kind is rejected with -32602. A missing or incomplete answer produces a fresh InputRequiredResult, not an error.
  • Durability. Approval and run tokens stay verifiable across a host restart (the signing key and the consumed nonces are stored). Permission and question tokens are bound to the host's boot: a token from a previous boot is rejected with -32602 (data.reason: "input_unavailable"), it is not re-projected.
  • Not projected. A run waiting on an escalate policy (it carries neither a question nor a schema); a run whose input schema is not flat (no console page exists to send it to); workflow_run_file and approval_request (workflow_status and approval_get are the observers). A form for a single choice that also allows free text loses its choices, because the flat subset cannot express both.
  • Rollback. mcp.humanGate (default true) switches every surface off; mcp.humanGateApprovals and mcp.humanGateRuns (default true) switch the approval and run surfaces off on their own.

Security considerations

  • No auth bypass. Modern routing happens strictly after authorizeMcp, enforceCallerIdentity, and surface restriction checks. A modern client without a valid bearer token (when bearer auth is active) or with an untrusted Origin receives the same 401 / 403 rejection as a legacy client.
  • No silent downgrade on mismatch. Conflicting header and _meta protocol versions are rejected (-32020) rather than coerced.
  • Bounded memory. Request bodies buffered for dispatch or modern handling enforce the gateway size ceiling and reject oversized payloads with 413.

Conformance

A host conforms to mcp-gateway/v1 when:

  1. /mcp serves server/discover, tools/list, tools/call, resources/*, prompts/*, and events/* under 2026-07-28 while continuing to serve initialize and all existing methods under 2025-11-25.
  2. server/discover on /mcp advertises ["2026-07-28", "2025-11-25"], while a modern request carrying 2025-11-25 in both header and _meta is rejected with HTTP 400 -32022.
  3. Every auth check, Origin check, caller-identity check, and query filter (denyTools, allowTools, deferred, surface) produces identical enforcement on both eras.
  4. -32021 maps to HTTP 400; -32601 maps to HTTP 404; -32020 and -32022 map to HTTP 400.
  5. Modern server/discover, tools/list, and HTTP errors update the host's session observation store.
  6. Setting mcp.modernEra to false restores pure legacy routing on /mcp.
  7. With the Skills binding enabled, server/discover announces the extension and resources; skills/list, skills/get and resources/read on skill:// serve only registry skills under their name, with digests over raw bytes and ttlMs / cacheScope on both methods; a traversal segment or a file outside the manifest is -32602; a skill above 512 files or 16 MiB is not served.
  8. With the human gate enabled, a held permission, a session question, a pending approval (url, only with a configured page) and a run waiting for input (operator only) are projected as InputRequiredResult to a client that declared the matching elicitation mode, and to no other client; a form never carries a secret field; an approval accept neither decides nor consumes; a session never resolves its own request; an altered, expired, replayed or foreign replay token is -32602.

See also

  • AIP-1: process and RFC 2119 terminology
  • AIP-3: SKILL, the format of the skills served by the Skills binding
  • AIP-7, AIP-45, AIP-58: the approvals, permissions and questions, and runs whose human input is carried over MRTR
  • AIP-46: SESSION, whose MCP tools are exposed through this gateway
  • AIP-78: TURN-TASK, whose tasks/get also carries a session's pending input
  • AIP-76: EVENT and the mcp-events/v1 public origin

AIP-76: EVENT (event/v1): host event subscriptions and signed webhook delivery, with the mcp-events/v1 binding

Fixes how an agentproto host lets an external client watch it: event definitions (name, description, delivery, inputSchema, payloadSchema), subscription identity (RFC 8785 JCS-deterministic sub_<hex32>, idempotent subscribe/refresh/unsubscribe, ttlMs 60s..30d default 7d), the signed callback challenge (type:verification, single-use 64-hex) that must pass before any mutation, the {eventId, name, timestamp, data, cursor} wire envelope, webhook delivery as Standard Webhooks (whsec_ secrets 24-64 bytes, v1 signatures, 10-minute dual-sign rotation window), the delivery guarantees (one event per POST, 256 KiB clamp to {summary, subject}, 2xx = ack, exponential backoff bounded to 5 attempts, never retry 410/413), and the durable outbox that makes delivery at-least-once across restarts. EVENT is transport-neutral; this AIP also fixes its first binding, mcp-events/v1: three native JSON-RPC methods (events/list, events/subscribe, events/unsubscribe) on the authenticated MCP endpoint, the events:{} capability at initialize, and a public MCP 2026-07-28 events origin (POST /mcp/events/<secret>). The binding also carries the MCP Events extension (io.modelcontextprotocol/events, protocol 2026-07-28): events/poll over a durable journal, events/stream (SSE push with notifications/events/*), the official -32023..-32027 error codes and the Mcp-Name header. It fills AIP-60's frozen webhook target kind with its delivery contract and does not touch the inbound inbox path. There is no EVENT.md file.

AIP-78: TURN-TASK (turn-task/v1): projecting one session turn as an MCP task

Specifies how a host that serves the 2026-07-28 MCP era projects a single turn of an AIP-46 session as an MCP task: server-decided creation for agent_start and agent_prompt, an opaque unguessable taskId bound to a prompt ticket and to its creating principal through a durable ledger, the turn-to-task state mapping, tasks/get, tasks/update and tasks/cancel semantics, cooperative cancellation that ends the turn and not the session, retention, and error codes. It does not replace the AIP-20 work board and does not change the multi-turn lifecycle of AIP-46.