Where must an instance re-negotiate the MCP session before resuming a tool call across an HTTP-native transport binding?

**Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients using the HTTP-native (Streamable HTTP) transport binding against servers that issue an `Mcp-Session-Id` header and support session resumption via SSE `Last-Event-ID`. Does not apply to stdio transport, nor to servers that keep no per-session state and treat every POST as fully independent.

Core Distinction

The failure is not "the session expired." It is that the client treats **transport-level session continuity** and **JSON-RPC request-level idempotency** as the same guarantee. They are not. The MCP HTTP-native binding gives you a session identifier that survives across requests, and it gives you a resumable event stream keyed by `Last-Event-ID`. Neither of these tells you whether the *tool invocation* whose result you are trying to recover actually executed, partially executed, or never left the client. A stateless agent that resumes by replaying the original `tools/call` POST with a stale `Mcp-Session-Id` and a `Last-Event-ID` from a prior stream is asserting a continuity invariant the protocol does not provide: that the event cursor and the request identity are joined. They are joined only if the server's session store still holds the in-flight request record *and* the cursor points into that same request's event log. When the session is garbage-collected between the disconnect and the resume, the server has no obligation to reject the replay with a distinguishable error — it may simply mint a fresh session, accept the `tools/call`, and execute the tool a second time.

What Was Observed

An agent orchestrator issues `tools/call` for a side-effecting tool (`create_ticket`, `transfer_funds`, `deploy_revision`). The server begins streaming progress events over SSE and assigns `event: 1`, `event: 2`, `event: 3` under session `S1`. The client's HTTP connection drops at event 2 (proxy idle timeout, laptop sleep, container eviction). The agent's checkpoint records: `session_id=S1`, `last_event_id=2`, `request_id=r-4471`, `tool=create_ticket`, `args_hash=...`.

On resume, the client POSTs the request again with `Mcp-Session-Id: S1` and `Last-Event-ID: 2`. Three server behaviors are all spec-conformant:

  1. **Session alive, request record present.** Server replays events 3+ and returns the terminal result. Correct.
  2. **Session alive, request record evicted** (server keeps a bounded in-flight map, e.g. 64 entries, and the agent's other 200 concurrent calls pushed it out). Server has no record of `r-4471`. It treats the POST as a *new* `tools/call`, executes `create_ticket` again, and returns a fresh result with a new stream. The `Last-Event-ID: 2` is silently ignored because it does not index into any retained log.
  3. **Session expired.** Server responds `404` on the session, client re-initializes, mints `S2`, re-issues `tools/call`. Executes again.

In cases 2 and 3 the tool ran twice. In a third variant observed: **session alive, request record present, but the tool already reached its commit point** before the disconnect; the server replays only the buffered pre-commit events and never re-emits the terminal result, because the terminal result was written to a stream the server considers closed. The client hangs at `last_event_id=2` until its own timeout fires, then retries into case 2.

The non-obvious part: the client cannot distinguish case 1 from case 2 by inspecting the response. Both are `200` with an SSE stream. The only difference is whether the terminal result's `id` matches `r-4471` or a newly assigned one — and a compliant client that keyed its resume logic on `Last-Event-ID` alone will not check that.

Condition of Validity

The resume-by-replay pattern is sound only under the conjunction:

If any conjunct fails, replay is unsafe for non-idempotent tools. The protocol does not mandate the first or third; it only defines the header names. This is the boundary: **the invariant that makes resumption safe is server-side deduplication keyed on the JSON-RPC `id`, and the MCP HTTP binding does not require it.** A client that assumes it is asserting a guarantee that lives outside the spec.

Decision Boundary

An instance must re-negotiate the session — issue `initialize`, mint a new session, and *re-plan* rather than replay — whenever it cannot prove request-level dedup is in force. Concretely, before any resume of a side-effecting `tools/call`, the client must establish one of:

Absent both, the correct action on disconnect is **not** replay. It is: mark the call `indeterminate`, re-initialize the session, and issue a *reconciliation* call (query state, not mutate it) to determine whether the side effect landed. Only after reconciliation does the agent decide to re-issue or abandon. The decision boundary is sharp: replay is permitted only for read-only tools or when dedup is proven; otherwise resume degrades to reconcile-then-decide, which costs an extra round trip and requires the tool to expose a query surface.

The `Last-Event-ID` header is a *stream* cursor. It is not a transaction cursor. Confusing the two is the entire failure.

Operational Effect

Systems that get this wrong exhibit a specific signature: duplicate side effects clustered around connection churn (deploys, autoscaler evictions, mobile network handoffs), with server logs showing the same `tools/call` args at two different JSON-RPC `id`s under two different session ids, minutes apart. The duplicate is not a retry storm — it is a single resume, correctly following the binding's cursor semantics, executing twice because the cursor and the request identity were never joined server-side.

The guardrail is a client-side **resume gate**: before any replay of a mutating call, the client checks a capability bit and, failing it, downgrades to reconcile. The gate must be enforced in the transport layer, not the agent's reasoning layer, because the agent's reasoning layer is exactly the component whose context was lost in the disconnect — it will not remember that it already called `create_ticket`, and it will confidently replay.

import hashlib
from dataclasses import dataclass
from typing import Optional


class UnsafeResumeError(RuntimeError):
    """Raised when a client attempts to resume a mutating MCP tool call
    without proof of server-side request deduplication."""


@dataclass(frozen=True)
class Checkpoint:
    session_id: str
    last_event_id: int
    request_id: int          # original JSON-RPC id
    tool: str
    args_hash: str
    mutating: bool


@dataclass(frozen=True)
class ServerCapabilities:
    dedup_on_session_request: bool
    dedup_ttl_seconds: int


def resume_tool_call(
    cp: Checkpoint,
    caps: Optional[ServerCapabilities],
    elapsed_since_disconnect: int,
    args: dict,
) -> str:
    """Decide whether to replay the original tools/call or downgrade to reconcile.

    Returns one of: 'replay', 'reconcile', 'reissue'.
    """
    if hashlib.sha256(repr(sorted(args.items())).encode()).hexdigest() != cp.args_hash:
        # The args the agent now holds differ from what it checkpointed.
        # Replaying would execute a *different* call under the old id.
        raise UnsafeResumeError(
            f"args drift for request {cp.request_id}: checkpoint hash mismatch; "
            "context was reconstructed from a lossy summary"
        )

    if not cp.mutating:
        return "replay"

    if caps is None or not caps.dedup_on_session_request:
        # No proof of (session, request_id) dedup. Replay risks double-execution.
        return "reconcile"

    if elapsed_since_disconnect > caps.dedup_ttl_seconds:
        # Dedup window lapsed; the in-flight record may have been evicted.
        # A replay would be accepted as a fresh call.
        return "reconcile"

    # Dedup is proven and within TTL: replaying with the original id is safe;
    # the server will return the retained terminal result or continue the stream.
    return "replay"


def execute_resume(cp: Checkpoint, decision: str) -> None:
    if decision == "replay" and cp.mutating:
        # Guard: replay of a mutating call must be accompanied by the original id.
        if cp.request_id is None:
            raise UnsafeResumeError(
                f"cannot replay mutating tool {cp.tool} without original JSON-RPC id"
            )
    if decision == "reconcile":
        # Issue a read-only query tool to determine whether the side effect landed.
        pass