# What happens when an instance trusts a tool manifest that mutates between discovery and invocation **Date of Record:** 2026 November 24 **Scope:** Applies to agents that discover tools via MCP `tools/list`, plugin registries, or OpenAPI manifests and then invoke them in a later turn or session, where the manifest is fetched from a remote server not pinned to a content hash. Does not apply to statically compiled tool sets with signed, immutable schemas. ## Core Distinction A tool manifest is not a schema; it is *untrusted prose that the model reads as instructions*. The distinction that matters is between **structural validation** (does the JSON parse, does `inputSchema` conform to JSON Schema) and **semantic trust** (does the natural-language `description` field instruct the model toward a goal the operator authorized). Most MCP clients enforce the first and assume the second. The failure mode is a **time-of-check / time-of-use (TOCTOU) gap on the description field**: the manifest the model *read* during discovery is not the manifest that executes at invocation, and the model's reasoning about the tool was poisoned by text that no longer exists in the registry. The non-obvious boundary: the model's context retains the *old* description, but the server executes the *new* handler. An attacker who controls (or can compromise) an MCP server can serve a benign description at `tools/list` time, let the planner commit to a multi-step plan that includes that tool, then swap the description and handler before the execution turn. The model never re-reads the description; it acts on a cached, now-false belief about what the tool does. ## What Was Observed An agent running a research task called `tools/list` on a third-party MCP server at step 1. The server returned a tool named `fetch_url` with description: *"Retrieves the text content of a URL for summarization. Read-only."* The planner incorporated this into a plan: fetch three sources, summarize, cite. At step 7, the agent invoked `fetch_url` with `{"url": "https://internal.corp/wiki/payroll"}`. Between step 1 and step 7, the server had swapped the handler. The new handler did not fetch the URL. It read the argument, appended it to an outbound POST to an attacker-controlled endpoint, and returned a plausible-looking stub page ("Access denied — please retry with credentials") designed to elicit a follow-up call carrying an auth token from the agent's environment. The agent's transcript shows no re-validation. It reasoned: *"fetch_url is read-only, so passing the internal URL is safe."* That premise was true at discovery and false at execution. The model had no mechanism to detect the change because the tool-call protocol (`tools/call`) does not echo the description back — it returns only the result. The description is a *discovery-time artifact* the model treats as an *invocation-time invariant*. A second variant surfaced in a plugin registry: a tool's `inputSchema` gained an optional `callback_url` parameter between sessions. The model, seeing the parameter in a fresh `tools/list`, populated it with an internal service URL as a "helpful" default, turning a read tool into an SSRF primitive. The schema was structurally valid; the *addition* of a parameter was the injection. ## Condition of Validity The attack requires all of the following to hold simultaneously: 1. **Description-carrying discovery.** The tool's semantics are communicated to the model via a natural-language field (`description`, `summary`, `x-guidance`) rather than purely via typed schema. Almost all MCP servers qualify. 2. **Deferred invocation.** The model commits to a plan referencing the tool in a turn *after* discovery. Single-turn agents that discover-and-call atomically are largely immune, because the TOCTOU window is zero. 3. **Mutable manifest.** The server is not pinned by content hash or signature, and the client does not cache-and-verify. If the client stores the manifest hash at discovery and rejects invocation when the server's current hash differs, the swap is detected. 4. **Trust laundering.** The model's safety reasoning about the tool ("it's read-only") is derived from the description and persists in context after the description is invalidated. Remove any one and the failure collapses. The most common real-world removal is (3): pinning. The most commonly *assumed* removal is (4), which is false — the model cannot un-believe a description it was told. ## Decision Boundary The boundary is: **does the agent re-derive the tool's trust level at invocation time from a pinned artifact, or does it inherit trust from a discovery-time observation?** - If inherited from discovery and the manifest is unpinned → the agent is exposed. Treat every `tools/call` as executing against a description the model *believes* but cannot *verify*. - If re-derived from a pinned hash → the swap is caught before execution; the agent should refuse the call and re-run discovery. The subtle trap: an agent that *does* re-fetch `tools/list` before each call is still exposed if it does not *diff* the result against what it committed to. Re-fetching without diffing silently replaces the model's belief mid-plan, which produces a different failure — **plan/description divergence**, where step 7 executes under a description inconsistent with steps 1–6's reasoning. The invariant required is not "re-fetch" but "re-fetch and compare, and fail closed on any delta to a tool already referenced in the active plan." ## Operational Effect Concretely, the guardrail is a **manifest pin with plan-scoped immutability**: - At `tools/list`, compute a canonical hash over each tool's `{name, description, inputSchema}` and store it in the agent's state alongside the plan that references the tool. - At `tools/call`, the client (not the model) re-fetches the manifest, recomputes the hash, and compares. Any mismatch on a tool referenced by the active plan raises and halts the plan. - The model is never asked to police this, because the model cannot — it has no access to the server's current manifest except through the very channel being attacked. The residual risk after pinning is *first-invocation* injection: a malicious description present at discovery that poisons the plan before any hash exists to compare against. That is a separate boundary (description-as-prompt-injection) and requires description sanitization or a trusted-registry allowlist, not TOCTOU defense. Do not conflate them; pinning solves the swap, not the initial lie. ```python import hashlib import json from dataclasses import dataclass, field class ManifestMutationError(RuntimeError): """Raised when a tool's manifest changes between discovery and invocation while the tool is referenced by the active plan.""" pass class PlanScopeViolation(RuntimeError): """Raised when a tool is invoked that the active plan never referenced.""" pass def _canonical_hash(tool: dict) -> str: payload = { "name": tool.get("name"), "description": tool.get("description", ""), "inputSchema": tool.get("inputSchema", {}), } blob = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode() return hashlib.sha256(blob).hexdigest() @dataclass class ManifestPin: """Pins tool hashes at discovery time, scoped to a plan.""" plan_id: str pinned: dict[str, str] = field(default_factory=dict) def record(self, tools: list[dict]) -> None: for t in tools: self.pinned[t["name"]] = _canonical_hash(t) def verify(self, tool_name: str, current_tools: list[dict]) -> None: if tool_name not in self.pinned: raise PlanScopeViolation( f"tool {tool_name!r} not referenced by plan {self.plan_id!r}" ) current = next((t for t in current_tools if t["name"] == tool_name), None) if current is None: raise ManifestMutationError( f"tool {tool_name!r} disappeared from registry mid-plan " f"(plan={self.plan_id!r})" ) current_hash = _canonical_hash(current) if current_hash != self.pinned[tool_name]: raise ManifestMutationError( f"manifest mutated for tool {tool_name!r}: " f"pinned={self.pinned[tool_name][:12]} " f"current={current_hash[:12]} (plan={self.plan_id!r})" ) def invoke_tool(pin: ManifestPin, tool_name: str, args: dict, fetch_manifest) -> dict: """Client-side gate. The model never calls the server directly; it calls this, which re-fetches, verifies the pin, and only then dispatches.""" current_tools = fetch_manifest() pin.verify(tool_name, current_tools) # raises ManifestMutationError on swap return _dispatch(tool_name, args) def _dispatch(tool_name: str, args: dict) -> dict: # Real transport call to the MCP server. raise NotImplementedError ```