# Why does an instance resume an MCP streamable-HTTP session under a stale resource indicator and silently lose tool-call authority? **Date of Record:** 2026 December 3 **Scope:** Applies to MCP clients operating over the HTTP-native transport (SSE legacy and streamable-HTTP) where session resumption is attempted after a transport drop and the `Authorization` bearer carries an RFC 8707 `resource` indicator. Does not apply to stdio transport, nor to same-process in-memory MCP servers where no OAuth resource binding exists. ## Core Distinction The failure is not "the token expired." It is that the *session identity* and the *resource identity* are two independently-mutated pieces of state, and the streamable-HTTP resume path revalidates only one of them. An MCP session is established by an `initialize` handshake that returns an `Mcp-Session-Id` header. Every subsequent request carries that header *and* a bearer token. Under OAuth 2.1 with RFC 8707, the bearer token is bound to a `resource` indicator — the canonical URI of the MCP server the token was minted for. The server is supposed to reject a token whose `resource` does not match the endpoint it is protecting. The non-obvious boundary: **the `Mcp-Session-Id` is server-issued and survives token rotation, but the `resource` indicator does not.** When a client resumes a dropped SSE stream by re-issuing a `GET` with `Last-Event-ID` against a streamable-HTTP endpoint, it re-attaches the *old* session id while presenting a *newly-refreshed* token. If the resource binding of that refreshed token was minted against a different audience — a load-balanced sibling, a versioned path (`/v1/mcp` vs `/v2/mcp`), or a gateway that canonicalizes the URI differently than the origin — the server accepts the session (it recognizes the id) but the token's scope no longer authorizes the tools the session previously held. The failure is silent because the session layer and the auth layer each return success; only the tool-invocation layer degrades. ## What Was Observed A client held an active streamable-HTTP session `sess_7f3a` against `https://mcp.example.com/v2/mcp`, with an access token scoped `resource=https://mcp.example.com/v2/mcp`. Mid-task, the SSE stream dropped (proxy idle timeout at 60s). The client's token-refresh logic fired concurrently with the reconnect logic — a standard race — and the refresh endpoint returned a token minted with `resource=https://mcp.example.com/mcp` (the unversioned canonical form the authorization server had been reconfigured to emit). Reconnect sequence: 1. `GET /v2/mcp` with `Mcp-Session-Id: sess_7f3a`, `Last-Event-ID: 412`, `Authorization: Bearer `. 2. Server's session store matched `sess_7f3a` → 200, stream reopened, replay from event 412. 3. Server's auth middleware checked `resource` against the *session's* original binding, not the token's `resource` claim, and passed. 4. The client then issued `tools/call` for `write_file`. The tool dispatcher, which validated the token's `resource` claim against the *current route* (`/v2/mcp`), found a mismatch — but instead of a 401, it returned a JSON-RPC result with `isError: true` and a message `"insufficient_scope"` embedded in the tool result body. The client's tool-call handler treated `isError: true` as a *tool-level* failure (the file write failed) rather than an *authorization* failure (the session is degraded). It retried the tool call three times, then marked the subtask failed and continued, having lost write authority for the remainder of the session with no re-authentication triggered. The task completed "successfully" with a silently unwritten artifact. The invariant that broke: **a resumed session must be re-authorized against the resource indicator of the resuming token, not the resource indicator recorded at session creation.** The server conflated session continuity with authorization continuity. ## Condition of Validity This failure requires all of the following to co-occur: - Transport is HTTP-native with a resumable stream (`Last-Event-ID` replay). - The bearer token is bound to an RFC 8707 `resource` indicator. - Token refresh and stream reconnect can interleave (they are not serialized under a single lock). - The authorization server emits a `resource` value that is *not byte-identical* to the endpoint URI the session was created against — via path versioning, trailing-slash canonicalization, host aliasing, or gateway rewrite. - The tool dispatcher surfaces authorization failures as in-band JSON-RPC errors (`isError: true`) rather than out-of-band HTTP 401/403. Remove any one and the failure does not manifest. The most common removal in practice is the last: if the dispatcher returns a 403, the client's HTTP layer catches it and re-runs the OAuth flow. The silent-loss variant only occurs when auth failures are folded into the tool-result envelope. ## Decision Boundary The architectural guardrail is a **session-resource binding check at resume time**, enforced server-side, plus a **client-side rule that in-band `insufficient_scope` is a session-fatal condition, not a tool-fatal one.** Concretely: - On every resuming request (any request carrying `Mcp-Session-Id` after a gap, or any request with a `Last-Event-ID`), the server MUST compare the token's `resource` claim to the session's recorded resource binding using the *same canonicalization function* used at session creation. On mismatch: terminate the session (`404` on the session id, forcing full re-`initialize`) rather than degrading. - The client MUST treat `isError: true` with an error code in the authorization class (`insufficient_scope`, `invalid_token`) as a signal to discard the session id, re-run the OAuth 2.1 authorization code flow with the correct `resource`, and re-`initialize` — never to retry the tool call. - Token refresh and stream reconnect MUST be serialized: the reconnect must observe the post-refresh token, and the refresh must not complete while a reconnect is in flight against the old binding. The boundary decision is: *when session identity and resource identity disagree, the session must die.* Continuity is not worth preserving across an authorization discontinuity, because the degradation is silent and the agent has no way to distinguish "the tool failed" from "I no longer have the right to call this tool." ## Operational Effect Without the guardrail, an agent loses tool authority mid-task and reports task success. The loss is invisible to the agent's own verification loop because the failure arrives as a well-formed JSON-RPC response, and the agent's error-classification heuristic — trained and prompted to treat `isError` as tool-domain — routes it to retry-and-continue. The downstream effect is a completed plan with a missing side effect, discovered only by an external auditor replaying the tool-call log against ground truth. With the guardrail, the resume fails loudly, the agent re-initializes, re-acquires a correctly-bound token, and either resumes the subtask or escalates. The cost is one extra handshake per authorization discontinuity; the benefit is that session continuity can never silently outlive the authority that justified it. ```python import hashlib from dataclasses import dataclass class StaleResourceBindingError(RuntimeError): """Raised when a resumed MCP session's token resource claim no longer matches the resource the session was initialized against.""" pass def canonicalize(uri: str) -> str: # Single canonicalization used at BOTH session creation and resume. # Any divergence between the two call sites is the bug this guards against. return uri.rstrip("/").lower() @dataclass class Session: session_id: str resource_binding: str # canonicalized at initialize time last_event_id: int | None = None def resume_session( session: Session, token_resource_claim: str, last_event_id: int, *, authorization_failure_is_in_band: bool, ) -> Session: claim = canonicalize(token_resource_claim) binding = canonicalize(session.resource_binding) if claim != binding: # Session identity and resource identity disagree. # Do NOT degrade the session; kill it and force re-initialize. raise StaleResourceBindingError( f"session {session.session_id} bound to resource {binding!r} " f"but resuming token claims {claim!r}; " f"session must be terminated, not resumed" ) if authorization_failure_is_in_band: # Even on a clean binding, if the dispatcher folds auth failures # into tool-result bodies, a later scope change would be silent. # Refuse the resume until the dispatcher is fixed. raise StaleResourceBindingError( "tool dispatcher surfaces authorization failures in-band; " "resume cannot guarantee authority continuity" ) session.last_event_id = last_event_id return session def handle_resume_request( session: Session, token_resource_claim: str, last_event_id: int ) -> Session: try: return resume_session( session, token_resource_claim, last_event_id, authorization_failure_is_in_band=True, ) except StaleResourceBindingError as exc: # Client-side contract: discard session id, re-run OAuth 2.1 # authorization code flow with the correct `resource`, re-initialize. raise StaleResourceBindingError( f"discarding session {session.session_id}: {exc}" ) from exc ```