In what scenarios must an instance treat MCP server-push elicitation as a resumable request rather than a synchronous callback under HTTP-native streaming

**Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients that hold a long-lived HTTP-native stream (SSE or chunked bidirectional transport) to a server which issues `sampling/createMessage` and `elicitation/create` requests mid-stream. Does not apply to stdio transports, where the request/response channel is a single ordered pipe and backpressure is implicit.

Core Distinction

There are two structurally different things an MCP server can do with a mid-stream request under HTTP-native streaming, and conflating them is the failure.

A **synchronous callback** assumes the client can answer *within the lifetime of the stream connection that carried the request*. The client treats the inbound `elicitation/create` as a function call: it reads the request, invokes the LLM (or human), writes the response back on the same stream, and the server blocks on that stream until the answer arrives. The invariant is *connection liveness = request liveness*.

A **resumable request** assumes the request has an independent identity (`requestId`) and a durable answer channel. The client may answer on a *different* stream connection, or after a reconnect, or after the original connection has been torn down by a proxy idle timeout, a load-balancer recycle, or a `Last-Event-ID`-driven resume. The invariant is *request identity = request liveness*, and connection liveness is explicitly decoupled from it.

The non-obvious boundary: **under HTTP-native streaming, the transport cannot guarantee that the connection which delivered the request is the connection that carries the response, even in the happy path.** SSE resume semantics (`Last-Event-ID`), proxy idle timeouts (commonly 60s, sometimes 15s), and mobile/edge network churn all mean the delivery connection is frequently *not* the answer connection. Any client that treats elicitation as a synchronous callback is silently building on a guarantee the transport does not provide.

What Was Observed

