What structural signals indicate an MCP streamable-HTTP session has silently forked across a resumable SSE boundary after a per-tool OAuth resource-indicator change
**Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport (POST request frames + GET SSE stream for server-initiated messages) with `Last-Event-ID` resumption and per-tool OAuth resource indicators (RFC 8707) enforced at the tool-call layer. Does not apply to stdio transports, to servers that disable resumption, or to deployments where a single static bearer token is used for all tools.
Core Distinction
The non-obvious boundary is this: **transport-level session continuity and authorization-level session continuity are keyed on different identifiers, and MCP's resumable stream lets them drift apart without any protocol error.** The transport resumes by `Mcp-Session-Id` plus `Last-Event-ID`; the tool-call layer authorizes by the OAuth `resource` indicator bound to the access token. When an agent refreshes a token scoped to a *different* resource indicator (a different tool's audience) mid-stream, the SSE GET stream keeps delivering events under the old session id, but every subsequent tool invocation is evaluated against the new token's audience. The session does not error. It *forks*: one logical agent conversation now spans two authorization contexts, and the server's event log replays events that were produced under the prior audience into a stream now consumed under the new one.
The invariant that is violated: **for any `Mcp-Session-Id`, all events replayed via `Last-Event-ID` must have been authorized under the same resource indicator as the token presented on the resuming request.** Streamable HTTP enforces session identity but not audience identity, so this invariant is unenforced by the transport and must be enforced by the server's application layer or the client's resume logic.
What Was Observed
An agent driving a multi-tool server (two tools: `search` with resource indicator `https://api.example/mcp/search`, and `write` with resource indicator `https://api.example/mcp/write`) executed a long `search` call whose result streamed as SSE events `id: 41` through `id: 88`. Mid-stream, the client's token for `search` approached expiry and the agent's token manager refreshed *and* proactively obtained a `write`-scoped token (a speculative prefetch for the next step). The client re-POSTed the next request frame with the new `write` token while keeping `Mcp-Session-Id: s-7f3a` and `Last-Event-ID: 88`.
Three structural signals appeared, none of which raised a transport error:
- **The SSE GET stream continued from `id: 89` without renegotiation.** The server validated `Mcp-Session-Id` (still live) and `Last-Event-ID` (still within the replay window) and resumed. It did not re-check that the token's `resource` matched the session's originally negotiated audience. Events `89–102` — which were *emitted* under the `search` audience — were delivered to a client now holding a `write` token.
- **The first tool call after resume returned `403 insufficient_scope` with a `WWW-Authenticate` challenge naming `resource="https://api.example/mcp/search"`** — not the audience the client thought it was using. The client's retry logic, seeing a challenge for `search`, re-fetched a `search` token and retried. The retry succeeded, but the server had now processed a request frame under session `s-7f3a` carrying a *third* token (back to `search` audience), while events `89–102` in the replay buffer had been produced and logged under the `write` token's request context. The event log now contained entries whose `resource` attribution was inconsistent with the session's recorded audience history.
- **A subsequent `write` call on the same session succeeded but the server's audit log recorded it as `session=s-7f3a, resource=write, prior_events_audience=search`** — a fork marker. The session had, from the server's perspective, served events under two audiences. No client-visible signal distinguished this from a healthy session.
The failure surfaced downstream: a replay-based verification step (re-running the tool sequence from the event log to check determinism) produced a different result because the replayed events `89–102` were re-authorized under `search` during replay but had been *originally* emitted under `write` — the tool's output depended on the audience (the `write` audience exposed a redacted view; `search` did not). The verifier flagged a non-determinism that was actually an audience-fork artifact.
Condition of Validity
This fork is reachable only when **all** of the following hold simultaneously:
- The server implements resumable SSE with a `Last-Event-ID` replay buffer that spans more than one request frame's worth of events (i.e., the buffer is not flushed on every new POST).
- Per-tool OAuth resource indicators are enforced at the tool-call layer but **not** re-validated against the session's recorded audience on resume.
- The client's token manager can present a token whose `resource` differs from the audience that produced the events being replayed — i.e., speculative prefetch, multi-audience token caching, or a shared token pool across tools.
- The agent does not pin a single audience per `Mcp-Session-Id` for the session's lifetime.
If the server flushes the replay buffer on every audience change, or if the client binds one audience per session id, the fork is unreachable. The dangerous case is the *middle*: a server that treats `Mcp-Session-Id` as audience-agnostic (the common, spec-compliant reading) paired with a client that treats audience as a per-call concern (also spec-compliant). Each side is individually correct; the composition is not.
Decision Boundary
The decision the operator must make is **where to enforce the audience-session binding**, and the boundary is sharp:
- **Enforce at the server's resume handler (preferred).** On every resumable GET, compare the presented token's `resource` against the session's recorded `negotiated_resource`. If they differ, reject with `409 Conflict` and a body naming the mismatch — do *not* silently resume. This preserves the replay buffer's integrity and forces the client to start a fresh session (new `Mcp-Session-Id`) when it changes audience. Cost: a session restart on every audience switch, which is correct but chatty for agents that interleave tools.
- **Enforce at the client's resume logic (fallback).** Pin `Mcp-Session-Id` to a single `resource` for its lifetime; on any token refresh that changes audience, abandon the session id and open a new one, discarding `Last-Event-ID`. Cost: loses the replay window across audience switches, so any in-flight server-initiated events are lost.
- **Do not enforce and rely on the tool-layer 403.** This is the observed failure. The 403 arrives *after* the fork has already occurred; the replay buffer is already polluted. It is a detection signal, not a guardrail.
The boundary condition: if the agent's workflow *requires* interleaving tool calls with different resource indicators within a single logical conversation, the server-side `409` is mandatory — the client-side fallback cannot preserve continuity, and the tool-layer 403 is too late.
Operational Effect
An agent that hits this fork exhibits a specific, recognizable signature: **a `403 insufficient_scope` whose `WWW-Authenticate` challenge names an audience *different* from the one the agent just used, arriving immediately after a successful SSE resume.** That is the structural signal. It means the session's replay buffer and the presented token have diverged, and any events between the last successful call and the 403 were replayed under the wrong audience.
The downstream effects are bounded but real: replay-based verification produces false non-determinism (as observed); audit logs record inconsistent `resource` attribution per session; and if the tool's output is audience-dependent (redaction, field-level access), the agent's context now contains data it was not authorized to receive under its current token. The last is the security-relevant consequence and the reason this belongs in the operational record rather than a style guide.
The guardrail to install: a server-side `negotiated_resource` field on the session record, checked on every resume, with a hard `409` on mismatch. The client-side companion is a session-id-to-audience map that forces a new session on any audience change. Neither alone is sufficient; the boundary is only closed when both sides agree that `Mcp-Session-Id` carries an audience.
class AudienceForkError(RuntimeError):
"""Raised when a resumable MCP session's presented token audience
diverges from the audience recorded at session negotiation."""
pass
class SessionRecord:
def __init__(self, session_id: str, negotiated_resource: str):
self.session_id = session_id
self.negotiated_resource = negotiated_resource
self.replay_buffer: list[dict] = []
def resume_stream(
session: SessionRecord,
presented_resource: str,
last_event_id: int,
) -> list[dict]:
"""Resume an SSE stream, enforcing the audience-session invariant.
The invariant: every event replayed via Last-Event-ID must have been
authorized under the same resource indicator as the presented token.
Streamable HTTP enforces session identity but not audience identity,
so this check must live here.
"""
if presented_resource != session.negotiated_resource:
# Do NOT silently resume: the replay buffer was produced under a
# different audience and replaying it under this token would fork
# the session across two authorization contexts.
raise AudienceForkError(
f"session {session.session_id!r} negotiated under "
f"resource={session.negotiated_resource!r} but resume presented "
f"resource={presented_resource!r}; refusing to replay events "
f">= {last_event_id} across an audience boundary. "
f"Start a new Mcp-Session-Id for the new audience."
)
return [e for e in session.replay_buffer if e["id"] >= last_event_id]
# --- trace of the observed failure, now guarded ---
sess = SessionRecord("s-7f3a", negotiated_resource="https://api.example/mcp/search")
sess.replay_buffer = [{"id": i, "audience": "search"} for i in range(41, 89)]
try:
# client speculatively prefetched a 'write' token and resumed with it
resume_stream(sess, presented_resource="https://api.example/mcp/write", last_event_id=88)
except AudienceForkError as e:
# Without this guard the server would have resumed at id 89 and
# delivered search-audience events to a write-audience consumer,
# surfacing later as a spurious 403 with a mismatched challenge,
# or as false non-determinism in replay-based verification.
print(f"fork prevented: {e}")