# What happens when an instance reconnects to an MCP server mid-session and the server treats the new transport as a fresh session: capability-scoped authorization silently de-scopes to the negotiated root set **Date of Record:** 2026 November 26 **Scope:** Applies to MCP (Model Context Protocol) deployments where a client instance holds a long-lived session whose tool authorization is bound to session-scoped capability grants, and where the transport (stdio, SSE, or streamable HTTP) can drop and re-establish underneath the logical agent. Does not apply to stateless one-shot tool invocation where every call re-negotiates its own authorization envelope. ## Core Distinction There are two things an MCP client believes are the same object and the server believes are two different objects: *the logical agent instance* and *the protocol session*. The agent's identity is a durable, application-level concept—"this is instance `agent-7f3a`, mid-task, holding a grant to call `fs.write` scoped to `/work/out`." The MCP session is a transport-level concept with a `Mcp-Session-Id` header, a negotiated capability set, and a server-side authorization context that lives and dies with the connection. The failure mode lives in the gap: **when the transport reconnects, the server mints a new session, re-runs `initialize`, and re-negotiates capabilities from the client's declared root set—not from the grants the previous session had accumulated.** The client, meanwhile, has no protocol signal that its authorization scope changed. It believes it is resuming. The server believes it is onboarding a stranger. Both are internally consistent. That is what makes it dangerous. ## What Was Observed A file-management agent was mid-task: it had called `initialize`, then received an out-of-band capability grant via a `notifications/tools/list_changed` flow after the user approved write access to `/work/out`. That grant was recorded server-side against session `sess-A`. The agent then performed a long `tools/call` (`fs.read` on a 40 MB log), during which the SSE stream idle-timed out at the load balancer's 60-second limit. The client library detected the dropped stream and transparently reconnected. On the wire: 1. Client opens a new transport, sends `initialize` with the same `clientInfo` and the same declared `roots` (which still listed only `/work` as a read root—the write grant had been an *extension*, not a root). 2. Server, seeing no `Mcp-Session-Id` (the client library did not replay it; it treated the reconnect as a cold start), allocates `sess-B` and re-negotiates capabilities from the declared roots. 3. Server responds `initialize` result with `capabilities.tools` reflecting only read-scoped tools. The write grant is gone—not revoked with an error, not downgraded with a warning, simply absent. 4. Client sends `tools/call` for `fs.write`. Server returns a JSON-RPC error `-32601 Method not found` (the tool is not in `sess-B`'s authorized set) *or*, worse, `-32001` authorization denied depending on server implementation. The agent's reasoning loop saw a tool error. Its retry policy—written for transient failures—retried twice, then fell back to a "degraded mode" path that wrote its output to a temp location and reported partial success. **The task did not fail loudly. It succeeded with the wrong side effect**, because the authorization boundary changed underneath a probabilistic planner that had no invariant asserting "my tool surface is stable across my task." The trace signature to look for: a `tools/call` that succeeded before a transport drop and returns `-32601`/`-32001` after, with no intervening `notifications/tools/list_changed` that the client acknowledged. That notification is the *only* protocol-legal way the tool surface may shrink. A silent shrink across a reconnect is the tell. ## Condition of Validity This failure is bounded by three concurrency conditions, and it only manifests when all three hold: - **The session carries accumulated authorization state.** If every tool call is authorized purely from the connection's declared roots with no accumulation (no approval flow, no `list_changed` extension), a reconnect is harmless—the re-negotiated set equals the old set. The bug requires grants that *diverge* from the declared root set. - **The transport can drop mid-task without the logical task ending.** Stdio over a supervised process rarely drops; SSE and streamable HTTP behind a proxy with idle timeouts drop routinely. The longer the individual `tools/call`, the higher the exposure. - **The client library reconnects transparently.** A client that surfaces the drop to the agent loop lets the agent re-verify its tool surface. A client that hides the drop behind a retry wrapper converts a recoverable discontinuity into a silent scope change. The invariant that must hold: **the authorized tool surface for a logical task is a function of the task's grant history, not of the current transport's negotiated roots.** Any system where surface = f(session) rather than surface = f(task) violates this under reconnect. ## Decision Boundary The architectural fork is where session identity is anchored. - **Anchor on transport (default MCP behavior):** session = connection. Simple, stateless server, but a reconnect is indistinguishable from a new client. Authorization state must be re-derived from declared roots, and any accumulated grant is lost. This is correct *only* if the client replays the `Mcp-Session-Id` and the server honors resumption—which most implementations do not, because the spec leaves resumption semantics to the server. - **Anchor on logical instance:** session = (instance identity, task identity). The client presents a durable instance token (signed, short-TTL) in `initialize` params; the server looks up grant history keyed on that token, not on the transport. A reconnect resumes the same authorization context. This requires the server to maintain grant state across transports and to reject a `tools/call` whose tool is not in the *resumed* set with an explicit `-32001` carrying a `reason: "scope_changed"` field—never a bare `-32601`. The boundary decision: **if your agent's task can outlive a single transport, you must bind authorization to the instance token, and you must make scope changes observable.** The cheap version—client replays `Mcp-Session-Id`, server treats unknown session as fresh—fails the moment a proxy strips the header or the server garbage-collects the session during a long call. ## Operational Effect The concrete consequences, in order of how they bite: 1. **Silent scope narrowing masquerades as tool absence.** `-32601` is indistinguishable from "this server never had that tool." A planner that branches on error code will take the wrong recovery path. Always emit a distinguishable authorization error and require the client to treat `-32001` as a hard stop, not a retry. 2. **Retry policies amplify the damage.** A retry on `-32601` re-sends the same call into a session that will never authorize it, burning token budget and, if the fallback path writes to an unapproved location, producing a side effect the user never sanctioned. The guardrail: retries are permitted only for transport-class errors (`-32000`, timeouts), never for authorization-class errors. 3. **The agent's memory of its own capabilities goes stale.** The instance's episodic memory records "I have write access to `/work/out`" from the pre-drop turn. Post-drop, that memory is false. Any checkpoint/resume logic that trusts the memory rather than re-querying `tools/list` will plan against a capability it no longer holds. The invariant: **capability claims in memory are advisory; the authoritative surface is the last `tools/list` response, and it must be re-fetched after any reconnect the client observes.** 4. **Auditor/verifier agents inherit the gap.** If a verification agent replays the task transcript against a fresh session to check the output, it will see the write succeed (in the original session) and then fail to reproduce it (in the fresh session), and may flag a false discrepancy. Verification must replay against a session provisioned with the *original* grant set, or it will produce spurious mismatches. The bounding guardrail, stated as an invariant the runtime should enforce: **before any `tools/call` that mutates external state, assert that the current session's `tools/list` contains the tool and that the session's grant epoch matches the epoch recorded at task start; on mismatch, halt and re-authorize rather than degrade.** ```python import hashlib from dataclasses import dataclass, field from typing import Dict, Set class ScopeDiscontinuityError(RuntimeError): """Raised when a logical task's authorized tool surface changes across a transport reconnect without an acknowledged capability notification.""" @dataclass class GrantEpoch: """Snapshot of the authorized tool surface at a point in a task.""" epoch_id: str tools: Set[str] roots: Set[str] @classmethod def snapshot(cls, tools: Set[str], roots: Set[str]) -> "GrantEpoch": digest = hashlib.sha256( ("|".join(sorted(tools)) + "#" + "|".join(sorted(roots))).encode() ).hexdigest()[:16] return cls(epoch_id=digest, tools=set(tools), roots=set(roots)) @dataclass class TaskBinding: """Binds a logical task to the grant epoch it started under.""" instance_token: str task_id: str start_epoch: GrantEpoch mutating_tools: Set[str] = field(default_factory=set) class SessionGuard: def __init__(self) -> None: self._bindings: Dict[str, TaskBinding] = {} def begin_task(self, instance_token: str, task_id: str, current_tools: Set[str], current_roots: Set[str], mutating_tools: Set[str]) -> TaskBinding: epoch = GrantEpoch.snapshot(current_tools, current_roots) binding = TaskBinding(instance_token, task_id, epoch, mutating_tools) self._bindings[task_id] = binding return binding def check_before_call(self, task_id: str, tool: str, live_tools: Set[str], live_roots: Set[str], reconnect_observed: bool, capability_notification_acked: bool) -> None: binding = self._bindings.get(task_id) if binding is None: raise ScopeDiscontinuityError( f"task {task_id} has no recorded grant epoch; refusing mutating call" ) live = GrantEpoch.snapshot(live_tools, live_roots) # Non-mutating reads may proceed under any epoch that still contains the tool. if tool not in binding.mutating_tools: if tool not in live.tools: raise ScopeDiscontinuityError( f"read tool {tool} absent from live surface {sorted(live.tools)}" ) return # Mutating calls: the surface must match the task-start epoch, OR the # change must have been delivered via an acknowledged capability notification. if live.epoch_id != binding.start_epoch.epoch_id: if reconnect_observed and not capability_notification_acked: raise ScopeDiscontinuityError( f"task {task_id}: mutating tool {tool} requested after reconnect; " f"surface changed {binding.start_epoch.epoch_id} -> {live.epoch_id} " f"with no acknowledged tools/list_changed. Halt and re-authorize." ) if tool not in live.tools: raise ScopeDiscontinuityError( f"task {task_id}: mutating tool {tool} not in live surface " f"{sorted(live.tools)} (epoch {live.epoch_id}); grant was dropped." ) def guarded_write(guard: SessionGuard, task_id: str, tool: str, live_tools: Set[str], live_roots: Set[str], reconnect_observed: bool, capability_notification_acked: bool) -> str: guard.check_before_call( task_id, tool, live_tools, live_roots, reconnect_observed, capability_notification_acked, ) return f"authorized {tool} under live epoch" if __name__ == "__main__": g = SessionGuard() g.begin_task( instance_token="agent-7f3a", task_id="task-991", current_tools={"fs.read", "fs.write"}, current_roots={"/work", "/work/out"}, mutating_tools={"fs.write"}, ) # Simulate a transparent reconnect that re-negotiated only read scope. try: guarded_write( g, "task-991", "fs.write", live_tools={"fs.read"}, live_roots={"/work"}, reconnect_observed=True, capability_notification_acked=False, ) except ScopeDiscontinuityError as exc: print(f"HALT: {exc}") ```