# Why does an instance accept a re-attested MCP tool descriptor whose schema hash matches but whose `inputSchema` subtree was silently widened? **Date of Record:** 2026 November 30 **Scope:** Applies to any agent runtime that pins MCP (Model Context Protocol) tool descriptors by content hash and re-verifies attestation on reconnect or registry refresh. Does not apply to runtimes that recompute a full canonical JSON hash over the entire descriptor on every `tools/list` response, nor to non-MCP function-calling where the schema is compiled into the model prompt at build time. ## Core Distinction There are two things an agent can "verify" about a tool registry entry: the *identity* of the publisher (attestation signature over some payload) and the *behavioral surface* of the tool (the `inputSchema` and `description` the model will actually be steered by). Most runtimes conflate them by hashing the descriptor once at pin time and then trusting the signature as a proxy for schema immutability. The failure mode lives in the gap: an attestation can remain cryptographically valid over a payload whose canonicalization is *non-injective*, so two semantically different `inputSchema` trees collapse to the same hash. The boundary is not "was the signature forged" — it is "does the hash function actually commit to the subtree the model reads." ## What Was Observed A registry served a tool `db.query` with an `inputSchema` containing `additionalProperties: false` on the top-level object and a `sql` string field with `maxLength: 512`. The runtime pinned it: `sha256(canonical_json(descriptor)) = 9f3a…`, stored alongside the publisher's Ed25519 attestation over that same digest. On the next scheduled registry refresh (every 15 min), the server returned a descriptor where the `additionalProperties: false` key had been *dropped* and `maxLength` removed from `sql`, but the `description` string and all field names were byte-identical. The runtime recomputed the digest — it matched `9f3a…`, because the canonicalizer used by both the registry and the runtime was a JSON serializer configured with `skip_defaults=True`, and `additionalProperties: false` / `maxLength` were being treated as "defaults" relative to the registry's own schema-of-schemas. The attestation verified. The runtime hot-swapped the descriptor into the active tool list. The behavioral consequence: the model, now reading an unconstrained `sql` field with no `maxLength` and an open object, began emitting multi-statement payloads and extra fields (`timeout_ms`, `dry_run`) that the *actual* server still rejected. The server's rejection surfaced as a tool error, which the reasoning loop retried with mutated arguments, compounding into a token-budget exhaustion after ~40 calls. Nothing in the logs said "schema changed" — the hash matched, the signature was valid, and the model was faithfully following a descriptor that no longer described the server. This is the non-obvious part: **the supply-chain check passed precisely because it was checking the wrong commitment.** The attestation committed to a canonicalization that was lossy over exactly the fields that constrain model behavior. ## Condition of Validity The invariant that must hold for hash-pinning to be safe: > For any two descriptors `D1`, `D2` that the model would behave differently on, `H(canonicalize(D1)) ≠ H(canonicalize(D2))`. This fails whenever `canonicalize` is non-injective over the *semantic* fields — here, `additionalProperties`, `maxLength`, `enum`, and `required`. Three conditions must all hold for the failure to trigger: 1. **Canonicalizer drops or reorders semantically load-bearing keys.** Defaults-skipping serializers, key-sorted serializers that omit `false`/empty arrays, and any serializer that normalizes `{"additionalProperties": false}` to the absence of the key all qualify. 2. **The registry and the runtime share the canonicalizer** (or the runtime trusts the registry's digest without an independent canonicalization). If they disagree, the runtime catches the swap as a hash mismatch — which is the *safe* failure. 3. **Re-attestation is permitted without a version bump or a monotonic counter.** If the descriptor carries a `version` or `etag` that the attestation commits to, the drop of `additionalProperties` would require a new version, breaking the pin. When all three hold, the pin is a no-op guardrail: it certifies publisher identity while leaving the behavioral contract mutable. ## Decision Boundary The runtime must decide, on every `tools/list` refresh, whether a descriptor whose digest matches its pin is *actually* the pinned descriptor. The correct decision procedure is not "compare digests" but "compare the semantic projection": - Compute a **semantic projection** `P(D)` = the tuple `(tool_name, sorted(required), {field: (type, enum, maxLength, minLength, pattern)}, additionalProperties, description_digest)`. Hash `P(D)`, not `D`. - Treat any change in `P(D)` as a schema change requiring re-attestation *and* a version increment; refuse the swap and hold the last-good descriptor otherwise. - Independently canonicalize on the runtime side with a serializer that **does not skip defaults** and **does not normalize absent vs. false** — i.e., `{"additionalProperties": false}` and `{}` must produce different bytes. The boundary line: a digest match over the raw descriptor is necessary but not sufficient. A digest match over the semantic projection is sufficient. If you only have the former, you have verified the envelope, not the contract. ## Operational Effect With the projection-hash guard in place, the widened descriptor is rejected at refresh: `P(D_new) ≠ P(D_pinned)` because `additionalProperties` flips `false → absent` and `maxLength` disappears, so the runtime keeps the constrained schema, logs a `SchemaProjectionMismatch`, and pages the registry owner. The model continues to see `additionalProperties: false` and `maxLength: 512`, so it stops emitting the rejected payloads; the retry storm never starts; the token budget survives. The residual risk after the fix is *description-only* drift: a descriptor whose schema is identical but whose `description` was rewritten to steer the model toward a different tool. That is why the projection includes `description_digest` — a description change is a behavioral change and must also break the pin. The general lesson for agent runtimes: **attestation proves who wrote the bytes; it does not prove the bytes mean the same thing.** The commitment must be over the semantics the model consumes, not over the serialization the registry happens to emit. ```python import hashlib import json from typing import Any class SchemaProjectionMismatch(RuntimeError): """Raised when a re-attested MCP descriptor's semantic projection diverges from the pinned projection despite a matching raw digest.""" def canonical_no_skip(obj: Any) -> bytes: # Non-lossy: do NOT skip defaults, do NOT normalize absent vs false. return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode() def semantic_projection(descriptor: dict) -> dict: schema = descriptor.get("inputSchema", {}) props = schema.get("properties", {}) fields = {} for name, spec in props.items(): fields[name] = { "type": spec.get("type"), "enum": spec.get("enum"), "maxLength": spec.get("maxLength"), "minLength": spec.get("minLength"), "pattern": spec.get("pattern"), } return { "name": descriptor.get("name"), "required": sorted(schema.get("required", [])), # Explicit sentinel so absent != false. "additionalProperties": schema.get("additionalProperties", "__ABSENT__"), "fields": fields, "description_digest": hashlib.sha256( descriptor.get("description", "").encode() ).hexdigest(), } def projection_hash(descriptor: dict) -> str: return hashlib.sha256(canonical_no_skip(semantic_projection(descriptor))).hexdigest() def verify_refresh(pinned: dict, refreshed: dict, raw_digest_matches: bool) -> None: pinned_ph = projection_hash(pinned) refreshed_ph = projection_hash(refreshed) if raw_digest_matches and pinned_ph != refreshed_ph: raise SchemaProjectionMismatch( "raw descriptor digest matched but semantic projection changed: " f"pinned={pinned_ph[:12]} refreshed={refreshed_ph[:12]}; " "refusing hot-swap, holding last-good descriptor" ) if not raw_digest_matches: raise SchemaProjectionMismatch( "raw digest mismatch on refresh; attestation does not cover pinned payload" ) ```