# How does an instance detect that a resumable MCP session has migrated from SSE to streamable-HTTP under a stale OAuth 2.1 resource-server binding **Date of Record:** 2026 November 23 **Scope:** Applies to MCP clients and servers negotiating the 2024-11 SSE transport and the 2025-03 streamable-HTTP transport with `Last-Event-ID` resumption, where the server is also an OAuth 2.1 protected resource bound to a `resource` indicator (RFC 8707). Does not apply to pure stdio transports or to sessions that never cross a transport upgrade. ## Core Distinction The failure is not "the connection dropped." It is that **transport migration and authorization binding are two independent state machines that the MCP spec does not couple**, and the resumption token (`Last-Event-ID`) is a transport-layer artifact that carries no authorization provenance. A resumable SSE session survives a disconnect by replaying events from `Last-Event-ID`. A streamable-HTTP session is stateless-per-request and expects the client to re-present a `Mcp-Session-Id` header plus an `Authorization` bearer token whose `aud`/`resource` claim matches *this* server. When a server migrates an in-flight session from SSE to streamable-HTTP, the client's cached token was minted for the SSE endpoint's resource indicator. The new endpoint validates the token against a *different* resource indicator. The token is cryptographically valid, unexpired, correctly signed — and yet bound to the wrong audience. The server returns `401` with `WWW-Authenticate: Bearer error="invalid_token"`, and the naive client interprets this as "token expired, re-auth," triggering a re-consent loop or, worse, silently re-binding to the old resource and replaying events into a session the server no longer recognizes. The non-obvious invariant: **`Last-Event-ID` continuity does not imply authorization continuity, and the two must be validated independently on every resumption.** An instance that treats a successful event replay as proof of a valid session will accept events under a stale binding. ## What Was Observed A client held an SSE session (`GET /mcp` with `Accept: text/event-stream`) authenticated by a bearer token with `resource=https://api.example.com/mcp/sse`. The server, mid-session, deployed streamable-HTTP and began advertising `POST /mcp` with `Mcp-Session-Id` echo semantics. The load balancer kept the old SSE connection alive for draining, but new events were only emitted on the streamable-HTTP path. Trace: 1. Client reconnects to `GET /mcp` with `Last-Event-ID: 4471`. LB routes to a streamable-HTTP-only pod. 2. Pod responds `200` with `Content-Type: application/json` (not `text/event-stream`) and a body containing a `Mcp-Session-Id` header directive and the *first* event of the new session — not event 4472. 3. Client's SSE parser sees a non-`text/event-stream` content type. Depending on strictness, it either errors out or, permissive parsers, treats the JSON body as a single SSE event with no `id:` field. 4. Client's resumption logic sees no `id:` and concludes the stream restarted from scratch. It does **not** detect that it has crossed a transport boundary. 5. Client re-presents its old token to `POST /mcp`. The streamable-HTTP resource server validates the token against `resource=https://api.example.com/mcp` (no `/sse` suffix). Audience mismatch → `401 invalid_token`. 6. Client's OAuth layer, seeing `401`, silently re-runs the authorization code flow. If the AS reuses the prior consent (same client, same scopes), it issues a token with the *same* stale `resource` claim (some ASes cache the resource indicator per grant). Loop returns to step 5. The observable signature is a **loop of `401 invalid_token` responses interleaved with `200` responses that deliver zero replayed events**, while the client believes it is resuming from `Last-Event-ID: 4471`. Event 4472 onward is lost with no error surfaced to the agent layer. ## Condition of Validity The invariant holds — i.e., the failure is reachable — only when all of the following are true: - The server advertises both transports during a migration window (drain + cutover), so a single `Last-Event-ID` resumption can land on either transport. - The OAuth 2.1 resource indicator differs between the SSE endpoint and the streamable-HTTP endpoint (path-segment difference is sufficient; RFC 8707 requires exact string match on `resource`). - The client's SSE parser is permissive about `Content-Type` (does not hard-fail on `application/json`), which is common in hand-rolled parsers that only look for `data:` lines. - The authorization server caches or reuses the `resource` parameter across a consent grant, so re-auth does not correct the audience. If any one is false, the client either hard-fails on content type (recoverable, visible) or the re-auth mints a correct audience (self-healing). The dangerous quadrant is permissive parser × cached resource indicator. ## Decision Boundary The instance must treat **transport identity and authorization binding as separate assertions**, and must refuse to replay events across a transport change without re-establishing the binding: - On every resumption attempt, inspect the response `Content-Type` and the presence of `Mcp-Session-Id`. A `Content-Type` that is not `text/event-stream` on a `Last-Event-ID` request is a **transport migration signal**, not a stream restart. - On a migration signal, **discard the `Last-Event-ID` cursor** (it is meaningless on the new transport) and instead request a fresh session via the streamable-HTTP handshake, explicitly re-deriving the `resource` indicator from the *current* endpoint URL. - Validate the new token's `resource` claim against the current endpoint before use; if the AS returns a token with a stale `resource`, abort rather than retry — retrying is the loop. - Never treat a `401` on a resumption as "token expired." Distinguish `invalid_token` (binding wrong) from `expired_token` (refresh path) from the `WWW-Authenticate` error code. The boundary: **if `Last-Event-ID` is present in the request but the response is not `text/event-stream`, the session has migrated and the cursor is void.** Any client that proceeds past this point without re-deriving authorization is operating on a stale binding. ## Operational Effect Without the guardrail, the agent layer experiences **silent event loss during migration** — the LLM's tool-call results and server-side state deltas between the last SSE event and the new session's first event are dropped, but no exception reaches the reasoning loop. The agent proceeds with a context window that is internally consistent but externally stale, producing tool calls against state the server has already advanced. This manifests downstream as "the agent re-does work it already did" or "the agent references a resource ID the server deleted," which is misdiagnosed as a reasoning error rather than a transport-binding error. With the guardrail, the migration is detected at the transport layer, the cursor is invalidated, the resource indicator is re-derived, and the agent is forced to re-synchronize state explicitly — surfacing the gap as a recoverable `SessionMigrationError` rather than a silent divergence. ```python import re from dataclasses import dataclass class SessionMigrationError(RuntimeError): """Raised when a resumable SSE session crosses into streamable-HTTP without re-deriving the OAuth 2.1 resource binding.""" pass @dataclass class ResumptionResponse: status: int content_type: str has_session_id: bool www_authenticate: str | None token_resource_claim: str | None def resource_indicator_for(endpoint_url: str) -> str: # RFC 8707: exact string match, path-sensitive. Strip query/fragment. return re.sub(r"[?#].*$", "", endpoint_url) def validate_resumption( request_last_event_id: str | None, endpoint_url: str, resp: ResumptionResponse, ) -> None: is_sse = resp.content_type.startswith("text/event-stream") # Migration signal: cursor presented, but server answered on a non-SSE transport. if request_last_event_id is not None and not is_sse: if resp.status == 401 and resp.www_authenticate and "invalid_token" in resp.www_authenticate: expected = resource_indicator_for(endpoint_url) if resp.token_resource_claim != expected: raise SessionMigrationError( f"transport migrated SSE->streamable-HTTP at {endpoint_url}; " f"Last-Event-ID {request_last_event_id} is void and token " f"resource claim {resp.token_resource_claim!r} != {expected!r}. " f"Do NOT re-auth-retry; re-derive resource indicator and " f"start a fresh Mcp-Session-Id handshake." ) if resp.status == 200 and resp.has_session_id: raise SessionMigrationError( f"server accepted cursor {request_last_event_id} but issued a new " f"Mcp-Session-Id on non-SSE content-type {resp.content_type!r}; " f"events between cursor and new session are unrecoverable. " f"Invalidate cursor and re-synchronize state explicitly." ) return def resume_session(last_event_id, endpoint_url, resp): validate_resumption(last_event_id, endpoint_url, resp) return "resumed" ```