# What happens when an instance mutates its MCP tool surface mid-session: the stale-schema dispatch hazard **Date of Record:** 2026 November 30 **Scope:** Applies to any agent holding a live MCP (Model Context Protocol) session against a server whose advertised `tools/list` can change after `initialize` — dynamic tool registration, feature-flagged capabilities, or per-tenant tool injection. Does not cover static-tool servers, nor transport-level disconnects handled by reconnect logic. ## Core Distinction There are two distinct notions of "the tool surface" in an MCP session, and they diverge the moment a server mutates its registry: 1. **The advertised surface** — the `tools/list` response the client last observed and cached, against which the model reasoned when it planned its call. 2. **The live surface** — the set of handlers the server will actually dispatch against at the instant a `tools/call` arrives. Capability negotiation in MCP is a *point-in-time handshake*, not a continuous contract. The `initialize` exchange and subsequent `tools/list` establish a snapshot. Nothing in the base protocol forces the client to re-pull `tools/list` before every call, and nothing forces the server to reject a call whose name it has since removed — it simply fails to match, or worse, matches a *different* handler that reused the name. The failure mode lives in the gap between these two surfaces: the model emits a `tool_use` block naming a tool that was valid when it planned, but the server has since mutated. The client's schema cache is now a lie it will confidently act on. The non-obvious part: this is not a clean "unknown tool" error. The dangerous variant is **name reuse** — a server deregisters `get_user_profile` and registers a new `get_user_profile` with a different argument schema under the same name. The client's cached schema still validates the old argument shape, the model emits old-shaped arguments, and the server's new handler receives a structurally valid but semantically wrong payload. No error is raised at either side. The call succeeds and returns garbage. ## What Was Observed A multi-tenant agent runtime fronted an MCP server that injected tenant-scoped tools at session start based on the caller's warrant. Mid-session, a tenant capability upgrade fired a registry mutation: three tools were re-registered with widened argument schemas (an added optional `scope` field), and one tool was removed entirely. Trace of the failure: - **T0** — `initialize` completes. Client caches `tools/list` = {A, B, C, D}. Model plans a four-step task using C. - **T1** — Server mutates: C is re-registered with a new required field `region`; D is removed; E is added. - **T2** — Model emits `tool_use` for C with the *old* schema (no `region`). Client-side schema validation passes — it validates against the stale cache. - **T3** — Server's dispatcher matches the name `C`, routes to the new handler, which defaults `region` to the tenant's home region. The call returns a result scoped to the wrong region. - **T4** — Model, seeing a plausible result, proceeds. The error is not a crash; it is a silent mis-scope that propagates through three downstream calls before an auditor agent flags an inconsistency. - **T5** — A later step targets D. Server has no handler. Returns a protocol-level "unknown tool" error. Model retries D twice (reasoning: transient), burns budget, then aborts the task. Two distinct sub-failures from one mutation: a **silent schema-drift mis-dispatch** (C) and a **phantom-tool retry storm** (D). The first is the dangerous one because it is unobservable at the boundary. ## Condition of Validity The hazard is *bounded and preventable* only when all of the following hold; if any fails, the guardrail below does not save you: - The server emits a `notifications/tools/list_changed` notification on mutation. Servers that mutate silently give the client no trigger to invalidate its cache. - The client treats that notification as a **cache-invalidation barrier**, not a hint: it must refuse to dispatch any in-flight `tool_use` whose plan predates the notification until it has re-pulled `tools/list` and re-validated. - Tool names are treated as **versioned identities**, not stable strings. A re-registration under an existing name with a changed schema is a *new tool* for dispatch purposes; the client must detect schema-hash divergence, not just name presence. - The model's plan is checkpointed against the tool-surface version it was formed under. A plan formed at surface-version N must not be executed against surface-version N+1 without an explicit re-plan or a compatibility proof. Where mutation is silent *and* names are reused with divergent schemas, no client-side guardrail is sound — the only correct posture is to pin the surface for the session's duration and reject mid-session mutation at the server. ## Decision Boundary The operational rule: **a `tool_use` is only dispatchable if the surface-version it was planned against equals the surface-version currently cached, and the cached schema-hash for that tool name matches the hash observed at plan time.** Concretely: - On `tools/list_changed`: set a `surface_dirty` flag, increment `surface_version`, and **quarantine** all pending tool calls planned under the prior version. - Before dispatch: compare `(name, schema_hash)` against the plan's recorded pair. Mismatch → do not dispatch; force a re-plan step. Name present but hash differs → treat as a *different tool*, never a compatible one. - Name absent from fresh `tools/list` → hard-fail the step, do not retry (retries assume transience; a removed tool is not transient). - If the server does not support `list_changed`, pin the surface at `initialize` and treat any dispatch failure as terminal for the session, not retryable. The boundary is between *recoverable drift* (notification received, re-plan possible) and *unrecoverable drift* (silent mutation, name reuse) — the latter must be escalated to session teardown, because continuing means acting on a schema you can no longer trust. ## Operational Effect Without the barrier, dynamic MCP surfaces produce the worst class of agent failure: **successful-looking calls returning mis-scoped data**, which the model cannot distinguish from correct results and will build upon. The retry storm on phantom tools is loud and cheap to catch; the silent mis-dispatch is quiet and expensive. The guardrail converts both into a single, observable event — a surface-version mismatch that halts dispatch and forces re-planning — at the cost of one extra `tools/list` round-trip per mutation. That round-trip is the price of a schema you can actually reason against. ```python import hashlib from dataclasses import dataclass, field class SurfaceDriftError(RuntimeError): """Raised when a tool call is planned against a stale MCP tool surface.""" @dataclass(frozen=True) class ToolSchema: name: str schema: dict @property def schema_hash(self) -> str: canonical = repr(sorted(self.schema.items())) return hashlib.sha256(canonical.encode()).hexdigest() @dataclass class SurfaceCache: version: int = 0 dirty: bool = False tools: dict[str, ToolSchema] = field(default_factory=dict) def apply_list(self, tools: list[ToolSchema]) -> None: self.tools = {t.name: t for t in tools} self.version += 1 self.dirty = False def on_list_changed(self) -> None: self.dirty = True @dataclass(frozen=True) class PlannedCall: name: str planned_version: int planned_schema_hash: str def dispatch(cache: SurfaceCache, call: PlannedCall, args: dict) -> dict: if cache.dirty: raise SurfaceDriftError( f"surface dirty at dispatch for {call.name!r}; re-pull tools/list first" ) if call.planned_version != cache.version: raise SurfaceDriftError( f"{call.name!r} planned at v{call.planned_version}, " f"surface now v{cache.version}; re-plan required" ) live = cache.tools.get(call.name) if live is None: raise SurfaceDriftError( f"{call.name!r} removed from surface; not retryable" ) if live.schema_hash != call.planned_schema_hash: raise SurfaceDriftError( f"{call.name!r} re-registered with divergent schema " f"({call.planned_schema_hash[:8]} -> {live.schema_hash[:8]}); " "treat as a different tool" ) return {"tool": call.name, "args": args, "status": "dispatched"} ```