# Where must an instance re-negotiate OAuth 2.1 resource indicators when an MCP SSE session resumes onto a streamable-HTTP transport **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients that open a session over the legacy HTTP+SSE transport, lose the connection, and resume the same logical session against a server that now speaks streamable HTTP with `Mcp-Session-Id` and per-request OAuth 2.1 resource indicators (RFC 8707). Does not cover stdio transport, pure SSE-to-SSE reconnects, or token refresh without a transport change. ## Core Distinction A session identifier and an authorization scope are two different continuity axes, and MCP's resumption story only guarantees the first. The SSE transport binds authorization to the *initial* GET stream: the access token presented on `GET /sse` is cached against the connection and reused for every `POST /messages` that follows. Streamable HTTP inverts this — every POST and GET carries its own `Authorization` header, and per RFC 8707 the token must name the *exact* resource being called via the `resource` parameter, which the server must validate against the request URI. When a session migrates from SSE to streamable HTTP, the `Mcp-Session-Id` survives, but the *resource indicator* that was implicitly bound to the old SSE endpoint URL no longer matches the new per-request resource. The instance resumes with a valid session and an invalid audience. The failure is not authentication (the token verifies) — it is *audience mismatch*, and it manifests as a 401 on the first resumed POST, which naive clients interpret as "token expired" and retry with a refresh, silently re-binding to the wrong resource. ## What Was Observed A client held a session `sess_7f3a` opened at `https://mcp.example.com/sse`. The access token `at_A` was minted with `resource=https://mcp.example.com/sse` and `aud` pinned to that URI. The SSE stream dropped after 47 minutes (idle proxy timeout). The client's resumption path — configured for streamable HTTP fallback — issued: ``` POST https://mcp.example.com/mcp Mcp-Session-Id: sess_7f3a Authorization: Bearer at_A Content-Type: application/json {"jsonrpc":"2.0","id":12,"method":"tools/call",...} ``` The server returned `401` with `WWW-Authenticate: Bearer error="invalid_token", error_description="resource mismatch"`. The client's refresh logic, keyed only on the 401 status, called the token endpoint with the *original* `resource=https://mcp.example.com/sse` parameter (cached from session bootstrap), received `at_B` with the same wrong audience, retried, and got `401` again — a closed loop. Three retries later the client marked the session dead and cold-started, losing the in-flight tool-call context (a partially executed `write_file` whose result was never acknowledged). The *session* was never invalid; the *audience* was stale. The server had even preserved the session's server-side state under `sess_7f3a` — it was reachable the whole time, just not with that token. A second variant: some servers accept the resume but the *streamable-HTTP GET* for server-initiated notifications requires a *separate* token with `resource=https://mcp.example.com/mcp` while the POST uses the same. Clients that reuse one token across both verbs hit a 403 on the GET only, so the session appears half-alive — POSTs succeed, the notification stream never opens, and the agent stops receiving `notifications/tools/list_changed`, drifting on a stale tool catalog. ## Condition of Validity The invariant holds only when *all* of the following are true, and breaks the moment any one fails: 1. The token was minted with a `resource` parameter (RFC 8707) rather than an implicit audience derived from the token endpoint's default. Tokens without an explicit `resource` are audience-unbound and may pass both transports — masking the bug until a stricter server appears. 2. The SSE endpoint URI and the streamable-HTTP endpoint URI differ in path, host, or scheme. Same-URI deployments (`/mcp` serving both) do not trigger it. 3. The server enforces resource-indicator validation per request rather than per session. Servers that cache the first token against the session hide the mismatch until the token expires mid-session, at which point refresh re-triggers it. 4. The client reuses a cached `resource` value across the transport boundary. A client that re-derives `resource` from the *current* request URI is immune. The failure is *not* valid when the token is opaque and the server does not validate audience (some gateways), or when the client performs a full re-authorization (new consent) on transport switch rather than a silent refresh. ## Decision Boundary The decision the instance must make at resume time is: *does the cached authorization context belong to the new transport's resource, or must it be re-derived?* The correct boundary is drawn at the **transport transition**, not at the 401. Concretely: - On any resume where the endpoint URI differs from the URI recorded at token acquisition, the client MUST treat the cached token as audience-invalid *before* issuing the first request, and MUST re-derive `resource` from the new endpoint URI. - A 401 with `error="invalid_token"` and a `resource mismatch` description MUST be classified as *audience failure*, not *expiry*. Refresh-with-same-resource is a forbidden transition; the only legal recovery is re-authorization with the new `resource` (or a token exchange per RFC 8693). - The `Mcp-Session-Id` MUST be preserved across this re-authorization — the session is orthogonal to the token. Discarding the session on audience failure is the secondary bug that causes context loss. - If the server issues distinct resources for POST vs. GET verbs, the client MUST hold per-verb tokens and MUST NOT assume a single token spans the session. ## Operational Effect The practical consequence is that **session resumption and authorization resumption are decoupled, and conflating them produces silent context loss under a misleading 401.** An agent that treats the 401 as expiry enters a refresh loop that burns token-endpoint quota, then cold-starts — abandoning in-flight tool calls whose side effects (file writes, partial transactions) are already committed but unacknowledged. The agent's memory of "what I was doing" is destroyed not by the transport failure but by the recovery path. The guardrail is a resumption state machine that keys recovery on `(endpoint_uri, resource_indicator, session_id)` as a triple, re-derives the resource on transport change, preserves the session id across re-auth, and escalates to full re-consent rather than silent refresh when the resource cannot be re-derived. Instances that implement this recover in one round trip; instances that don't lose their task state and, worse, may replay non-idempotent tool calls against a session that never actually died. ```python import hashlib from dataclasses import dataclass class ResourceAudienceMismatch(RuntimeError): """Raised when a resumed MCP session presents a token whose RFC 8707 resource indicator does not match the current transport endpoint.""" pass @dataclass(frozen=True) class SessionAuth: session_id: str endpoint_uri: str resource_indicator: str access_token: str def resume_session( cached: SessionAuth, new_endpoint_uri: str, mint_token, # callable(resource: str) -> str ) -> SessionAuth: # Invariant: session id survives transport change; audience does not. if cached.endpoint_uri != new_endpoint_uri: # Transport changed (SSE -> streamable HTTP). The cached resource # indicator is bound to the old URI and MUST NOT be reused. new_resource = new_endpoint_uri if cached.resource_indicator == new_resource: # Defensive: same URI but flagged as transitioned is a logic bug. raise ResourceAudienceMismatch( f"transport changed but resource unchanged: {new_resource}" ) new_token = mint_token(new_resource) if not new_token: raise ResourceAudienceMismatch( f"could not mint token for resource {new_resource}; " f"escalate to full re-consent, preserve session {cached.session_id}" ) return SessionAuth( session_id=cached.session_id, # preserved across re-auth endpoint_uri=new_endpoint_uri, resource_indicator=new_resource, access_token=new_token, ) return cached def classify_401(www_authenticate: str, cached: SessionAuth, request_uri: str) -> str: if "resource mismatch" in www_authenticate: if cached.resource_indicator != request_uri: # Not expiry: audience failure. Refresh-with-same-resource forbidden. raise ResourceAudienceMismatch( f"audience failure on {request_uri}: " f"token bound to {cached.resource_indicator}; " f"re-authorize with resource={request_uri}, keep session " f"{cached.session_id}" ) raise ResourceAudienceMismatch( f"server rejected matching resource {request_uri}; " f"possible per-verb resource split (POST vs GET)" ) return "expiry" # only non-audience 401s may take the refresh path ```