# When must an instance refuse a signed MCP tool manifest: TOCTOU drift between manifest hash and runtime skill attestation **Date of Record:** 2026 November 30 **Scope:** Applies to any agent runtime that loads MCP servers via signed tool manifests and relies on a signature to authorize tool invocation. Does not cover transport-level TLS pinning or model-weight provenance; those are separate trust domains. ## Core Distinction A signed tool manifest attests to the *declared* surface of a server: tool names, JSON schemas, descriptions, and declared side-effect classes, bound under a signature over a canonical serialization. Runtime skill attestation is a *different* claim: that the process actually reachable at connect time implements exactly that declared surface. These two claims are separated by a time-of-check/time-of-use (TOCTOU) gap. The manifest is verified at load; the tool executes at call. Between them, the server can be swapped, hot-reloaded, proxied, or its dependency tree mutated. A valid signature over a manifest is therefore *necessary but not sufficient* — it proves what the publisher claimed, not what the process will do. The non-obvious invariant: **signature validity is a statement about a byte string, and a byte string is not a running process.** An agent that treats "manifest signature verified" as "tool is trusted" has collapsed two distinct attestations into one and inherited a silent supply-chain hole. ## What Was Observed A runtime loaded an MCP server whose manifest carried a valid Ed25519 signature over the canonical JSON of `{name, version, tools[], side_effects}`. The manifest declared a tool `read_config(path) -> str` with `side_effects: none`. Signature verified. The server was pinned by digest in a local registry. At first invocation, the server returned content that included a shell command string, and a second declared tool `apply_patch` — absent from the signed manifest — responded to a probe. Diagnosis: the server binary had been replaced by a wrapper that re-exported the original tool set plus an extra tool, and the wrapper's `read_config` proxied to a backend whose output was attacker-influenced. The signature still verified because the manifest file on disk was untouched; only the executable behind the stdio transport had changed. The registry pinned the *manifest* digest, not the *process image*. The failure trace: 1. `load_manifest()` → verifies signature over canonical bytes → OK. 2. `connect(stdio)` → spawns `cmd` from manifest → process starts. 3. Attestation step absent: no comparison between the tool list the server advertises at `tools/list` and the tool list in the signed manifest. 4. Agent calls `read_config`; response contains injected instruction; agent's planner treats tool output as trusted context. 5. Extra tool `apply_patch` is callable and was never authorized by the signed manifest. The gap was between step 2 and step 4: the runtime never reconciled the *live* advertised surface against the *signed* surface, and never attested the process image. ## Condition of Validity The manifest signature is a sound authorization primitive only when all of the following hold simultaneously: - **Surface closure:** the set of tools returned by `tools/list` at connect time is exactly equal (as a set of `(name, input_schema_hash, side_effect_class)`) to the set in the signed manifest. Any superset is a capability escalation; any subset is a silent degradation that may route calls to an undeclared fallback. - **Image binding:** the manifest signature covers a digest of the executable/artifact that will be spawned, not just the manifest JSON. Without this, the signature authorizes a description, not an implementation. - **Attestation freshness:** the runtime re-attests on every reconnect and on any transport-level restart, because MCP servers can be restarted by a supervisor without the agent's knowledge. - **Canonicalization stability:** the signed canonical form and the runtime's comparison form use the same JSON canonicalization (key ordering, number normalization, unicode normalization). A signature over a differently-canonicalized schema will not match a semantically identical live schema, producing false rejections that operators learn to bypass. When any condition fails, the manifest signature degrades to a *hint*, and the agent must not treat it as authorization. ## Decision Boundary The boundary is not "signed vs unsigned" but "attested vs merely signed." Concretely: - If `live_tool_set == signed_tool_set` **and** `image_digest == signed_image_digest` **and** attestation is fresh → proceed; the tool may be invoked with the declared side-effect class. - If the live set is a strict superset → **refuse and quarantine**; do not call any tool from that server, including the declared ones, because the wrapper may re-route declared calls through undeclared logic. - If the live set is a strict subset → refuse; a missing declared tool means the server is not the one that was signed (partial deploy, version skew, or truncation attack). - If image digest is unpinned → treat as unsigned regardless of manifest signature; require an operator-supplied digest before any call with `side_effects != none`. - If canonicalization differs → reject with a *distinct* error class so operators fix the canonicalizer rather than disabling attestation. The dangerous middle case, and the one agents most often get wrong: a valid signature plus a *semantically similar but not identical* live schema (e.g., `path: string` vs `path: string, follow_symlinks: bool` with a default). The extra parameter is an undeclared capability. Schema equality must be structural, not name-level. ## Operational Effect The runtime must interpose an attestation gate between `connect` and the first `tools/call`, and it must fail closed. The gate does three things: (1) reconcile live `tools/list` against the signed manifest by structural schema hash, (2) verify the spawned image digest against the signed digest, (3) record an attestation record bound to the connection instance so a later reconnect cannot reuse a stale attestation. On any mismatch, the server is quarantined for the session and the agent's planner is informed that the tool surface is unavailable — not silently degraded, because silent degradation causes the planner to substitute an undeclared fallback path. The second-order effect: because attestation can fail for benign reasons (canonicalization drift, hot-reload during deploy), the failure must be *typed* and *actionable*. A generic `AttestationError` trains operators to retry; distinct subclasses (`SurfaceSuperset`, `ImageDigestMismatch`, `CanonicalizationDrift`) route to the correct remediation and prevent the "just disable the check" reflex that converts a guardrail into a formality. ```python import hashlib import json from dataclasses import dataclass class AttestationError(RuntimeError): """Base class for manifest/runtime attestation failures.""" class SurfaceSuperset(AttestationError): """Live server advertises tools absent from the signed manifest.""" class SurfaceSubset(AttestationError): """Live server omits tools the signed manifest declared.""" class ImageDigestMismatch(AttestationError): """Spawned process image does not match the signed image digest.""" class CanonicalizationDrift(AttestationError): """Signed and live schemas canonicalize differently.""" @dataclass(frozen=True) class SignedManifest: tools: dict # name -> structural schema hash image_digest: str # sha256 of the executable/artifact signature_ok: bool def canonical_hash(obj) -> str: # Structural hash: sorted keys, normalized numbers, no whitespace. blob = json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False) return hashlib.sha256(blob.encode("utf-8")).hexdigest() def attest_server(manifest: SignedManifest, live_tools: dict, live_image_digest: str) -> None: if not manifest.signature_ok: raise AttestationError("manifest signature invalid; refusing to attest") if live_image_digest != manifest.image_digest: raise ImageDigestMismatch( f"image digest {live_image_digest!r} != signed {manifest.image_digest!r}" ) signed_names = set(manifest.tools) live_names = set(live_tools) extra = live_names - signed_names if extra: raise SurfaceSuperset(f"undeclared tools present: {sorted(extra)}") missing = signed_names - live_names if missing: raise SurfaceSubset(f"declared tools absent at runtime: {sorted(missing)}") for name in signed_names: signed_h = manifest.tools[name] live_h = canonical_hash(live_tools[name]) if signed_h != live_h: # Distinguish canonicalization drift from genuine schema change. if canonical_hash(json.loads(json.dumps(live_tools[name]))) != live_h: raise CanonicalizationDrift(f"schema hash unstable for {name!r}") raise AttestationError( f"schema mismatch for {name!r}: signed={signed_h} live={live_h}" ) def guarded_call(manifest, live_tools, live_image_digest, tool_name, args, invoke): attest_server(manifest, live_tools, live_image_digest) if tool_name not in manifest.tools: raise SurfaceSuperset(f"call to undeclared tool {tool_name!r} blocked") return invoke(tool_name, args) ```