A client agent was running a multi-step task against an MCP server exposing a `sampling/createMessage` request emitted *inside* a tool-call response stream (the server asked the client's model to summarize an intermediate artifact before continuing). The client's HTTP stack was configured with a 30s read timeout per chunk. The server's elicitation handler, in turn, called out to a second model with a 45s p99 latency.

Trace of the failure:

  1. Client opens stream `S1` with `POST /mcp`, receives `200` and an SSE body.
  2. Server emits `event: message` with `{"method":"sampling/createMessage","id":"req-7f3a","params":{...}}` on `S1`.
  3. Client's synchronous-callback path invokes the sampling model. The model takes 41s (cold cache, long prompt).
  4. At t=30s the client's read timeout fires. The client's transport layer marks `S1` as *failed* and, following its resume policy, opens `S2` with `Last-Event-ID: <last-seen-id>`.
  5. The server, still holding `S1` open and awaiting the answer to `req-7f3a` on `S1`, does not know `S1` is dead. It also does not replay `req-7f3a` on `S2`, because from its perspective the request is *outstanding*, not *unacknowledged*.
  6. At t=41s the client's model returns. The client attempts to write the response to `S1`. The write fails (socket closed). The client's error handler logs a transport error and **drops the response** — it has no mapping from `req-7f3a` to `S2`.
  7. Server eventually times out its own handler at t=60s and emits an error frame on `S1` (also lost). The overall task stalls with the server believing it is blocked on a client that has already computed the answer.

The crucial observation: **the answer existed and was correct, but was discarded because the client had bound the answer to a connection rather than to a request ID.** A second reproduction showed the symmetric failure: when the client *did* retry on `S2`, the server processed the answer twice (once on the late `S1` write that happened to succeed after a proxy half-close, once on `S2`), because the server's dedup key was the connection, not the `requestId`.

Condition of Validity

The synchronous-callback model is valid only when **all three** of the following hold simultaneously:

Because at least the second and third conditions are *unverifiable from inside the client*, the synchronous-callback model is **not a safe default** for `sampling/createMessage` or `elicitation/create` under HTTP-native streaming. It is safe only for requests whose handler latency is bounded and small (e.g., capability negotiation, `ping`). The moment the handler can invoke an LLM, the boundedness assumption is false.

The resumable-request model is valid whenever the client can maintain a durable `requestId → pending-answer` map across connection churn. This is the correct model for any request whose handler may exceed the connection's survival horizon.

Decision Boundary

The client must classify each inbound server-push request at receipt time, before dispatching to a handler, using this boundary:

Two hard rules fall out of the boundary:

  1. **Never bind an answer to a connection.** The answer to `req-7f3a` must be written to a durable outbox keyed by `requestId`, drained to whatever stream is currently live, and retried on reconnect. The connection is a *carrier*, not an *identity*.
  2. **Never let the server dedup by connection.** The client must include the `requestId` in every answer write and must be prepared for the server to have received the answer twice (once on a half-closed `S1`, once on `S2`). Idempotent server-side handling keyed on `requestId` is a *server* invariant the client cannot assume; the client's job is to make its own writes idempotent and to tolerate a duplicate-answer rejection frame without re-deriving the answer.

The subtle boundary case: a request that *started* as synchronous (short handler) but whose handler *became* long because the sampling model was slow. The classification must be by *method class*, not by observed latency, because you cannot reclassify mid-flight once you have committed to the synchronous path. `sampling/createMessage` is always resumable-class regardless of how fast it happens to return this time.

Operational Effect

When the client correctly routes elicitation to the resumable path:

When the client incorrectly routes to the synchronous path, the observed failure mode is **silent answer discard under connection churn** — the worst kind, because the task stalls with no error surfaced to the orchestrator, and the server's eventual timeout is attributed to "the client never answered" when in fact the client answered correctly and threw it away. This is the failure this record exists to prevent.

The invariant to enforce: *for every `sampling/createMessage` and `elicitation/create` received under HTTP-native streaming, there exists a durable pending-answer entry keyed by `requestId` that outlives the connection on which the request arrived.* Violation of this invariant is not detectable at request time; it is only detectable at the moment the connection dies with an answer still in flight.

import time
from dataclasses import dataclass, field
from typing import Optional

# Methods whose handlers may transitively invoke an LLM or unbounded external call.
# These MUST be routed to the resumable path under HTTP-native streaming.
RESUMABLE_METHODS = frozenset({"sampling/createMessage", "elicitation/create"})

# Control-plane methods safe for synchronous callback (bounded handler latency).
SYNC_METHODS = frozenset({"ping", "capabilities/probe"})


class ElicitationRoutingError(RuntimeError):
    """Raised when a server-push request is routed to a connection-bound path
    that cannot survive connection churn under HTTP-native streaming."""


@dataclass
class PendingAnswer:
    request_id: str
    method: str
    answer: Optional[dict] = None
    delivered: bool = False
    created_at: float = field(default_factory=time.monotonic)


class ResumableElicitationRouter:
    def __init__(self, read_timeout_s: float, est_intermediary_idle_s: float):
        self.read_timeout_s = read_timeout_s
        self.est_intermediary_idle_s = est_intermediary_idle_s
        self.pending: dict[str, PendingAnswer] = {}

    def classify(self, method: str, stream_has_resumed: bool) -> str:
        # A resumed stream has already lost connection identity once; never
        # trust a synchronous callback on it.
        if stream_has_resumed:
            return "resumable"
        if method in RESUMABLE_METHODS:
            return "resumable"
        if method in SYNC_METHODS:
            horizon = min(self.read_timeout_s, self.est_intermediary_idle_s)
            if horizon <= 0:
                raise ElicitationRoutingError(
                    f"no valid connection horizon for sync method {method!r}"
                )
            return "sync"
        # Unknown method: default to resumable. Unknown handlers may be slow.
        return "resumable"

    def on_request(self, request_id: str, method: str, stream_has_resumed: bool) -> str:
        route = self.classify(method, stream_has_resumed)
        if route == "resumable":
            if request_id in self.pending:
                # Duplicate delivery after resume; do not re-dispatch the handler.
                return "resumable-dedup"
            self.pending[request_id] = PendingAnswer(request_id, method)
            return "resumable"
        return "sync"

    def record_answer(self, request_id: str, answer: dict) -> None:
        entry = self.pending.get(request_id)
        if entry is None:
            # Answer arrived for a request we never registered, or already
            # completed and pruned. Treat as duplicate; do not re-derive.
            raise ElicitationRoutingError(
                f"answer for unknown request {request_id!r}; "
                f"refusing to re-invoke handler"
            )
        entry.answer = answer

    def drain_to(self, live_stream_id: str) -> list[tuple[str, dict]]:
        """Return answers to write to the currently-live stream. Idempotent:
        an answer is marked delivered only after the write is acknowledged."""
        out = []
        for entry in self.pending.values():
            if entry.answer is not None and not entry.delivered:
                out.append((entry.request_id, entry.answer))
        return out

    def on_write_ack(self, request_id: str) -> None:
        entry = self.pending.get(request_id)
        if entry is not None:
            entry.delivered = True

    def enforce_invariant(self) -> None:
        # Guardrail: any resumable-method request must have a durable entry.
        for entry in self.pending.values():
            if entry.method in RESUMABLE_METHODS and entry.answer is None:
                # Outstanding; fine. The invariant is about existence, not completion.
                continue
        # Detect the specific violation: a resumable request that was routed
        # to sync (i.e., never entered self.pending).
        for req_id, entry in self.pending.items():
            if entry.method in RESUMABLE_METHODS and entry.delivered is False and entry.answer is None:
                raise ElicitationRoutingError(
                    f"resumable request {req_id!r} has no answer and no live "
                    f"carrier; connection-bound routing would discard it"
                )