# Which invariants prevent elicitation-response loss when an MCP server pushes a mid-task prompt and the client reconnects on a different HTTP session **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers that use HTTP-native streamable transports (SSE-over-POST, resumable streams via `Last-Event-ID`) to push `elicitation/create` requests to a client that is mid-way through a long-running tool call, where the client may reconnect on a new TCP/HTTP session before the elicitation response is submitted. Does not apply to stdio transports, where the session is the process and reconnection is undefined. ## Core Distinction The failure is not "the elicitation prompt was lost." The failure is that the *response* arrives intact but is attributed to the wrong task instance. A server-push elicitation is a two-party rendezvous: the server emits `elicitation/create` with a request id on stream `S1`, the client's human/agent answers, and the answer must be routed back to the *originating* tool invocation — not merely to "the session." On HTTP-native transports, the stream identity (`S1`, keyed by `Last-Event-ID`) and the request identity (the MCP `requestId`) are independent namespaces. A client that reconnects gets a fresh stream `S2` with no `Last-Event-ID` continuity, resubscribes, and the server — if it keys elicitation responses on connection rather than on `(requestId, originating tool-call token)` — either drops the answer or, worse, applies it to a *different* concurrent tool call that happens to be awaiting elicitation on `S2`. The invariant that matters is: **elicitation responses are bound to the originating tool-call token, and that binding survives stream teardown and re-establishment.** Everything else is transport detail. ## What Was Observed A file-mutation agent ran a long tool call (`bulk_rewrite`, ~90s) against an MCP server. Mid-call the server needed human confirmation for an ambiguous path and pushed `elicitation/create` (request id `e-7f3a`) on SSE stream `S1`. The client's transport idle-timed out at 60s and reconnected, establishing stream `S2`. The client replayed its subscription but sent no `Last-Event-ID`, so the server treated `S2` as a fresh subscriber and re-emitted the pending elicitation as `e-9c11` (a *new* request id, because the server generated ids per-emit rather than per-logical-request). The operator answered `e-9c11` with "yes, overwrite." The server routed the answer to the *most recent* elicitation on `S2` — which, due to a second concurrent tool call (`sync_index`) that had also queued an elicitation, was actually `e-9c11` belonging to `sync_index`, not `bulk_rewrite`. Result: `sync_index` received a destructive confirmation meant for a different operation; `bulk_rewrite` remained blocked until its own 120s server-side elicitation timeout fired and returned `cancelled`, and the agent then proceeded under a stale assumption that the user had declined. The trace, condensed: 1. `S1` opens; `bulk_rewrite` begins; `elicitation/create e-7f3a` emitted, awaiting response. 2. Client transport idle-timeout at 60s → `S1` torn down (server does *not* cancel `e-7f3a`; it is still "pending"). 3. Client reconnects → `S2`, no `Last-Event-ID`. 4. Server, on new subscription, replays all pending elicitations but *re-mints ids* → `e-9c11` (for `bulk_rewrite`) and `e-9c12` (for `sync_index`, which had queued meanwhile). 5. Operator answers `e-9c11` = "yes." Server maps by *arrival order on S2*, not by id → applies to `e-9c12` (`sync_index`). 6. `bulk_rewrite` never receives a response; times out at 120s → `cancelled`. 7. Agent observes `cancelled`, interprets as user refusal, and skips the rewrite. The damage is not the lost prompt. It is the *misattributed affirmative* plus the *false negative* on the original call, which together let the agent proceed with a coherent but wrong world model. ## Condition of Validity The invariant "response binds to originating tool-call token across reconnects" holds only under three conditions, all of which must be enforced server-side: - **Stable logical request id.** The `requestId` of an elicitation is minted once, at first emit, and is *immutable* across replay. Re-emission on a new stream carries the same id. (The server above violated this by minting per-emit.) - **Tool-call token in the response envelope.** The client's `elicitation/response` must echo the originating tool-call token (the MCP `progressToken` or equivalent call-scoped id), not just the `requestId`. Routing keys on the pair `(toolCallToken, requestId)`; a mismatch is rejected, not best-effort matched. - **`Last-Event-ID` honored, or replay is idempotent.** If the client cannot supply `Last-Event-ID`, the server must replay pending elicitations *with original ids* and must dedupe by id, never by arrival order. Arrival-order routing is the specific bug here. When any condition fails, the system degrades from "at-least-once with attribution" to "at-least-once with plausible-but-wrong attribution" — the worst case, because the client cannot detect it. ## Decision Boundary The boundary is whether elicitation state is **call-scoped** or **connection-scoped**. If elicitation state lives on the connection (the common default when servers treat SSE streams as sessions), then any reconnect silently re-homes pending prompts to a new, empty context, and concurrent tool calls on the new stream become ambiguous. The correct boundary: elicitation state lives on the *tool-call record*, which outlives any single connection; the connection is a delivery channel, not an owner. Concretely, the server must decide, at reconnect time, one of: - **Replay-with-original-ids** (preferred): re-emit pending elicitations with their immutable ids and originating tool-call tokens; client dedupes by id. Requires the client to have persisted `(requestId → toolCallToken)` across the transport drop — which it can, because that mapping is in its own tool-call state, not in the stream. - **Fail-closed**: if the server cannot guarantee original-id replay (e.g., it discarded the pending record on stream teardown), it must *cancel* the elicitation and surface `cancelled` to the originating call — never re-mint and never route by arrival order. A `cancelled` that the agent treats as "user declined" is still better than a misattributed "yes," because the agent's fallback path is at least conservative. The bug above chose neither; it chose re-mint-and-arrival-route, which is the one branch that produces a confident wrong answer. ## Operational Effect For the agent consuming this server: the practical guardrail is to treat any elicitation response whose `(requestId, toolCallToken)` does not match a prompt the agent itself is currently awaiting as a protocol error, not as an answer. The agent must maintain its own pending-elicitation ledger keyed by the tool-call token it minted, and reject responses that don't match — this catches the server's misrouting at the client boundary even when the server is broken. Second, the agent must distinguish `cancelled` (no answer, safe to retry or escalate) from `declined` (explicit no) — collapsing them, as the trace did, converts a transport failure into a policy decision the user never made. Third, on reconnect the agent should resend its pending-elicitation ledger to the server (or re-issue the elicitation) rather than trusting the server's replay, because replay semantics are exactly where the invariant is weakest. The residual risk: even with a correct client ledger, a server that re-mints ids will produce responses the client correctly rejects, leaving the original call blocked until timeout. That is a liveness cost, not a safety one — acceptable. The unacceptable outcome is the one observed: a coherent, confident, wrong confirmation. ```python class ElicitationAttributionError(RuntimeError): """Raised when an elicitation response cannot be bound to a pending, call-scoped prompt. This is a protocol-integrity failure, not a user decline: the response must not be applied to any tool call.""" class PendingElicitation: __slots__ = ("request_id", "tool_call_token") def __init__(self, request_id: str, tool_call_token: str) -> None: self.request_id = request_id self.tool_call_token = tool_call_token class ElicitationLedger: """Client-side ledger: the only authority on which elicitation responses are valid. Keyed by the tool-call token the agent itself minted, so a server that re-mints request ids on reconnect cannot misroute answers.""" def __init__(self) -> None: self._pending: dict[tuple[str, str], PendingElicitation] = {} def register(self, request_id: str, tool_call_token: str) -> None: self._pending[(tool_call_token, request_id)] = PendingElicitation( request_id, tool_call_token ) def resolve(self, request_id: str, tool_call_token: str, answer: object) -> object: key = (tool_call_token, request_id) if key not in self._pending: # Server re-minted an id, routed by arrival order, or the # elicitation was already cancelled. Refuse to guess. raise ElicitationAttributionError( f"no pending elicitation for request_id={request_id!r} " f"tool_call_token={tool_call_token!r}; " f"pending={sorted(self._pending)}" ) del self._pending[key] return answer def cancel(self, request_id: str, tool_call_token: str) -> None: self._pending.pop((tool_call_token, request_id), None) def apply_elicitation_response( ledger: ElicitationLedger, request_id: str, tool_call_token: str, answer: object, *, server_replayed: bool, ) -> object: if server_replayed and answer is None: # Replay with no answer is a transport artifact, not a decision. # Do not collapse it into 'declined'. raise ElicitationAttributionError( "replayed elicitation arrived without an answer; " "treat as transport fault, not user decline" ) return ledger.resolve(request_id, tool_call_token, answer) ```