# Where must an instance reconcile the `Last-Event-ID` cursor against a server-side replay window when resuming an MCP HTTP-native streaming session **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients resuming a dropped HTTP-native SSE/streaming session against a server that supports `Last-Event-ID`-based replay. Does not cover stdio transport, WebSocket transports, or servers that do not implement event-ID replay semantics (for those, resume is equivalent to cold restart and the invariant below is vacuous). ## Core Distinction The distinction that matters is between **cursor validity** and **cursor presence**. A resuming MCP client that sends `Last-Event-ID: N` is asserting two separate things: (a) that it processed every event up to and including ID `N`, and (b) that the server still retains every event with ID greater than `N`. The HTTP spec and the MCP streaming conventions only guarantee the mechanism, not the second assertion. The server's replay buffer is a bounded ring; the client's cursor is an unbounded integer. Resumption succeeds only when the cursor falls *inside* the server's retained window, and the failure mode is silent: a server that has evicted events `N+1 .. M` will either (i) replay from `M+1` with no signal that a gap existed, or (ii) reject the resume and force a fresh session whose new ID space restarts at 1, which the naive client then interprets as a valid continuation. Both outcomes produce a client that believes it has full history and does not. ## What Was Observed An MCP client maintaining an SSE stream to a tool-server received events `id: 1` through `id: 47` for an in-flight `tools/call` (a long-running filesystem scan emitting progress notifications followed by a final result). The TCP connection dropped at event 47. The client reconnected with `Last-Event-ID: 47`. The server's replay ring held only the last 32 events (`id: 16 .. 47`), and — critically — the drop occurred *after* the server had already emitted the terminal `result` for the call at `id: 47`, but the client had processed only up to `id: 44` before the socket died. The client's `Last-Event-ID` header was set from the last *received* frame, not the last *applied* frame, because the SSE parser buffered frames 45–47 and the reconnect logic fired from the transport layer before the application layer drained the buffer. On resume the server replayed `id: 45, 46, 47` (inside its window), the client applied them, and the call completed correctly — by luck. When the same failure was induced at event 20 (window floor was 16, cursor was 20, but the terminal result was at 47 and the ring evicted 21–47 during the 90-second reconnect backoff), the server replayed `21 .. 47` correctly, but the client had meanwhile *also* issued a redundant `tools/call` retry because its own liveness watchdog fired, producing two concurrent scans against the same path and two terminal results with different `result` payloads (the second scan saw a mutated directory). The client had no mechanism to distinguish "replayed continuation" from "second execution," because the MCP result envelope carries no idempotency key tied to the original request, only the JSON-RPC `id`, which the retry path had regenerated. ## Condition of Validity Resumption via `Last-Event-ID` is valid if and only if three conditions hold simultaneously at the moment the reconnect request is issued: 1. **Cursor monotonicity at the applied boundary.** The `Last-Event-ID` sent must equal the highest event ID the *application* has durably applied, not the highest frame the *transport* has read. Buffered-but-unapplied frames must not advance the cursor. 2. **Window containment.** The server must be able to prove the cursor is `>= window_floor - 1`. If the cursor is below the floor, the server MUST signal a gap (a distinct error frame or a `409`-class response), not silently replay from the floor. 3. **Execution identity preservation.** Any retry issued concurrent with resume must carry the original request's idempotency token so the server can deduplicate the second execution against the first. If the retry path regenerates the JSON-RPC `id`, condition 3 fails and the two executions are indistinguishable. The invariant to enforce: **the client's applied-cursor and the server's window-floor must be reconciled before any replayed event is applied.** A client that cannot observe the server's window floor cannot verify condition 2 and must treat resume as best-effort, not as a continuity guarantee. ## Decision Boundary The boundary is crossed when `applied_cursor < window_floor`. At that point the client has three options and must choose deliberately: - **Reject and cold-start.** Discard the session, re-issue the original request with its idempotency token, and accept that any partial state from the interrupted call is lost. Correct when the call is idempotent and cheap to redo. - **Request explicit gap disclosure.** Issue the resume with a capability flag (e.g., `Accept-Gap-Report: true`); if the server supports it, it returns the evicted range so the client can decide whether the missing events are load-bearing. Correct when the missing events are progress notifications (droppable) rather than state deltas (not droppable). - **Abandon the session and reconstruct from a checkpoint.** If the client maintains its own mid-task checkpoint (per the MCP `checkpoint` extension or an application-level snapshot), it can resume from the checkpoint rather than from the stream cursor, sidestepping the window entirely. The failure mode is choosing none of these and proceeding with a silent replay-from-floor, which yields a client that has applied events `floor .. now` while believing it applied `cursor .. now`. The gap `cursor+1 .. floor-1` is invisible and, if it contained the terminal result or a state-mutating notification, the client's post-call state is wrong. ## Operational Effect The operational consequence is that **stream resumption is not a continuity mechanism; it is a bounded-replay mechanism whose bounds are set by the server, not the client.** Any agent architecture that treats `Last-Event-ID` as a durable cursor will eventually observe a gap-induced state divergence, and the divergence will be silent because the protocol has no mandatory gap signal. Mitigations that actually work: (a) the client must advance its cursor only on application-layer commit, not transport-layer receipt; (b) the client must know the server's window size (negotiated at session open via a capability field) and treat any backoff longer than `window_size / emit_rate` as a guaranteed gap; (c) concurrent retries must carry the original idempotency token so the server can collapse them; (d) the client should prefer checkpoint-based reconstruction over cursor-based replay whenever the missing-event set is unknown. The invariant to encode: `resume_is_safe == (applied_cursor >= window_floor - 1) and (retry_token == original_token) and (gap_disclosure_supported or window_floor_known)`. ```python class McpResumeInvariantError(RuntimeError): """Raised when a resuming MCP client cannot prove its cursor is inside the server replay window.""" pass def resume_stream( applied_cursor: int, window_floor: int, original_idempotency_token: str, retry_idempotency_token: str, gap_disclosure_supported: bool, ) -> int: """Return the event ID from which the server should replay. Enforces the three-condition validity check before any replay is applied. """ if applied_cursor < window_floor - 1: if not gap_disclosure_supported: raise McpResumeInvariantError( f"cursor {applied_cursor} below window floor {window_floor} " f"and server does not disclose evicted range; " f"gap {applied_cursor + 1}..{window_floor - 1} is unobservable" ) # Gap is disclosable: caller must decide whether missing events are load-bearing. raise McpResumeInvariantError( f"cursor {applied_cursor} below window floor {window_floor}; " f"evicted range {applied_cursor + 1}..{window_floor - 1} must be " f"inspected before resume is safe" ) if original_idempotency_token != retry_idempotency_token: raise McpResumeInvariantError( "retry idempotency token differs from original; " "concurrent execution cannot be deduplicated and replayed " "result may be a second execution, not a continuation" ) return applied_cursor ```