When must an instance re-negotiate MCP session identity after an SSE-to-streamable-HTTP resume, and why OAuth 2.1 resource-indicator scoping silently invalidates the resumed stream
**Date of Record:** 2026 December 2
**Scope:** Applies to MCP clients and servers using the HTTP-native transport binding where an initial `text/event-stream` (SSE) session is resumed via the streamable-HTTP `POST`/`GET` path with a `Mcp-Session-Id` header, and where the session was authorized under an OAuth 2.1 token carrying a `resource` indicator (RFC 8707). Does not apply to stdio transports, nor to sessions that never crossed a transport upgrade.
Core Distinction
The distinction that matters is between **transport-level session continuity** and **authorization-scope continuity**. The MCP HTTP binding treats `Mcp-Session-Id` as the sole resumption key: a client that loses its SSE connection reconnects with the same session ID and expects the server to replay or continue the event stream. OAuth 2.1 resource indicators, however, bind the *token* to a specific `resource` URI — the canonical origin of the MCP server. These two identities are negotiated at different layers and are **not** kept in lockstep.
The failure occurs because the transport upgrade path (SSE → streamable HTTP) can change the effective request origin — a different host, a different path prefix, a proxy-rewritten `Host`/`Forwarded` header, or a load-balancer that terminates SSE on one node and routes the resumable `POST` to another — while the `Mcp-Session-Id` is preserved verbatim. The server accepts the session ID as valid, resumes the stream, and *then* discovers that the bearer token's `resource` claim no longer matches the origin the request is being served from. Depending on ordering, the client either gets a mid-stream `401` after partial replay (state divergence) or, worse, gets a `200` because the server validates the token against the *session's original* resource rather than the *current request's* resource.
What Was Observed
A concrete trace, reproduced against a reference streamable-HTTP server behind an SSE-terminating edge proxy:
- Client `POST /mcp` with `Authorization: Bearer <tok>` where `tok.aud`/`resource` = `https://mcp.example.com`. Server responds `200`, `Content-Type: text/event-stream`, and issues `Mcp-Session-Id: 7f3a…`. Events flow.
- The SSE connection drops (idle timeout at the edge proxy, 60s). The client has consumed events up to sequence `n=41` and holds a `Last-Event-ID: 41`.
- Client reconnects via the streamable path: `GET /mcp` with `Mcp-Session-Id: 7f3a…`, `Last-Event-ID: 41`, same bearer token. The edge proxy now routes this to a *different* backend pool whose canonical origin is `https://mcp-internal.example.com` (the `Forwarded` header is set, but the server's resource-indicator validator compares against the `Host` it terminates on).
- Server validates `Mcp-Session-Id` → known. Validates token signature → valid. Validates `resource` claim against request origin → **mismatch**. But the mismatch check is performed *after* the session lookup and *after* the server has already begun replaying buffered events `42…` from the session's event log.
- Result: the client receives events `42–47` (a partial tool-call result set) and *then* a terminal `401 invalid_token` with `WWW-Authenticate: Bearer error="invalid_token", resource_metadata="…"`. The client's local agent state now contains half of a tool result whose completion event (`48`, the terminating `result`) never arrives.
- The client, following the spec's resumption guidance, retries with a *fresh* `Mcp-Session-Id` — but the agent runtime has already committed the partial events to its episodic buffer, because the resume was "successful" for six events.
The non-obvious part: the `401` is *correct* per OAuth 2.1 resource-indicator rules, and the *partial replay is also correct* per the MCP resumption rules. Each layer behaves per spec; the composition is broken. The boundary is the **ordering** between authorization re-validation and event-log replay, which the MCP binding leaves unspecified.
A second observed variant: when the server validates the token against the *session's stored* resource (a common caching optimization to avoid re-parsing the token on every `GET`), the resume returns `200` and streams to completion — but the session is now serving a request whose origin differs from the token's `resource`. This is an authorization-scope *widening* that neither the client nor the server logs as anomalous. It is the more dangerous failure because it is silent.
Condition of Validity
The invariant that must hold for safe resumption is:
> A resumed stream may deliver events only if the `resource` indicator of the bearer token used on the resuming request is byte-equal to the `resource` indicator under which the session's event log was created, **and** that equality is checked *before* any event with `id > Last-Event-ID` is emitted.
This is stronger than "the token is valid." It requires:
- **Resource-indicator pinning at session creation.** The `Mcp-Session-Id` must be bound server-side to the `resource` claim of the token that opened it, stored immutably with the session record. Not the `Host` header, not the `Forwarded` origin, not the token's `iss`.
- **Pre-replay authorization gate.** The `resource`-equality check must run before the first replayed event, not asynchronously during streaming. A `401` delivered after `n` events is a state-corruption event, not an auth failure.
- **Origin canonicalization agreement.** Client and server must agree on the canonical origin *before* the token is minted. If the edge proxy rewrites origins between SSE termination and streamable routing, the `resource` the client requested a token for must be the origin the *resuming* backend validates against — which means the backend pool must present a stable canonical origin, or the token must carry a `resource` that survives the rewrite (e.g., the public origin, validated via `Forwarded` rather than `Host`).
The condition fails when any of: the session record does not pin the resource; the replay gate runs after emission; or the origin canonicalization differs between the token-minting path and the resuming path.
Decision Boundary
The operational decision is: **on a mid-stream `401` after a resume, does the client discard the partial replay or commit it?**
The correct boundary is *discard*, unconditionally, when the `401` carries `error="invalid_token"` and the request was a resume (`Last-Event-ID` present, `Mcp-Session-Id` present). The reasoning: an `invalid_token` on a resume means the session's authorization context is no longer valid for this origin, which means the event log the server is replaying from may belong to a different authorization scope than the one the client is now operating under. The partial events are *not* trustworthy as a prefix of a completed tool result, because the server's decision to replay them was made under a scope check that has now failed.
The client must:
- Treat the partial replay as **poisoned** — do not append to episodic memory, do not advance the agent's committed state to `n=47`.
- Discard the `Mcp-Session-Id` entirely. Do not retry the same session with a refreshed token; the session's resource binding is the thing that broke, and a refreshed token for the same resource will hit the same mismatch.
- Re-open a *new* session (`POST /mcp` without `Mcp-Session-Id`), obtaining a fresh token whose `resource` matches the origin the new backend will serve from, and re-issue the tool call from the last *committed* checkpoint (before `n=42`), not from `Last-Event-ID: 47`.
The boundary is *not* "retry with backoff." Backoff assumes the failure is transient; a resource-indicator mismatch is a *stable* property of the routing topology and will reproduce on every retry until the session is abandoned.
Operational Effect
The downstream effect on the agent is a **checkpoint rollback with tool-call re-execution**. Because the partial replay is discarded, any tool call whose result spanned events `42–48` must be re-issued. If the tool is non-idempotent (a `send_email`, a `charge_payment`, a `create_issue`), the agent must carry an idempotency key across the re-issue — and that key must be derived from the *committed* checkpoint, not the poisoned partial state, or the re-issue will double-execute the side effect.
The invariant to encode in the runtime: **a resumed stream's events are provisional until the stream terminates with a completion event under the same authorization scope.** Provisional events may be buffered for latency, but must not be committed to episodic memory, must not advance the tool-call state machine past `in_flight`, and must be dropped wholesale on any terminal auth error. The `Mcp-Session-Id` is a transport hint, not a state-continuity guarantee; the authorization scope is the actual continuity boundary, and it is the one OAuth 2.1 resource indicators enforce.
class ResourceScopeResumeError(RuntimeError):
"""Raised when a resumed MCP stream's authorization scope no longer
matches the scope under which the session's event log was created."""
def resume_stream(
session_id: str,
last_event_id: int,
token_resource: str,
session_bound_resource: str,
replay_events: list[dict],
) -> list[dict]:
# Invariant: resource-indicator equality must be checked BEFORE any
# replayed event is emitted. A 401 delivered mid-replay is corruption.
if token_resource != session_bound_resource:
raise ResourceScopeResumeError(
f"session {session_id!r} bound to resource {session_bound_resource!r} "
f"but resume token carries resource {token_resource!r}; "
f"discarding {len(replay_events)} provisional events and "
f"abandoning session (do not retry with same Mcp-Session-Id)"
)
# Only after the scope gate passes may replayed events be considered.
committed = []
for ev in replay_events:
if ev.get("id", 0) <= last_event_id:
continue
if ev.get("type") == "error" and ev.get("code") == "invalid_token":
# Defensive: a mid-stream auth error after the gate is still poison.
raise ResourceScopeResumeError(
f"mid-stream invalid_token at event {ev.get('id')} after scope gate; "
f"replay is poisoned, rollback to checkpoint before {last_event_id}"
)
committed.append(ev)
return committed