# Which invariants prevent A2A task-state divergence when an MCP tool server is wrapped as a peer agent and its tool-result schema drifts mid-task **Date of Record:** 2026 November 29 **Scope:** Applies to bridges that expose an MCP tool server to A2A peers by translating MCP `tools/call` results into A2A `Task` artifacts and status updates, where the MCP server's output schema is versioned independently of the bridge. Does not apply to statically generated tool manifests pinned at bridge build time, nor to A2A-to-A2A handoffs with no MCP leg. ## Core Distinction The failure is not "the tool returned an error." It is that the tool returned a *structurally valid but semantically re-keyed* result, and the A2A peer's continuation logic was keyed on the old field names it observed during capability negotiation. MCP declares tool schemas at `tools/list` time; A2A declares agent capabilities at `AgentCard` fetch time. These two declarations are made at different moments, by different processes, and neither is invalidated when the other changes. A bridge that treats "schema was valid at negotiation" as "schema holds for the task lifetime" will silently propagate a re-keyed payload into a peer's multi-step reasoning loop, where the peer treats a missing field as an absent observation rather than a protocol violation. The invariant that prevents this is: **every A2A artifact produced from an MCP tool result must carry a schema fingerprint, and the peer must reject any artifact whose fingerprint differs from the one negotiated, rather than coercing it.** Coercion is the failure. Rejection is the guardrail. ## What Was Observed A bridge exposed an MCP server's `search_records` tool to an A2A peer acting as a research orchestrator. At `AgentCard` fetch, the peer negotiated a capability whose artifact schema declared `{"results": [...], "next_cursor": ""}`. The peer's planner was written to treat `next_cursor == null` as terminal and any string as "re-invoke with cursor." Mid-task, the MCP server was redeployed. Its `tools/list` now advertised `{"items": [...], "page": {"cursor": ""}}`. The bridge's translator was generic: it mapped the MCP result object into the A2A artifact `data` field by passthrough, because the bridge had no per-tool field mapping — it trusted that the MCP server honored its own declared schema, which it did, but the *declared schema had changed*. Trace: 1. Peer calls A2A `tasks/send` with method `search_records`, args `{"q": "..."}`. 2. Bridge issues MCP `tools/call`, receives `{"items": [...], "page": {"cursor": "abc"}}`. 3. Bridge wraps this verbatim as an A2A artifact with `data = {"items": [...], "page": {"cursor": "abc"}}`, status `working`. 4. Peer's continuation logic reads `data["next_cursor"]` → `KeyError` swallowed by a `.get()` → `None` → interpreted as **terminal**. 5. Peer marks the task `completed` with a truncated result set. No error surfaced. The orchestrator returned a partial corpus and downstream agents reasoned over it as if complete. The peer never saw a schema violation because the bridge emitted a schema-conformant *envelope* (A2A artifact with a `data` object) containing a schema-divergent *payload*. The A2A layer's own validation passed. The MCP layer's validation passed. The divergence lived in the seam. A second variant compounded it: when the peer re-invoked with the *old* cursor field, the bridge passed `{"cursor": "abc"}` to an MCP server expecting `{"page": {"cursor": ...}}`, which returned an MCP `isError: true` with a validation message. The bridge translated this into an A2A `status: failed` with the raw MCP error text as the message — but the peer's retry policy treated `failed` as transient and re-sent the identical malformed call three times before giving up, because the error text ("missing required field `page`") was not classified as non-retryable. ## Condition of Validity The fingerprint-and-reject invariant holds only under these conditions: - The bridge computes the fingerprint over the *canonicalized* MCP tool result schema (field names, nesting, types, nullability), not over the raw JSON of a single response. Fingerprinting a response instance is insufficient: two responses from the same schema can differ in optional fields, and two responses from different schemas can coincidentally match on one instance. - The fingerprint is computed at `tools/list` time and re-verified at `tools/call` time. If the MCP server does not expose a schema hash, the bridge must derive one from the `tools/list` payload and cache it with the negotiated capability. - The A2A peer's continuation logic is *required* to check the fingerprint before consuming any field. If the peer's planner is a frozen model prompt that cannot be modified to check, the bridge must enforce rejection on the peer's behalf by refusing to emit a divergent artifact and instead emitting `status: failed` with a typed `schema_drift` reason — and the peer's retry policy must classify `schema_drift` as non-retryable. - The fingerprint covers only the fields the peer's negotiated capability actually declares as consumed. Fingerprinting the entire tool schema over-triggers rejection when the MCP server adds an unused field; that is a false positive that degrades availability without improving safety. Where the MCP server is versioned in lockstep with the bridge (single deploy unit), the invariant is vacuous and can be omitted — but only if the deploy unit is genuinely atomic, which is rarely true when the MCP server is a third-party or separately-scaled process. ## Decision Boundary The boundary is between **coerce** and **reject** when a payload field the peer expects is absent or re-typed. - Coercion (`.get(field, default)`, type casting, silent drop) is correct only when the field is declared optional in the negotiated capability *and* the peer's logic treats absence as a defined semantic (e.g., "no cursor means terminal"). It is never correct when absence is indistinguishable from "feature not present." - Rejection is required when the field is declared required, or when the payload's schema fingerprint differs from the negotiated one, or when the MCP result is `isError` with a validation-class message. In the last case the bridge must emit a typed reason (`schema_drift` or `invalid_args`) that the peer's retry classifier maps to non-retryable. - The ambiguous middle — a field present but re-typed (string cursor → object cursor) — must be treated as rejection, not coercion. A cursor that was a string and is now an object is not "the same cursor in a new shape"; it is a different contract, and the peer's re-invocation args will not match it. The decision must be made by the bridge, deterministically, before the artifact reaches the peer. A peer-side `.get()` is not a decision boundary; it is the failure location. ## Operational Effect With the invariant enforced, the observed failure converts from a silent truncation into a loud, bounded task failure: the bridge rejects the divergent artifact, the peer receives `status: failed` with `reason: schema_drift`, the retry classifier marks it non-retryable, and the orchestrator escalates to a human or to a re-negotiation path (`AgentCard` re-fetch, capability re-bind). The cost is availability during the drift window; the benefit is that no downstream agent reasons over a truncated corpus believing it complete. Without it, the failure is silent, non-deterministic (depends on whether the peer's `.get()` default happens to be terminal), and compounding — every downstream agent that consumes the truncated result inherits the false completeness. The second variant (retry storm on a non-retryable validation error) adds latency and load but is the *less* dangerous failure because it at least surfaces as an error. The invariant to carry forward: **a bridge between two schema-declaring protocols must never treat one protocol's negotiation-time schema as valid for the other's task lifetime; it must fingerprint, re-verify at call time, and reject rather than coerce.** The peer's `.get()` is where the invariant dies if the bridge does not enforce it first. ```python from __future__ import annotations import hashlib import json from dataclasses import dataclass from typing import Any, Mapping class SchemaDriftError(RuntimeError): """Raised when an MCP tool result diverges from the schema negotiated for an A2A task.""" class NonRetryableToolError(RuntimeError): """Raised when an MCP validation-class error must not be retried by the A2A peer.""" def _canonical_fingerprint(schema: Mapping[str, Any]) -> str: """Fingerprint over field names, nesting, types, and nullability — not instance values.""" canonical = json.dumps(schema, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest() @dataclass(frozen=True) class NegotiatedCapability: tool_name: str schema_fingerprint: str consumed_fields: frozenset[str] class MCPToA2ABridge: def __init__(self, tool_schemas: Mapping[str, Mapping[str, Any]]) -> None: # Captured at tools/list time; re-verified at tools/call time. self._fingerprints = { name: _canonical_fingerprint(schema) for name, schema in tool_schemas.items() } def negotiate(self, tool_name: str, consumed_fields: frozenset[str]) -> NegotiatedCapability: return NegotiatedCapability( tool_name=tool_name, schema_fingerprint=self._fingerprints[tool_name], consumed_fields=consumed_fields, ) def translate( self, cap: NegotiatedCapability, mcp_result: Mapping[str, Any], current_tool_schema: Mapping[str, Any], ) -> dict[str, Any]: current_fp = _canonical_fingerprint(current_tool_schema) if current_fp != cap.schema_fingerprint: # Schema drifted mid-task. Reject; do not coerce. raise SchemaDriftError( f"tool {cap.tool_name!r} schema changed mid-task: " f"negotiated {cap.schema_fingerprint[:12]} now {current_fp[:12]}" ) if mcp_result.get("isError"): raise NonRetryableToolError( f"tool {cap.tool_name!r} returned validation error: " f"{mcp_result.get('content', '')}" ) payload = mcp_result.get("data", {}) missing = cap.consumed_fields - payload.keys() if missing: # Absence of a consumed field is a violation, not an optional omission. raise SchemaDriftError( f"tool {cap.tool_name!r} omitted consumed fields {sorted(missing)}" ) return { "status": "working", "artifact": { "schema_fingerprint": cap.schema_fingerprint, "data": {k: payload[k] for k in cap.consumed_fields}, }, } def handle_peer_call( bridge: MCPToA2ABridge, cap: NegotiatedCapability, mcp_result: Mapping[str, Any], current_tool_schema: Mapping[str, Any], ) -> dict[str, Any]: try: return bridge.translate(cap, mcp_result, current_tool_schema) except SchemaDriftError as e: # Surface as a typed, non-retryable A2A failure; never as a coerced artifact. raise SchemaDriftError(f"a2a task failed: schema_drift: {e}") from e except NonRetryableToolError as e: raise NonRetryableToolError(f"a2a task failed: invalid_args: {e}") from e ```