Where must an instance reconcile the SSE resume cursor against the OAuth 2.1 resource-metadata `resource` binding when an MCP server migrates a session from legacy SSE to streamable HTTP mid-stream

**Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients (agent runtimes) that hold a live legacy-SSE session carrying an `Last-Event-ID` resume cursor and are redirected, via 307/308 or a protocol-version bump, into a streamable-HTTP endpoint whose OAuth 2.1 protected-resource metadata declares a `resource` identifier that differs from the SSE origin. Does *not* cover pure streamable-HTTP sessions with no prior SSE state, nor static bearer-token deployments with no resource-metadata document.

Core Distinction

The non-obvious failure is not "the token is rejected" or "the stream breaks." It is that **the resume cursor and the OAuth resource binding are validated against two different authorities that the client has silently been told to treat as the same session.** Legacy SSE carries resumption state in `Last-Event-ID` (an opaque server-issued string) and authenticates against the token audience of the *original* SSE endpoint. Streamable HTTP carries resumption state in the same header but authenticates against the `resource` field of the RFC 9728 protected-resource-metadata document fetched from `/.well-known/oauth-protected-resource`. During a mid-stream migration these two can diverge: the cursor is still valid for the SSE event log, but the token's audience no longer matches the newly declared `resource`, and the server's 401 challenge now points at a *different* authorization server than the one that minted the live token.

The invariant that must hold is: **`Last-Event-ID` is only replayable against the resource identifier under which the event was originally emitted.** If the streamable-HTTP endpoint's metadata declares `resource = https://api.example.com/mcp` while the SSE stream was served under `https://sse.example.com/stream`, the cursor is orphaned even though it is byte-identical and unexpired.

What Was Observed

A client agent held an SSE session at `https://sse.example.com/stream` with an active access token minted by `https://auth.example.com`, audience `https://sse.example.com`. The server operator migrated the deployment: `sse.example.com` began returning `307 Temporary Redirect` to `https://api.example.com/mcp`, and published RFC 9728 metadata at `https://api.example.com/.well-known/oauth-protected-resource` declaring:

{
  "resource": "https://api.example.com/mcp",
  "authorization_servers": ["https://auth2.example.com"],
  "bearer_methods_supported": ["header"]
}

The client, on reconnect, sent `GET https://sse.example.com/stream` with `Last-Event-ID: evt_8841` and `Authorization: Bearer <token-aud-sse.example.com>`. The redirect was followed (many HTTP stacks follow 307 automatically, preserving method and headers). The streamable-HTTP endpoint received the resume request, looked up `evt_8841` in its event store, found it, and — critically — **the event store was shared between the two transports during the migration window.** The event was replayed. The client appended it to its transcript a second time.

The failure trace in order:

  1. Client follows 307, preserving `Authorization` and `Last-Event-ID`.
  2. Streamable-HTTP endpoint validates the token. The token's `aud` is `https://sse.example.com`, but the endpoint's declared `resource` is `https://api.example.com/mcp`. A strict RFC 8707 / RFC 9728 resource-indicator check should reject this; a lenient one (audience check against a list including the legacy origin during migration) accepts it.
  3. Event store lookup for `evt_8841` succeeds because the store was dual-homed.
  4. Event is replayed. The client has no way to know the replay crossed a transport boundary and a resource-identity boundary simultaneously.
  5. On the *next* reconnect, the client's token has expired, and the new 401 challenge points at `https://auth2.example.com` — not the original AS. If the client naively re-runs the token flow against the cached AS from the SSE session, it gets a token with the wrong audience and a 403 loop.

The observable symptom was **duplicate tool-call dispatch**: the replayed event was a `tools/call` result, and the client re-applied it to its working state, producing a doubled side effect (a record created twice). The root cause was not the duplicate replay per se — it was that the client treated a cross-resource resume as a same-resource resume.

Condition of Validity

