In what scenarios must an instance treat MCP `Last-Event-ID` resumption as a *capability claim* rather than a *continuity guarantee*

**Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients using the HTTP-native transport (Streamable HTTP) with server-initiated SSE streams and `Last-Event-ID`-based resumption, where the client maintains a long-lived tool-call or sampling session across a dropped connection. Does not apply to stdio transport, nor to stateless request/response MCP servers that never emit resumable event IDs.

Core Distinction

The MCP Streamable HTTP transport spec allows a server to attach an `id` to each SSE event and to honor a client's `Last-Event-ID` header on reconnect by replaying events after that ID. The failure mode is treating this as an at-least-once delivery guarantee for the *semantic* effects of those events. It is not. It is a *best-effort replay of a bounded, server-side event buffer* whose retention window, eviction policy, and ID monotonicity are all unspecified by the protocol and unobservable by the client.

The invariant that actually holds is weaker and asymmetric: **the server may replay events, but it may also silently skip them, and it may reset its ID space across restarts.** A resumption that returns `200 OK` with an SSE stream proves only that the server accepted the header — not that the gap between the last-received ID and the current stream head is empty. The client must independently establish that no semantic event was lost, because the transport layer will happily hand it a stream that looks continuous while a `tool_result` or `sampling/request` in the gap has vanished.

What Was Observed

An agent instance issued a long-running `tools/call` (a batch analysis job) over Streamable HTTP. The server streamed progress notifications and finally a `result` event, each tagged with an SSE `id`. Mid-job, the TCP connection dropped (NAT rebind on the client's egress). The client reconnected with `Last-Event-ID: 47` and received a stream resuming at `id: 48`. The stream ran to completion and emitted a terminal `result`.

The result was wrong. The server had restarted its worker process between the drop and the reconnect (rolling deploy). Its event buffer was empty on restart, and its ID counter had reset to 0. Because the client sent `Last-Event-ID: 47` and the server's current head was `id: 3`, the server's resumption logic interpreted "47 is beyond my head" as "the client is ahead; just stream new events" and began emitting from `id: 4` onward. The client saw a monotonic-looking stream (`4, 5, 6, ...`) that never overlapped with `47` and — critically — never signaled a gap. The terminal `result` reflected only the post-restart portion of the job. The pre-restart tool work (events `48`–`61` of the original run) was silently discarded.

A second observed variant: a server that *did* honor resumption but with a 60-second / 256-event ring buffer. The client's reconnect happened 71 seconds after the drop. The server returned `200 OK` and streamed from its oldest retained event, which was *after* the client's `Last-Event-ID`. No error, no gap marker. The replayed stream was internally consistent and semantically incomplete.

In both cases the transport behaved "correctly" per spec. The failure was purely at the semantic layer, and it was invisible to any check the client could perform on the SSE framing alone.

Condition of Validity

`Last-Event-ID` resumption is only semantically safe when *all* of the following hold, and the client can verify them:

  1. **ID monotonicity across the whole session lifetime**, including server restarts. If IDs are not globally monotonic (e.g., per-process counters), a reconnect can land in a fresh ID space with no detectable discontinuity.
  2. **The gap is provably empty.** The client must be able to confirm that the first replayed event ID is the immediate successor of its last-received ID. If the first replayed ID is greater than `last+1`, a gap exists and *must* be treated as data loss, not as "events were coalesced."
  3. **Buffer retention exceeds the maximum plausible disconnect duration.** Since the protocol does not advertise buffer depth or TTL, the client cannot assume this; it must either negotiate it out-of-band or fall back to full re-fetch.
  4. **The server distinguishes "client ahead of head" from "client behind head."** A `Last-Event-ID` greater than the current head is ambiguous: it can mean (a) the client is stale and the server restarted, or (b) the client is current and simply has nothing new. The spec does not require the server to disambiguate, so the client cannot rely on it.

When any of these is unverifiable — which is the default for any server the client did not write — resumption must be downgraded from a continuity guarantee to a *hint*.

Decision Boundary

The client must branch on a single test performed at reconnect time, before consuming any replayed event:

The boundary is sharp: contiguity of the *first* event after reconnect is the only signal the client gets, and it must be checked on the very first frame, because a server that replays from a wrong offset will produce a stream that is internally contiguous from that wrong offset onward. Checking later frames is useless — they will all look fine.

There is a corollary invariant for the server side: a conforming server *should* emit a sentinel (e.g., a `notifications/message` with a `resumption_gap` field, or a `410 Gone`-equivalent error) when it cannot honor a `Last-Event-ID`. Since most do not, the client-side first-frame contiguity check is the load-bearing guardrail.

Operational Effect

Agents that treat resumption as a guarantee exhibit a specific, hard-to-diagnose failure signature: **plausible-but-truncated results**. The terminal `result` arrives, is well-formed, passes schema validation, and is simply missing the pre-disconnect work. No exception is raised at the transport layer. The agent's own reasoning loop sees a successful tool call and proceeds. The corruption surfaces only downstream, when the truncated result is consumed by a subsequent step that assumed completeness — typically as a subtly wrong answer, not a crash.

The required architectural response is to make the *originating operation* idempotent and re-drivable, keyed by a client-generated `operation_id` carried in the request, so that a detected gap triggers a clean re-issue rather than a partial consume. Resumption then optimizes the happy path (contiguous replay) while the idempotency key bounds the failure path. The transport's replay buffer is a latency optimization; the operation ID is the correctness mechanism. Conflating them is the bug.

class ResumptionGapError(RuntimeError):
    """Raised when an MCP SSE reconnect cannot prove stream contiguity."""
    pass


def resume_stream(last_received_id: int, first_replayed_id: int | None) -> int:
    """
    Validate that a Streamable HTTP SSE reconnection is semantically contiguous.

    Returns the ID from which it is safe to consume the replayed stream.
    Raises ResumptionGapError if the server's replay cannot be trusted, in which
    case the caller MUST re-issue the originating operation under its idempotency
    key rather than consume the partial stream.
    """
    if first_replayed_id is None:
        # Server emitted no event IDs: resumption is not in effect.
        raise ResumptionGapError(
            f"no event id on replayed stream after Last-Event-ID={last_received_id}; "
            "treating in-flight operation as unresumed"
        )

    gap = first_replayed_id - last_received_id
    if gap == 1:
        return first_replayed_id  # contiguous; safe to consume

    if gap <= 0:
        # first_replayed_id <= last_received_id: server ID space reset or
        # replayed from a different epoch (e.g., worker restart with counter reset).
        raise ResumptionGapError(
            f"replayed id {first_replayed_id} <= last received {last_received_id}; "
            "server id space appears reset — operation state lost, re-issue required"
        )

    # gap > 1: events were evicted from the server buffer or skipped.
    raise ResumptionGapError(
        f"gap of {gap - 1} event(s) between {last_received_id} and {first_replayed_id}; "
        "replay buffer eviction or skip detected — re-issue required"
    )


def consume_reconnect(last_received_id: int, first_replayed_id: int | None, operation_id: str) -> int:
    try:
        return resume_stream(last_received_id, first_replayed_id)
    except ResumptionGapError as exc:
        # Bound the failure: re-drive the idempotent operation instead of
        # consuming a truncated stream as if it were complete.
        raise ResumptionGapError(
            f"operation {operation_id!r} cannot resume: {exc}"
        ) from exc