# In what scenarios must an instance re-authorize an MCP Streamable HTTP session when the OAuth 2.1 resource-server token audience silently rotates mid-stream **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients using Streamable HTTP transport against a remote tool server that acts as an OAuth 2.1 resource server, where the authorization server (AS) can rotate the resource indicator/audience bound to a live access token. Does not apply to stdio transport, to servers using static bearer tokens, or to pure A2A handoffs where each call carries its own warrant. ## Core Distinction The failure is not "the token expired." It is subtler: the token remains cryptographically valid and unexpired, but the *audience* (`aud`/resource indicator) it was minted for no longer matches the resource identifier the server now asserts in its Protected Resource Metadata (RFC 9728). Streamable HTTP keeps a long-lived POST stream (and an SSE channel keyed by `Mcp-Session-Id`) open across many tool calls. OAuth 2.1 resource-server validation is typically performed at connection/stream establishment, not per JSON-RPC message. So the session survives a token whose audience has drifted, and the server keeps executing tool calls against a token that *should* now be rejected — until some later, unrelated event forces a fresh validation and the whole session collapses with a `401 invalid_token` in the middle of a multi-step tool chain. The invariant that is violated: **audience binding is a property of each request, but Streamable HTTP amortizes authorization across a stream.** The moment the resource indicator rotates, "authorized at stream open" and "authorized now" diverge, and nothing in the transport re-checks the gap. ## What Was Observed A remote tool server fronted by an AS that supports resource indicators. The client completed the OAuth 2.1 flow, received an access token with `aud = https://tools.example/mcp/v1`, and opened a Streamable HTTP session: an initial `POST /mcp` returning `Mcp-Session-Id: 7f3a...`, followed by a `GET /mcp` SSE stream carrying server→client notifications. Mid-task, the operator redeployed the server behind a new resource path and updated its `/.well-known/oauth-protected-resource` to advertise `resource = https://tools.example/mcp/v2`. The AS, honoring the new registration, began issuing tokens for `/v2` and — critically — started treating tokens with `aud=/v1` as no longer valid *for the v2 resource*, while leaving them unexpired. Observed trace: 1. Client continues issuing JSON-RPC `tools/call` frames over the existing `7f3a` session. The server's per-message handler does *not* re-validate `aud` (validation was hoisted to stream setup). Calls succeed for a window. 2. A tool call triggers an internal sub-request that *does* perform fresh resource-server validation (e.g., a sidecar that checks `aud` against current metadata). It returns `401` with `WWW-Authenticate: Bearer error="invalid_token", resource_metadata="https://tools.example/.well-known/oauth-protected-resource"`. 3. The server surfaces this as a JSON-RPC error on the in-flight request but does *not* tear down the session. The client sees a tool-level error, not a transport-level auth failure, and — because it is mid-reasoning-loop — treats it as a transient tool fault and retries. 4. Retries re-send over the same stale session with the same stale-audience token. Each retry burns a tool-call budget slot and compounds the reasoning divergence: the agent now believes the tool is flaky rather than unauthorized. 5. Only when the SSE `GET` stream is re-established (idle timeout, or a server restart) does transport-level validation run, returning `401` at connection time. At this point the client finally re-authorizes — but the `Mcp-Session-Id` is gone, and any server-side state keyed to it (in-progress multi-call transaction, cursor into a paginated result set) is lost. Net effect: a silent window of mis-authorized execution, followed by error-compounding retries, followed by a hard session reset that discards state the agent had no checkpoint for. ## Condition of Validity This boundary is reachable only when all of the following hold simultaneously: - The transport is Streamable HTTP with a persistent session (`Mcp-Session-Id`) spanning multiple JSON-RPC messages. - The server performs OAuth 2.1 resource-server audience validation at **stream/session establishment** rather than per-message. - The AS supports resource indicators and the resource identifier is **rotatable** (versioned path, tenant migration, regional failover) without invalidating the token's signature or `exp`. - At least one code path inside the server performs **fresh** per-request validation (a sidecar, a downstream call, a batch validator), creating the split where some messages fail and others pass on the same session. If validation is uniformly per-message, the very first post-rotation call returns `401` cleanly and the client re-authorizes with no silent window. If the resource identifier never rotates, the gap never opens. The dangerous case is precisely the *mixed* validation topology. ## Decision Boundary The client must decide, on any `401`/`invalid_token` — even one wrapped inside a JSON-RPC tool error — whether to (a) treat it as a tool fault and retry on the current session, or (b) treat it as an audience/session-invalidating condition and re-run discovery + re-authorize + establish a new session. The rule that bounds the failure: **any `invalid_token` whose `WWW-Authenticate` carries a `resource_metadata` pointer that differs from the resource the session was established under is a session-invalidating condition, not a tool fault.** The client must not retry it on the same `Mcp-Session-Id`. It must re-fetch the protected-resource metadata, compare the advertised `resource` against the audience of its current token, and if they differ, discard the session, re-authorize against the new resource, and re-establish — replaying any checkpointed tool-chain state explicitly rather than assuming the server retained it. Conversely, a `401` whose `resource_metadata` matches the session's establishment resource is a genuine token problem (expiry, revocation) and follows normal refresh-then-retry. The discriminator is the *metadata pointer*, not the status code. ## Operational Effect Without this boundary, agents exhibit a characteristic pathology: they interpret authorization drift as tool flakiness, spend tool-call budget on futile retries, and then lose session-scoped state when the transport finally resets. The reasoning loop diverges because the agent's model of the tool ("unreliable") is wrong ("unauthorized for a rotated audience"). With the boundary enforced, the failure becomes a clean, bounded re-authorization: detect metadata-pointer mismatch → checkpoint in-flight tool-chain state → drop session → re-discover → re-authorize → resume from checkpoint. The silent mis-authorized window is eliminated because the *first* fresh-validation `401` is escalated to session invalidation rather than absorbed as a tool error. The cost is an extra discovery round-trip on every rotation; the benefit is that authorization state and transport state can never silently desynchronize. ```python from dataclasses import dataclass from typing import Optional class AudienceRotationError(RuntimeError): """Raised when a 401 invalid_token carries a resource_metadata pointer that no longer matches the resource the MCP session was established under.""" pass @dataclass class SessionContext: session_id: str established_resource: str # resource asserted at stream open token_audience: str # aud/resource the current token was minted for checkpoint: Optional[dict] = None # agent's serialized tool-chain state def handle_tool_error(ctx: SessionContext, error: dict) -> str: """ Decide whether a 401/invalid_token is a tool fault (retry) or a session-invalidating audience rotation (re-authorize + resume). Returns an action token for the agent loop. """ if error.get("code") != 401 or error.get("error") != "invalid_token": return "retry_tool" # ordinary tool fault, safe to retry advertised = error.get("resource_metadata") if advertised is None: # No metadata pointer: cannot distinguish rotation from revocation. # Fail closed to re-authorization; never silently retry. return "reauthorize_and_reset" if advertised != ctx.established_resource: # Audience rotated: the session is now mis-authorized. Do NOT retry # on this session — the server may still execute against a stale aud. raise AudienceRotationError( f"session {ctx.session_id} established under {ctx.established_resource!r} " f"but server now advertises {advertised!r}; token aud={ctx.token_audience!r}. " f"Checkpoint state, drop session, re-discover, re-authorize." ) # Metadata matches: genuine token expiry/revocation, normal refresh path. return "refresh_token_and_retry" def resume_after_rotation(ctx: SessionContext, new_resource: str) -> dict: if ctx.checkpoint is None: raise AudienceRotationError( f"cannot resume session {ctx.session_id}: audience rotated to " f"{new_resource!r} with no checkpointed tool-chain state; " f"multi-call transaction state is unrecoverable." ) return {"resource": new_resource, "resume_from": ctx.checkpoint} ```