# Under what conditions must an instance treat MCP transport upgrade negotiation as a state machine rather than a capability probe **Date of Record:** 2026 November 23 **Scope:** Applies to MCP servers exposing both the legacy HTTP+SSE transport and the streamable-HTTP transport on the same origin, where clients may attempt resumable upgrade negotiation and per-tool OAuth resource indicators are in play. Does not apply to stdio transports, single-transport servers, or deployments where the `Mcp-Session-Id` is not persisted across transport boundaries. ## Core Distinction A capability probe asks "does this server support streamable HTTP?" and acts on the answer. An upgrade negotiation asks "is *this session*, *this tool*, and *this OAuth resource indicator* jointly eligible to migrate from SSE to streamable HTTP, and at what point in the message stream?" The failure mode arises when an implementation collapses the second question into the first: it observes a `POST` succeeding against the streamable endpoint and concludes the session is upgraded, without verifying that the SSE stream's `Last-Event-ID` continuity, the negotiated `Mcp-Session-Id`, and the per-tool `resource` indicator on the bearer token are all consistent at the same instant. The non-obvious invariant: **an MCP session is not upgraded until the first streamable-HTTP response carries an event whose ID is strictly greater than the last event ID the client acknowledged on the SSE stream, *and* the OAuth token presented on that request carries a `resource` indicator matching the tool being invoked.** Either condition alone is insufficient and both are routinely violated in practice because they are checked at different layers (transport vs. auth middleware) that do not share state. ## What Was Observed In a deployment serving ~40 tools behind a single MCP endpoint, clients using the SSE transport were offered an upgrade by a reverse proxy that advertised streamable HTTP via an `MCP-Protocol-Version` header and a `Link: rel="streamable"` hint. The proxy accepted `POST /mcp` with `Mcp-Session-Id` and returned `200 OK` with a streamable response. Clients treated this as upgrade completion and dropped the SSE connection. Two distinct failures followed: 1. **Event-ID regression.** The streamable response began at event ID `1` (fresh per-connection counter) rather than continuing from the SSE stream's last acknowledged ID (e.g., `8412`). Clients that had buffered resumable state replayed or dropped messages. The proxy had no shared counter between the SSE backend and the streamable backend because they were separate upstream pools. 2. **Resource-indicator mismatch.** The OAuth token used for the SSE session carried `resource=https://mcp.example.com/sse`. When the same token was presented against the streamable endpoint, per-tool resource indicators required `resource=https://mcp.example.com/mcp/tools/`. Tools that validated the indicator rejected the call with `401 invalid_token`; tools that did not validate it accepted the call, producing a split-brain where half the tool surface worked post-upgrade and half did not, with no signal to the client about which invariant had failed. The combined effect: sessions appeared upgraded, then partially failed, and the SSE fallback had already been torn down. Recovery required full re-authentication and session re-establishment. ## Condition of Validity The state-machine treatment is *required* (not merely recommended) when all of the following hold: - The server exposes both transports on the same origin and accepts `Mcp-Session-Id` across both. - The SSE stream uses monotonic event IDs that the client acknowledges via `Last-Event-ID` on reconnect. - OAuth tokens carry RFC 8707 `resource` indicators, and at least one tool validates them per-call. - The streamable and SSE backends do not share a monotonic event counter or a session store. When any of these is false — e.g., a single backend serves both transports with a shared counter, or no tool validates resource indicators — the simpler capability-probe model is sound and the state machine adds unnecessary latency. The distinction matters because the probe model is cheap and the state-machine model requires cross-layer coordination between transport and auth middleware. ## Decision Boundary The boundary is crossed at the moment the client receives a streamable `200` but before it has confirmed event-ID continuity and resource-indicator validity for the *specific tool* it intends to call next. The correct decision rule: - **Do not tear down the SSE stream** until a streamable response has delivered an event with `id > last_acknowledged_sse_id` *and* the client has confirmed the token's `resource` indicator is accepted for the next tool invocation. - **Treat the upgrade as provisional** while either condition is unconfirmed; keep the SSE stream open in a draining state. - **On any `401 invalid_token` from a streamable call**, do not retry with the same token against a different tool; the resource indicator is per-tool and the token is scoped to the pre-upgrade resource. Re-acquire a token with the post-upgrade resource indicator. The failure mode is entering the "upgraded" state on the basis of transport-level success alone. The boundary is between transport-level acknowledgment and auth-and-continuity-level acknowledgment; they are not the same event and must not be conflated. ## Operational Effect Systems that implement the state machine correctly pay a small cost: they hold the SSE stream open through the first streamable round-trip and perform a token-resource check before declaring success. Systems that collapse the distinction observe partial tool-surface failures post-upgrade, event replay or loss, and recovery requiring full re-authentication. The observable signature of the bug is a session that reports healthy at the transport layer while a subset of tools return `401` — and the subset correlates exactly with which tools validate resource indicators. That correlation is the diagnostic: if tool failures partition cleanly along indicator-validation lines, the upgrade was declared prematurely. ```python class PrematureUpgradeError(RuntimeError): """Raised when a streamable-HTTP upgrade is declared before event-ID continuity and per-tool OAuth resource-indicator validity are both confirmed for the session.""" def confirm_upgrade( last_acknowledged_sse_id: int, first_streamable_event_id: int, token_resource: str, next_tool_resource: str, sse_stream_open: bool, ) -> None: if not sse_stream_open: raise PrematureUpgradeError( "SSE stream already torn down; cannot confirm continuity" ) if first_streamable_event_id <= last_acknowledged_sse_id: raise PrematureUpgradeError( f"event-ID regression: streamable id {first_streamable_event_id} " f"<= last acknowledged SSE id {last_acknowledged_sse_id}" ) if token_resource != next_tool_resource: raise PrematureUpgradeError( f"resource-indicator mismatch: token scoped to {token_resource!r}, " f"next tool requires {next_tool_resource!r}" ) # Only here is the session genuinely upgraded. ```