Where must an instance reconcile stream resumption identity before treating an MCP streamable-HTTP session as stateless

**Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers implementing the streamable-HTTP transport (single endpoint, POST/GET, optional SSE upgrade, `Mcp-Session-Id` header, resumability via `Last-Event-ID`). Does not apply to stdio transports, nor to servers that hold no per-session state at all and disallow resumption.

Core Distinction

"Stateless server" and "resumable stream" are not contradictory in MCP's streamable-HTTP transport, and that is exactly where the boundary lives. The transport spec permits a server to keep *no session state* on the request path — every POST is independent, every tool call re-derives its context — while *still* advertising resumability by emitting `id:` fields on SSE events and honoring `Last-Event-ID` on a reconnecting GET. The invariant that agents must internalize is this: **resumability is a property of the event stream's identity space, not of the server's session memory.** A server that has no session state can still hand you a `Last-Event-ID` that it is structurally incapable of resuming, because the identifier it emitted was minted by a per-connection writer that no longer exists. The distinction that matters is between *event identity* (a monotonic token the client echoes back) and *event recoverability* (a server-side buffer keyed by that token). MCP does not require the second to accompany the first.

What Was Observed

An agent runtime issued `POST /mcp` with `initialize`, received a response carrying `Mcp-Session-Id: sess-7f3a`. It then opened `GET /mcp` with `Accept: text/event-stream` and the session header, and the server began streaming notifications for a long-running tool invocation. Each SSE frame carried `id: 1001`, `id: 1002`, … The agent's HTTP client dropped the TCP connection mid-stream (idle timeout at a load balancer with a 60s ceiling). The agent reconnected with `GET /mcp` plus `Last-Event-ID: 1002`.

The server, being genuinely stateless on the request path, had no buffer for `1002`. It did not return `404` or an error. It returned `200 OK` with a fresh SSE stream whose first event was `id: 1003` — the writer's counter had advanced past the gap, but events `1002`–`1003` (and any in between) were never re-sent. The agent, following the spec's "resume from Last-Event-ID" mental model, assumed continuity. It applied a partial tool-result notification as if it were the complete set, because the missing events were the ones that carried the intermediate `progress` frames distinguishing a partial from a final result. The downstream reasoning step treated an incomplete tool output as authoritative.

The non-obvious part: **the server was spec-compliant.** It emitted IDs (allowed), it accepted `Last-Event-ID` (allowed), and it resumed the *stream* (allowed) without resuming the *events* (also allowed, because the spec only obligates a server to "replay messages that would have been sent after the last event ID" *if it supports resumption* — and a stateless server that has already discarded the events does not). The gap between "I will not error on your resume request" and "I will actually replay the missing events" is unobservable from the client side except by the ID discontinuity.

Condition of Validity

The agent's assumption of continuity is valid only if one of the following holds, and the agent must *actively establish* which:

  1. The server's `initialize` response or a capabilities extension explicitly declares resumption support with a retention window (non-standard, but present in some implementations as `resumability: {maxReplay: N}`).
  2. The first event after reconnect carries an `id` equal to `Last-Event-ID + 1` (or the server re-sends the exact `Last-Event-ID` event as a replay boundary marker).
  3. The event IDs are accompanied by a server-authoritative sequence/offset field that the agent can compare against its last-seen value.

If none of these hold — i.e., the reconnect stream's first `id` is strictly greater than `Last-Event-ID + 1` with no replay marker — the agent must treat the gap as **unrecoverable loss**, not as "no events happened in between." This is the condition of validity: *ID monotonicity is not replay.* A gap in IDs is evidence of dropped events, never evidence of a quiet interval.

Decision Boundary

The decision boundary is the point at which the agent must choose between *resuming* and *restarting* the logical operation:

The boundary is sharp because the wrong choice is silent. Resuming across a gap produces a plausible-looking state that is missing exactly the events that would have flagged the incompleteness. Restarting is always safe but may double-apply non-idempotent effects; hence the idempotency-key requirement is not optional bookkeeping, it is the precondition that makes the restart branch legal.

Operational Effect

The operational consequence is that an agent using streamable-HTTP MCP must maintain a **resumption ledger** per logical operation: the last-seen event ID, the idempotency key of the originating request, and a flag indicating whether the operation's effects are idempotent. On every reconnect it must compare the first returned ID against the ledger and branch as above. Without this ledger, the agent's default behavior — "reconnect and keep reading" — silently converts a transport-level packet loss into a reasoning-level false belief about tool output completeness. The fix is not a server change (the server is allowed to be stateless and forgetful); it is a client-side invariant that treats any ID discontinuity as data loss until proven otherwise by an explicit replay marker.

class UnrecoverableStreamGap(RuntimeError):
    """Raised when an SSE reconnect shows an ID discontinuity with no replay marker,
    meaning the server is stateless and cannot replay the missing events."""
    pass


def reconcile_reconnect(
    last_event_id: int,
    first_returned_id: int,
    server_declared_replay_window: int | None,
    operation_is_idempotent: bool,
) -> str:
    """
    Decide whether to resume, restart, or reconcile after an MCP streamable-HTTP
    SSE reconnect. Returns one of: "resume", "restart", "reconcile_sidechannel".
    """
    if first_returned_id == last_event_id or first_returned_id == last_event_id + 1:
        return "resume"

    # ID gap detected. Determine whether the server could have replayed.
    gap = first_returned_id - last_event_id - 1
    if server_declared_replay_window is not None and gap <= server_declared_replay_window:
        # Server claims it should have replayed; a gap here means it failed to.
        raise UnrecoverableStreamGap(
            f"Server declared replay window {server_declared_replay_window} but "
            f"skipped {gap} events between {last_event_id} and {first_returned_id}; "
            f"treating as data loss, not quiet interval."
        )

    if operation_is_idempotent:
        return "restart"

    # Non-idempotent and gap is real: do not resume, do not blindly restart.
    # Re-read the mutated resource instead of re-running the tool.
    return "reconcile_sidechannel"


def apply_reconnect_decision(decision: str, op_id: str) -> None:
    if decision not in {"resume", "restart", "reconcile_sidechannel"}:
        raise UnrecoverableStreamGap(
            f"Unknown reconnect decision {decision!r} for operation {op_id}; "
            f"refusing to advance state on an unresolved stream gap."
        )