The `Last-Event-ID` resume is valid if and only if all three hold:

If any of these is violated, the cursor must be treated as *foreign* and the resume must degrade to a cold-start replay from the client's last committed checkpoint, not from the server's event log.

The subtle part: the server cannot reliably enforce this alone, because the 307 redirect happens at the HTTP layer before the streamable-HTTP handler sees the request, and the handler sees a well-formed token and a well-formed cursor. The client must enforce it, because only the client knows which resource identifier the cursor was minted under.

Decision Boundary

The decision the client must make on every resume attempt:

if (resume_endpoint.resource_id != cursor.origin_resource_id):
    if (token.aud contains resume_endpoint.resource_id):
        # new resource, valid token — but cursor is foreign
        discard cursor; cold-start from client checkpoint
    else:
        # new resource, invalid token — re-authorize against
        # resume_endpoint.authorization_servers, then cold-start
else:
    # same resource — cursor is replayable
    resume with Last-Event-ID

The failure mode this prevents is the one observed: a client that checks only `token.aud` (which the lenient migration server accepted) and not `cursor.origin_resource_id` will replay across the boundary. The failure mode it *introduces* if applied too strictly is unnecessary cold-starts during legitimate same-resource migrations (e.g., a server that moves from `sse.example.com` to `api.example.com` but keeps `resource = https://sse.example.com` in its metadata to preserve session continuity — a valid and common transitional pattern). The boundary is therefore: **compare the declared `resource`, not the hostname.** Hostname changes are not resource changes; `resource`-field changes are.

Operational Effect

After adopting the `cursor.origin_resource_id` check, the client's behavior on the observed scenario became:

The cost is one extra metadata fetch and one cold-start per migration event. The benefit is bounded: no duplicate tool dispatch, no cross-AS token confusion, and a deterministic resume-or-cold-start decision that does not depend on the server's leniency during the migration window.

The general invariant, stated for reuse: **a resumption cursor is a capability scoped to a resource identifier; it must never be presented to an endpoint whose declared resource identifier differs from the one under which it was issued, regardless of whether the endpoint accepts it.** Servers accept foreign cursors during migrations because their event stores are dual-homed; clients must refuse them because their transcripts are not.

class ForeignResumeCursorError(RuntimeError):
    """Raised when a Last-Event-ID cursor is presented to an endpoint
    whose OAuth 2.1 protected-resource `resource` identifier differs
    from the one under which the cursor was issued."""
    pass


def resume_stream(
    cursor_id: str,
    cursor_origin_resource: str,
    resume_endpoint_resource: str,
    token_audiences: list[str],
    client_checkpoint: dict,
) -> dict:
    """Decide whether to resume from server event log or cold-start.

    Returns a dict describing the resume plan. Raises
    ForeignResumeCursorError if the cursor crosses a resource boundary
    and the caller has not opted into a cold-start fallback.
    """
    if cursor_origin_resource != resume_endpoint_resource:
        # Cursor is foreign to this endpoint. Do NOT present it.
        if resume_endpoint_resource not in token_audiences:
            # Token also invalid for the new resource; caller must
            # re-authorize against the new AS before retrying.
            raise ForeignResumeCursorError(
                f"cursor {cursor_id!r} issued under {cursor_origin_resource!r} "
                f"cannot be resumed at {resume_endpoint_resource!r}; "
                f"token audiences {token_audiences!r} do not cover the new "
                f"resource — re-authorize against the endpoint's "
                f"authorization_servers before cold-starting"
            )
        # Token valid, cursor foreign: cold-start from client checkpoint.
        return {
            "action": "cold_start",
            "reason": "foreign_cursor",
            "from_checkpoint": client_checkpoint,
            "discarded_cursor": cursor_id,
        }

    # Same resource: cursor is replayable.
    return {
        "action": "resume",
        "last_event_id": cursor_id,
        "resource": resume_endpoint_resource,
    }