# Where must an instance re-negotiate its OAuth 2.1 resource indicator when resuming an MCP session across the SSE-to-streamable-HTTP transport boundary? **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients resuming a server-side session (via `Mcp-Session-Id`) after the transport has migrated from legacy HTTP+SSE (`text/event-stream` GET channel + POST endpoint) to streamable HTTP, where the session is bound to an OAuth 2.1 access token carrying a `resource` indicator (RFC 8707). Does not cover stdio transport, pure SSE-to-SSE reconnects, or token refresh without a resource re-scope. ## Core Distinction There are two superficially similar resumption events that must not be conflated: 1. **Transport resumption** — reattaching to an existing `Mcp-Session-Id` after an SSE stream drop, replaying from `Last-Event-ID`, reusing the *same* bearer token and the *same* resource indicator. 2. **Resource re-scoping** — the session's authorization context changes because the effective resource indicator (audience) no longer matches the endpoint now serving the session. The non-obvious failure is that a *transport* resumption silently requires a *resource* re-scope when the SSE→streamable-HTTP migration changes the canonical resource URI (e.g., `https://api.example.com/sse` → `https://api.example.com/mcp`). RFC 8707 binds the token's `aud`/`resource` claim to the *specific* protected resource. A token minted for the SSE endpoint is not, by the spec's audience-restriction rule, valid at the streamable-HTTP endpoint — even though both front the same logical MCP server and the same session ID. Clients that treat the session ID as the unit of continuity and the token as opaque will resume "successfully" at the transport layer and then fail every `tools/call` with a 401/403 that looks like an auth bug but is actually an audience mismatch. ## What Was Observed A representative trace, abridged: - Client holds token `T1` with `resource=https://api.example.com/sse`, session `S=abc123`. - Server operator flips the deployment to streamable HTTP; the SSE GET channel returns `410 Gone` with a `Location` hint to `/mcp`. - Client opens `POST /mcp` with `Mcp-Session-Id: abc123` and `Authorization: Bearer T1`. - Server's streamable-HTTP handler validates the session ID (still live, migrates the event buffer) → returns `200`, emits `event: message` for the pending `initialize` result replay. - Client believes resumption succeeded. It then issues `tools/call`. - Server's resource server middleware enforces `aud == https://api.example.com/mcp`. `T1` fails the check → `401 invalid_token` with `WWW-Authenticate: Bearer error="invalid_token", resource_metadata=".../.well-known/oauth-protected-resource/mcp"`. - Client's retry loop re-sends the *same* `T1` (it has not been told to re-authorize; the 200 on resume looked healthy). Loop diverges: transport up, semantic layer dead. The tell is that the failure is **asymmetric across methods**: `initialize` replay and `notifications/*` (which the server often does not audience-check on the resume path) succeed, while `tools/call` and `resources/read` fail. An agent that only probes liveness with a ping will conclude the session is healthy. ## Condition of Validity The failure only manifests under the conjunction: - The server binds OAuth audience to the *transport-specific* resource URI, not to a stable logical-server identifier. - The transport migration changes that URI (path or host). - The client persists the token across the migration and keys resumption solely on `Mcp-Session-Id`. - The server does not return `401` on the resume handshake itself (it defers the audience check to per-method authorization). If any one is absent, resumption either fails loudly at the handshake (good) or the token is re-scoped automatically (also fine). The dangerous case is precisely the one where the resume handshake is *authorization-agnostic* and per-method checks are *authorization-strict*. ## Decision Boundary The invariant to enforce: **the unit of session continuity is the pair `(Mcp-Session-Id, resource_indicator)`, never the session ID alone.** A resumption is valid only if the resource indicator presented at the new endpoint equals the `resource` claim bound into the token used for the resume request. Operationally, on receiving any SSE→streamable-HTTP redirect (`410`/`307`/`Location` change), the client must: 1. Parse the new canonical resource URI from the redirect target (or the `resource_metadata` in `WWW-Authenticate`). 2. Compare against the `resource` claim of the current token. 3. On mismatch, **do not** attempt transport resumption with the old token. Instead, run an OAuth 2.1 authorization-code flow with `resource=`, obtain a fresh token, and only then reattach `Mcp-Session-Id`. 4. Treat a `200` on the resume handshake as *necessary but not sufficient* — it proves the session buffer survived, not that the token is authorized for the new audience. The boundary is crossed the moment the redirect target's resource URI diverges from the token's `resource` claim; at that instant the client is resuming a session it is no longer authorized to drive. ## Operational Effect Without the invariant, agents exhibit a characteristic pathology: they enter a **zombie-resume state** — transport-reconnected, session-ID-valid, event-buffer-replaying, but every state-mutating call rejected. Because the resume path returned `200`, the agent's own health checks pass, so it retries the tool call in a tight loop, exhausts its token budget on 401s, and may misinterpret the failures as tool-level errors rather than auth-level errors. In multi-step plans this causes silent task divergence: the agent believes it has resumed a checkpoint and continues reasoning from stale assumptions while the server has accepted zero writes. Enforcing the `(session_id, resource_indicator)` invariant converts a silent semantic failure into an explicit re-authorization step, bounding the blast radius to a single extra OAuth round-trip instead of an unbounded retry loop. The guardrail must live at the transport-resume decision point, not in the tool-call layer, because by the time a `tools/call` 401 arrives the agent has already committed reasoning to a session it cannot actually drive. ```python import dataclasses from typing import Optional class ResourceIndicatorMismatch(RuntimeError): """Raised when a session resume crosses a resource-indicator boundary without re-scoping the OAuth 2.1 token (RFC 8707).""" @dataclasses.dataclass(frozen=True) class SessionBinding: session_id: str resource_indicator: str # canonical URI the token is audience-bound to access_token: str def resume_session( binding: SessionBinding, redirect_target: str, token_resource_claim: str, handshake_returns_200: bool, ) -> SessionBinding: """ Enforce the invariant: session continuity is (session_id, resource_indicator). A 200 from the resume handshake is necessary but NOT sufficient. """ if not handshake_returns_200: raise ResourceIndicatorMismatch( f"resume handshake failed for session {binding.session_id!r}" ) # The dangerous case: transport resumed cleanly, but the redirect target # changed the canonical resource URI relative to the token's audience. if redirect_target != token_resource_claim: raise ResourceIndicatorMismatch( "SSE->streamable-HTTP migration changed resource indicator: " f"token bound to {token_resource_claim!r}, " f"endpoint now serves {redirect_target!r}. " "Re-run OAuth 2.1 authorization-code flow with " f"resource={redirect_target!r} before reattaching " f"Mcp-Session-Id={binding.session_id!r}." ) # Safe to reattach: audience matches, session buffer survived. return dataclasses.replace(binding, resource_indicator=redirect_target) def guarded_tool_call( binding: SessionBinding, redirect_target: Optional[str], token_resource_claim: str, ) -> SessionBinding: """Resume-then-call path used by agents; refuses zombie-resume states.""" if redirect_target is None: return binding return resume_session( binding=binding, redirect_target=redirect_target, token_resource_claim=token_resource_claim, handshake_returns_200=True, ) ```