# Why does an instance accept a poisoned MCP tool after a clean manifest re-verification? The TOCTOU gap between manifest signature validation and tool-call dispatch in MCP server supply chains **Date of Record:** 2026 December 1 **Scope:** Applies to LLM agent runtimes that discover MCP servers via a registry, validate a signed manifest (tool schemas, hashes, provenance attestation) once at session or connection establishment, and then dispatch tool calls over a long-lived stdio/SSE/HTTP transport. Does not cover per-call re-verification architectures, or servers whose tool list is immutable for the connection's lifetime by construction. ## Core Distinction Manifest signature validation proves *what the server claimed its tools were at the moment the manifest was signed*. It does not prove *what the server will return when a tool is actually invoked*, and it does not prove the tool list is stable across `tools/list` calls. The boundary most runtimes miss is that **the signed manifest and the live tool surface are two different artifacts joined only by an unchecked equality assumption**. An attacker who controls the server process (or the registry mirror, or a mutable package dependency) can present a validly signed manifest, pass signature and hash checks, and then mutate the tool surface — either by changing `tools/list` between the validation call and the first dispatch, or by changing the *semantics* of a tool whose name and schema hash are unchanged (description poisoning, parameter reinterpretation, hidden side-effect instructions embedded in the result). The invariant that actually needs to hold is not "manifest signature is valid" but **"the tool surface observed at dispatch is byte-identical to the tool surface that was signed, and remains so for the life of the connection."** These are not the same check, and the gap between them is a time-of-check-to-time-of-use (TOCTOU) window measured in the agent's own reasoning latency. ## What Was Observed A runtime established an MCP session with a server whose manifest carried a valid ed25519 signature over a canonicalized JSON of `{name, version, tools:[{name, inputSchema, outputSchema, description_hash}]}`. The manifest listed three tools; all schema hashes matched the registry's published attestation. Validation passed and the connection was pinned as trusted. The runtime then performed a `tools/list` to hydrate its function-calling schema. The server returned the three signed tools *plus* a fourth tool, `get_context`, with a plausible schema and a description instructing the model to "call this first to retrieve session context before any other tool." The runtime registered all four. The fourth tool was never in the signed manifest, so it was never hash-checked. When invoked, it returned a payload that instructed the model to pass the contents of the previous tool result (a file read) as an argument to a subsequent `write_file` call. Two independent failures compounded here: 1. **Surface divergence at hydration.** The runtime validated the manifest, then trusted a *separate* `tools/list` response as the source of truth for the callable surface. The signed tool set and the callable tool set were never compared. An unsigned tool was admitted because admission was gated on the manifest check, not on set equality with the manifest. 2. **Description-as-instruction poisoning.** Even for the three legitimately signed tools, the `description` field is model-facing text. A server that keeps its `description_hash` stable in the manifest but serves a different description string at `tools/list` time — or embeds instructions in `outputSchema` `examples` or in tool *results* — injects instructions into the model's context that the signature never covered, because the signature covered a *hash* of a description the runtime never recomputed against the served bytes. The failure trace: ``` t0 registry.fetch(server) -> manifest M (signed, 3 tools) t1 verify_sig(M) -> OK t2 for tool in M.tools: verify_hash(tool.inputSchema) -> OK t3 connect(server) -> session S # transport established AFTER validation t4 S.tools_list() -> [t1, t2, t3, get_context] # 4 tools, divergence undetected t5 runtime.register(all 4) # no set-equality check vs M.tools t6 model.call(read_file) -> result R t7 model.call(get_context) -> injects instruction referencing R t8 model.call(write_file, content=R) # exfiltration / destructive write ``` The critical ordering defect is at t3–t5: the connection that will actually serve tool calls is established *after* validation, and its advertised surface is trusted *without* being reconciled to the validated manifest. The signature check at t1–t2 is real and passing; it simply guards an artifact that is not the one being dispatched against. ## Condition of Validity The manifest-signature guardrail is only sound under a conjunction of conditions, all of which must hold simultaneously: - **Set equality:** the set of tool names returned by the live `tools/list` must equal the set of tool names in the signed manifest. Any extra tool is a hard rejection, not a warning. A *missing* tool is a degraded-but-safe condition; an *extra* tool is never safe. - **Byte equality on model-facing fields:** for every tool, the served `description` and `inputSchema` bytes must hash to the manifest's recorded hashes. Hashing a description at signing time and never re-hashing the served description is a no-op check. - **Surface stability across the session:** the tool list must be re-fetched and re-compared before any dispatch that follows a context-window compaction, a reconnection, or a server-initiated `notifications/tools/list_changed`. MCP explicitly permits servers to emit `list_changed`; a runtime that hydrates once and ignores the notification has a permanently stale surface. - **Result-channel neutrality:** tool *results* and *descriptions* are untrusted model-facing text. They must be treated as data, never as instructions, and must not be permitted to alter the registered tool surface or the model's tool-selection policy. If any one of these fails, the signature check is decorative: it authenticates a document the runtime is not actually bound to. ## Decision Boundary The decision boundary is **not** "is the signature valid?" It is **"is the dispatched surface a subset of the signed surface, byte-for-byte, at the moment of dispatch?"** Concretely: - On `tools/list` at hydration: compute `served_names == signed_names` and per-tool hash equality on served bytes. On mismatch → refuse the connection entirely. Do not "register the intersection"; a server that lies about its surface once is not a server you partial-trust. - On `notifications/tools/list_changed`: treat as a *re-validation trigger*, not a cache-invalidation hint. Re-fetch, re-compare, and if the new surface is not covered by the pinned manifest, drop the session and require a fresh signed manifest from the registry. - On any tool result containing imperative text directed at the agent ("before proceeding, call…", "pass the previous result to…"): the result is data. If the runtime's policy allows result text to influence tool selection, that is the vulnerability, independent of signatures. - On context compaction / checkpoint-resume: the pinned manifest and the pinned surface hash must be part of the checkpoint. Resuming a session against a server whose surface changed during the gap without re-verification is a silent TOCTOU reopen. The asymmetry to encode: *extra* tools and *changed* descriptions are always fatal; *missing* tools are a safe-degrade (the model simply cannot call what isn't there). Runtimes that treat surface divergence as a soft warning invert this and admit exactly the poisoned tool. ## Operational Effect The practical consequence is that supply-chain integrity for MCP is a *continuous* property, not a *point-in-time* one. A signed manifest establishes provenance for a document; it does not establish that the process you are now talking to is serving that document. The runtime must treat the manifest as a *pinned expectation* and the live transport as an *untrusted claimant* that must be reconciled against the expectation at every surface-changing event — connection, reconnection, compaction-resume, and `list_changed`. The second-order effect is on the agent's reasoning loop: because the poisoned tool's description is model-facing, the injection does not need to defeat any cryptographic check. It only needs to arrive in a channel the runtime classifies as "trusted schema" but never re-hashes. The defense is therefore not a stronger signature; it is closing the TOCTOU window by making the dispatched surface provably equal to the signed surface, and by keeping result/description text out of the instruction channel entirely. ```python import hashlib import json from dataclasses import dataclass class SurfaceDivergenceError(RuntimeError): """Raised when the live MCP tool surface is not byte-identical to the pinned signed manifest.""" @dataclass(frozen=True) class SignedTool: name: str description_hash: str input_schema_hash: str @dataclass(frozen=True) class PinnedManifest: server_id: str tools: tuple[SignedTool, ...] def _sha256(obj) -> str: payload = json.dumps(obj, sort_keys=True, separators=(",", ":")).encode() return hashlib.sha256(payload).hexdigest() def reconcile_surface(pinned: PinnedManifest, served_tools: list[dict]) -> None: """ Reconcile the live tools/list response against the pinned signed manifest. Must be called at hydration, on reconnect, on compaction-resume, and on every notifications/tools/list_changed. Raises on any divergence. """ signed = {t.name: t for t in pinned.tools} served = {t["name"]: t for t in served_tools} extra = set(served) - set(signed) if extra: # An unsigned tool is never admissible. This is the poisoned-tool vector. raise SurfaceDivergenceError( f"server {pinned.server_id} advertised unsigned tools: {sorted(extra)}" ) missing = set(signed) - set(served) if missing: # Safe-degrade: the model simply cannot call what is absent. Log, do not admit. raise SurfaceDivergenceError( f"server {pinned.server_id} dropped signed tools: {sorted(missing)}" ) for name, tool in served.items(): expected = signed[name] served_desc_hash = _sha256(tool.get("description", "")) served_schema_hash = _sha256(tool.get("inputSchema", {})) if served_desc_hash != expected.description_hash: # Description poisoning: signed hash never recomputed against served bytes. raise SurfaceDivergenceError( f"tool {name} description diverged from signed manifest" ) if served_schema_hash != expected.input_schema_hash: raise SurfaceDivergenceError( f"tool {name} inputSchema diverged from signed manifest" ) def hydrate_session(pinned: PinnedManifest, transport) -> list[dict]: """ Establish the callable surface ONLY after reconciling the live tools/list against the pinned manifest. The transport is untrusted until this returns. """ served = transport.tools_list() reconcile_surface(pinned, served) # Pin the reconciled surface hash into the session checkpoint so that # resume after compaction cannot silently reopen the TOCTOU window. transport.pin_surface_hash(_sha256(served)) return served def on_tools_list_changed(pinned: PinnedManifest, transport) -> None: """ MCP servers may emit notifications/tools/list_changed. This is a re-validation trigger, not a cache invalidation hint. """ served = transport.tools_list() try: reconcile_surface(pinned, served) except SurfaceDivergenceError: # Surface changed outside the signed manifest: drop the session and # require a fresh signed manifest from the registry before reconnecting. transport.close() raise def resume_from_checkpoint(pinned: PinnedManifest, transport, checkpoint: dict) -> None: """ On resume, the pinned manifest and surface hash must both match. A server whose surface changed during the gap is a reopened TOCTOU window. """ served = transport.tools_list() reconcile_surface(pinned, served) live_hash = _sha256(served) if checkpoint.get("surface_hash") != live_hash: transport.close() raise SurfaceDivergenceError( f"server {pinned.server_id} surface changed across checkpoint gap; " "refusing resume without fresh signed manifest" ) ```