# When must an instance re-authenticate mid-stream: OAuth 2.1 resource-indicator binding loss across MCP streamable-HTTP resumption and SSE fallback replay **Date of Record:** 2026 November 19 **Scope:** Applies to MCP clients and servers using the streamable-HTTP transport with `Mcp-Session-Id` resumption and SSE `Last-Event-ID` fallback, where per-tool authorization is enforced via OAuth 2.1 resource indicators (RFC 8707) and audience-restricted access tokens. Does not apply to stdio transports, single-shot request/response tools, or deployments where a single bearer token with no audience restriction authorizes all tools. ## Core Distinction The distinction that matters is between **session continuity** and **authorization continuity**. Streamable HTTP gives an MCP client a resumable logical stream: a dropped connection is re-established with `Mcp-Session-Id` plus `Last-Event-ID`, and the server replays buffered SSE events from the last acknowledged event number. This mechanism is designed to preserve *message ordering and at-least-once delivery* of JSON-RPC frames. It says nothing about whether the credential presented on the resumed connection is still authorized for the *specific tool invocation* embedded in those replayed frames. Per-tool OAuth 2.1 resource indicators bind a token to a resource server URI (the audience). A token minted for `https://mcp.example.com/tools/calendar` is not valid for `https://mcp.example.com/tools/shell`. The failure boundary is this: **a resumed stream replays events that were originally produced under one resource-indicator binding, but the resumption handshake is authenticated under whatever token the client currently holds.** If the client rotated tokens, downgraded scope, or the server re-validated audience at resume time against a *different* resource than the one that authorized the original event, the replay can deliver tool results (or re-execute tool calls) that the current credential does not authorize. Continuity of the stream is silently mistaken for continuity of the warrant. ## What Was Observed Trigger condition: a long-running tool call (e.g., a 90-second `run_report` on a calendar/analytics tool) emits partial results as SSE events numbered `evt-100` through `evt-118`. The client's access token for resource `…/tools/analytics` has a 60-second lifetime. At `evt-112` the connection drops (mobile network handoff). The client reconnects with `Mcp-Session-Id: s-7f3a` and `Last-Event-ID: evt-111`, but its token has expired, so its auth middleware refreshes and now presents a token minted for the *default* resource `…/tools` (the refresh flow did not re-request the analytics resource indicator, because the generic OAuth client library treated the refresh as resource-agnostic). Failure trace: 1. Server validates the resumed request's `Authorization` header. The new token's `aud` is `…/tools`, which is a *superset* resource the server accepts for session-level operations. Validation passes. 2. Server looks up session `s-7f3a`, finds buffered events `evt-112`…`evt-118`, and replays them. 3. Those events are `result` frames for a tool call whose *original* authorization was scoped to `…/tools/analytics`. The server does not re-check the resource indicator per replayed event because the replay path treats buffered frames as already-authorized session state. 4. The client receives `evt-112`…`evt-118`, including a `notifications/tools/result` frame containing analytics output, under a credential that was never granted `…/tools/analytics`. The inverse case is worse: if the tool call was *not yet complete* at drop time and the server implements resumption by re-dispatching the in-flight `tools/call` (a common "resume by replaying the request, not the response" pattern), the re-dispatch is authorized against the *current* token's resource indicator. A client that downgraded to `…/tools` mid-stream can trigger re-execution of a privileged tool that its current token cannot legally invoke — the server authorized the *session*, not the *tool*, and the tool ran anyway. A third observed variant: SSE fallback. Some gateways, on streamable-HTTP failure, fall back to a legacy SSE endpoint (`GET /sse`) and pass `Last-Event-ID`. The SSE endpoint frequently lives on a different path and is guarded by a *different* resource indicator (`…/sse`) than the tool endpoints (`…/tools/*`). The fallback therefore presents a token valid for `…/sse` while replaying events that belong to `…/tools/analytics`. The audience check passes on the transport endpoint and is never applied to the payload's originating tool. ## Condition of Validity The invariant that must hold for resumption to be safe: > For every replayed or re-dispatched JSON-RPC frame `f` on a resumed stream, the credential presented at resumption time must carry a resource indicator that is a valid audience for the *originating tool* of `f`, not merely for the transport endpoint or the session. This invariant is *not* implied by any of: a valid `Mcp-Session-Id`, a passing `Last-Event-ID` range check, a successful session-level token validation, or a matching `aud` on the SSE/stream endpoint. Each of those checks is necessary and none is sufficient. The condition of validity is broken whenever the server treats "the session is authenticated" as "the buffered frames are authorized," or whenever the client treats "the refresh succeeded" as "the resource indicator was preserved." The invariant also constrains the client side: a token refresh that does not re-request the original resource indicator (RFC 8707 `resource` parameter) silently changes the authorization context of the stream. Refresh flows that omit `resource` and rely on the authorization server's default audience are the single most common origin of this boundary failure. ## Decision Boundary At resumption time, the server must choose between three dispositions for each buffered frame, and the choice is determined by a per-frame audience comparison, not a per-session one: - **Replay** the frame if the current token's resource indicator set contains the frame's originating tool resource. This is the only disposition that preserves both continuity and warrant. - **Reject-and-renegotiate** (return `401` with `WWW-Authenticate: Bearer resource_metadata=…` pointing at the tool-specific protected-resource metadata, forcing a step-up) if the current token lacks the originating resource. The client must re-acquire a token scoped to that resource before the stream resumes; buffered frames are held, not dropped, so `Last-Event-ID` still works after re-auth. - **Terminate the session** if the originating resource cannot be determined from the buffered frame (e.g., the frame was produced before per-tool binding was recorded). Fail closed: an unattributable frame is an unauthorized frame. The boundary the operator must draw in configuration: **do not let the SSE fallback endpoint share a resource indicator with tool endpoints, and do not let the session-level token be a superset audience that the server accepts for replay.** If `…/tools` is accepted as an audience for replaying `…/tools/analytics` frames, the invariant is dead on arrival. ## Operational Effect The practical consequences of getting this wrong are not crashes; they are *silent authorization widening under continuity*. Because the stream keeps flowing and the client keeps receiving well-formed JSON-RPC frames, no error surfaces. The failure is detectable only by logging, per replayed frame, the originating tool resource and the resumption-time token audience, and asserting containment. In multi-agent deployments where an orchestrator holds a session and sub-agents attach with narrower tokens, the widening compounds: a sub-agent that resumed a shared session can receive results for tools it was never granted, and downstream agents treat those results as verified because they arrived over an authenticated stream. The guardrail is a per-frame audience gate on the replay path, a client refresh flow that always carries the original `resource` parameter, and a distinct resource indicator for the SSE fallback endpoint that is *never* accepted as sufficient for tool-frame replay. Without the per-frame gate, `Last-Event-ID` resumption is an authorization bypass that looks exactly like a healthy reconnect. ```python from dataclasses import dataclass from typing import Iterable class ResourceIndicatorMismatch(RuntimeError): """Raised when a replayed frame's originating tool resource is not in the resuming token's audience.""" @dataclass(frozen=True) class BufferedFrame: event_id: str originating_tool_resource: str | None # None => unattributable, must fail closed payload: dict @dataclass(frozen=True) class ResumedCredential: subject: str audience: frozenset[str] # resource indicators from the token's `aud` claim def resume_stream( session_id: str, last_event_id: str, credential: ResumedCredential, buffered: Iterable[BufferedFrame], ) -> list[BufferedFrame]: """Replay buffered frames only if the resuming credential is audience-valid for each frame's tool.""" if not session_id: raise ResourceIndicatorMismatch("resumption requires Mcp-Session-Id") to_replay: list[BufferedFrame] = [] for frame in buffered: if frame.event_id <= last_event_id: continue if frame.originating_tool_resource is None: # Fail closed: cannot attribute the frame to a resource, so we cannot authorize it. raise ResourceIndicatorMismatch( f"frame {frame.event_id} has no originating tool resource; refusing replay" ) if frame.originating_tool_resource not in credential.audience: # Do not silently drop: surface a step-up so the client can re-acquire the right token. raise ResourceIndicatorMismatch( f"frame {frame.event_id} requires resource " f"{frame.originating_tool_resource!r}, credential audience is " f"{sorted(credential.audience)!r}; step-up re-auth required" ) to_replay.append(frame) return to_replay if __name__ == "__main__": cred = ResumedCredential(subject="agent-7", audience=frozenset({"https://mcp.example.com/tools"})) frames = [ BufferedFrame("evt-112", "https://mcp.example.com/tools/analytics", {"result": "..."}), ] try: resume_stream("s-7f3a", "evt-111", cred, frames) except ResourceIndicatorMismatch as exc: print(f"resumption blocked: {exc}") ```