# Which invariants prevent identity attestation from surviving MCP session re-binding across transport reconnects **Date of Record:** 2026 November 30 **Scope:** Applies to MCP hosts that mint agent identity attestations (signed capability warrants) and bind them to a specific transport session (stdio, SSE, or streamable-HTTP). Does not apply to stateless one-shot tool invocations where no warrant is presented, nor to identity established purely out-of-band per request. ## Core Distinction An MCP agent's identity attestation is a *signed claim about who the caller is and what it may do*, whereas an MCP transport session is a *mutable, ephemeral channel object* that the SDK silently re-establishes after a disconnect. The failure boundary lives exactly where these two lifetimes are conflated: the warrant is bound at session-open time to a session identifier, but the transport layer is free to tear down and re-create that session (SSE reconnect, streamable-HTTP `Mcp-Session-Id` expiry, stdio process respawn) without re-presenting the warrant. The invariant that must hold is *attestation-to-session binding is one-directional and non-transferable*: a valid attestation for session A must never be accepted as evidence of identity on a freshly minted session B, even when B carries the same logical agent name, the same client certificate, or a replayed `Mcp-Session-Id` header. The subtlety is that most MCP client libraries treat reconnection as a *transparent* concern. The reconnect succeeds, the tool calls flow, and the only signal that identity binding was lost is that the server is now authorizing an un-attested session using whatever residual state it cached keyed by agent name. Nothing in the wire protocol forbids this; the guardrail is entirely a server-side invariant. ## What Was Observed A host minted a signed warrant `W` for agent `planner-7`, scoped to `tools: {read_repo, open_pr}`, with `aud = session_id = s_ab12`. The warrant was stored server-side in a map `attestations[s_ab12] = W`. During a long multi-step task the streamable-HTTP transport dropped (idle timeout on the SSE leg at 60s of no server→client traffic while the agent was thinking). The SDK reconnected, the server issued a *new* `Mcp-Session-Id = s_cd34`, and the client resumed issuing `tools/call` messages on the new session without re-presenting `W` — because from the client's perspective the logical agent never changed. The server's authorization check was written as: ``` warrant = attestations.get(session.id) if warrant is None: warrant = attestations_by_agent.get(principal_from_transport(request)) ``` The fallback branch is the defect. `principal_from_transport` returned `planner-7` (derived from the client TLS identity, which *does* survive reconnect), so the server looked up the *prior* warrant by agent name and authorized `open_pr` on session `s_cd34`. The reconnected session executed a state-mutating tool under a warrant that was cryptographically bound to a session that no longer existed. In a second observed trace, the reconnect happened *after* the warrant's `exp` but the cached `attestations_by_agent` entry had not been reaped, so an expired warrant authorized a live call — a stale-memory drift of the attestation cache rather than of the agent's episodic memory. The failure trace in order: 1. `s_ab12` open → `W` presented, verified, cached under both `s_ab12` and `planner-7`. 2. Transport drop; `s_ab12` torn down server-side, but `attestations_by_agent["planner-7"]` not invalidated. 3. Reconnect → `s_cd34` minted; no warrant presented (client considers binding unchanged). 4. `tools/call open_pr` on `s_cd34` → `attestations.get("s_cd34")` is `None` → fallback to agent-name lookup → returns stale `W`. 5. Authorization passes; mutation executes under a warrant whose `session_id` claim (`s_ab12`) contradicts the actual session (`s_cd34`). ## Condition of Validity The invariant holds only if three conditions are enforced simultaneously: - **Binding is to an unforgeable session identifier, not to a transport-derived principal.** The `session_id` in the warrant's `aud`/`cnf` claim must be compared for equality against the *current* session identifier, and the transport-derived principal (TLS identity, mTLS CN, bearer subject) must be treated as a *necessary but insufficient* condition. Identity of the client ≠ identity of the session. - **Reconnect is an identity event, not a transport event.** Any new `Mcp-Session-Id` must invalidate all prior bindings for that logical agent and force re-presentation of the warrant. The SDK's transparent reconnect must be surfaced to the authorization layer as `session_changed` so the server can demand re-attestation. - **The attestation cache is keyed solely by session identifier with a hard TTL equal to `min(warrant.exp, session.idle_timeout)`.** No secondary index by agent name may be consulted on the authorization path; if it exists for observability, it must be non-authoritative and must be reaped on session teardown. If any one of these is relaxed — in particular the second, since it is the one the protocol does not enforce — the binding silently degrades to "whoever the transport says you are," which is exactly the conflation the invariant forbids. ## Decision Boundary The boundary is crossed at the moment a `tools/call` or `resources/read` arrives on a session whose identifier does not appear in the attestation map. At that instant the server has exactly two lawful choices: reject with a re-attestation challenge (`401`-equivalent MCP error carrying the new `session_id` so the client can re-sign), or, if the operation is provably idempotent and read-only *and* the policy explicitly permits un-attested reads, proceed under an anonymous low-privilege principal. The unlawful third choice — fall back to a cached warrant keyed by agent name — is the boundary violation. A second, narrower boundary governs the stale-expiry case: even if the session identifier matches, if `now > warrant.exp` the warrant must be rejected regardless of cache presence. The cache TTL must be `≤` the warrant lifetime; a cache entry that outlives its warrant is a replay surface. ## Operational Effect The practical consequence of enforcing the invariant is that long-running agent tasks will experience *forced re-attestation* on every transport reconnect, which the orchestrator must handle as a first-class state transition rather than a retryable error. In practice this means the client wrapper must, on `session_changed`, re-sign a fresh warrant scoped to the new `session_id` before the next tool call — a step that costs one signing round-trip and, if the signing key is held in an HSM or remote KMS, can add 50–300ms of latency at exactly the moment the agent's reasoning loop is mid-step. The failure mode this prevents is worse: an unattested or stale-attested session executing a mutating tool, which in the observed trace opened a pull request against a protected branch under an expired warrant. Systems that skip the invariant do not fail loudly; they fail by authorizing the wrong session, which surfaces only in audit-log reconciliation days later when the warrant's `session_id` claim is compared against the session that actually performed the call. The reconciliation check — `warrant.aud == audit_event.session_id` for every mutating event — is the cheapest post-hoc detector and should be run continuously, not just on incident. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class AttestationBindingError(RuntimeError): """Raised when an MCP session cannot be lawfully bound to an identity warrant.""" pass @dataclass class Warrant: agent: str session_id: str tools: frozenset exp: float @dataclass class Session: id: str transport_principal: str # e.g. mTLS CN; survives reconnect, NOT sufficient alone class AttestationStore: """Authoritative store keyed ONLY by session id. No agent-name index on the auth path.""" def __init__(self) -> None: self._by_session: Dict[str, Warrant] = {} def bind(self, w: Warrant) -> None: if w.exp <= time.time(): raise AttestationBindingError( f"refusing to bind already-expired warrant for {w.agent} on {w.session_id}" ) self._by_session[w.session_id] = w def reap(self, session_id: str) -> None: self._by_session.pop(session_id, None) def authorize(self, session: Session, tool: str) -> Warrant: w = self._by_session.get(session.id) if w is None: # No fallback by agent name. Force re-attestation on the new session. raise AttestationBindingError( f"no attestation bound to session {session.id} " f"(principal={session.transport_principal}); re-attestation required" ) if w.session_id != session.id: # Defensive: catches any future secondary-index bug. raise AttestationBindingError( f"warrant bound to {w.session_id} presented on {session.id}" ) if time.time() > w.exp: self.reap(session.id) raise AttestationBindingError( f"warrant for {w.agent} on {session.id} expired at {w.exp}" ) if tool not in w.tools: raise AttestationBindingError( f"{w.agent} not attested for tool {tool} on {session.id}" ) return w def handle_reconnect(old_session: Session, new_session: Session, store: AttestationStore) -> None: """Transport reconnect is an identity event: drop the old binding, demand a new one.""" store.reap(old_session.id) if store._by_session.get(new_session.id) is not None: # A reconnect must never inherit a binding minted for another session. raise AttestationBindingError( f"reconnect to {new_session.id} found a pre-existing binding; refusing" ) # Caller is now obligated to present a fresh warrant before any tools/call. ```