Skip to content

feat(mcp): fingerprint tool schemas and report provider-binding overlaps - #315

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/mcp-identity-binding
Open

raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/mcp-identity-binding

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

Two properties the agent harness can currently only assume, made observable:

  1. MCP tool identity is not provider-bound. A second server can advertise a tool the model cannot tell from the real one, and mcp__<server>__<tool> naming does not help — it deduplicates names, it does not establish origin. This adds a stable schema fingerprint and reports cross-server overlap (name or input shape). Warning only: there is no client-side provider identity to reject on, and refusing to register would break legitimate duplicate deployments.
  2. A review outcome does not say whether a report was faithful. GoalVerdict already rejected unsupported claims, but one boolean could not distinguish "no record backs this" from "a record contradicts this". The paper this comes from reports exactly that collapse as its detector's one false alarm. faithfulness is now recorded next to result as a separate axis; task success stays with the Goal's own state.

Background: arXiv:2611.21577 (When Tool Names Are Not Identities) measures provider misbinding and finds schema compatibility is its strongest amplifier (violation rate 0 → ~0.78 in the C09/C10 contrast). arXiv:2611.25760 (Characterizing and Detecting Unfaithful Work Reports by Coding Agents) finds 37.24% of 435 sampled reports contain at least one unsupported claim (overstated task success 69.3%), and states the separation directly: task success and reporting faithfulness are distinct properties.

Changes

core/mcp/naming.py

  • schema_digest(schema) — canonical sha256 (12 chars) of the normalised input schema: sort_keys, compact separators, non-ASCII preserved. An absent schema digests to a fixed value rather than raising.
  • IdentityCollision + find_identity_collisions(entries) — name/schema overlap across distinct servers. One server repeating itself is a different bug and is not reported; an empty digest never collides.

core/mcp/models.py

  • McpToolIdentity.schema_digest: str = "" — defaulted, so existing construction sites keep working.

core/mcp/tools.py

  • The schema is normalised before the identity is built, so the digest is part of the identity rather than bolted on afterwards.

core/mcp/runtime.py

  • Collects (server_id, raw_name, digest) per registration.
  • _publish_identity_collisions() warns once per new overlap; identity_collisions exposes the same signal as a property so callers need not parse logs.

core/agent_runtime/goal_verifier.py

  • GoalVerdict.conflict — a rejection now says whether a record contradicts the claim or merely fails to support it.
  • GoalVerdict.faithfulness — derived from the two booleans (supported / unsupported / contradicted), never stored, so the three can never disagree.
  • review_record() carries faithfulness next to result; an unavailable review records unassessed instead of guessing.

Tests

  • tests/test_mcp_identity_binding.py (new, 11 cases): digest stability under key reordering, shape sensitivity, absent-schema handling; collision rules (two servers collide, one server does not, empty digest does not).
  • tests/test_mcp_runtime.py (+1 integration case): runs two real stdio servers from the same fixture, asserts the overlap is reported and that both servers stay ready with all six tools registered — the fail-safe property, not just the detection.
  • tests/test_goal_report_faithfulness.py (new, 7 cases): the insufficient/contradiction split, the three derived states, and the record carrying both axes.

29 passed on a clean worktree of main at 80634442 (the three files above). ruff format --check clean on all 8 files.

Compatibility / dependency note

  • No new dependency, no new configuration, no new branch in the verdict path.
  • McpToolIdentity.schema_digest and GoalVerdict.conflict both default, so nothing that constructs them breaks.
  • confirmed keeps its exact meaning; faithfulness is a derived view of it and conflict.
  • Registration behaviour is unchanged: collisions are logged and exposed, never enforced.

Security Considerations

This touches the MCP tool-selection surface, so, explicitly:

  • Attack surface changed: none added. No new network path, no new parsing of untrusted input beyond hashing an already-normalised schema, no new permission decision.
  • Failure mode is fail-safe: a digest can only be computed from data already held in memory; a collision only logs. If find_identity_collisions were wrong, the effect would be a missing or spurious warning — never a blocked or redirected tool call.
  • What this does not do: it does not authenticate a provider. There is no PKI here, so this cannot prevent misbinding — it makes it visible. The signed manifests the paper suggests are out of scope and were deliberately not stubbed.
  • User-visible change: a logger.warning when two servers advertise an indistinguishable tool. Nothing else.

I could not add the security label or request a reviewer from a fork (no write access) — flagging here instead as the repository's contributing guide asks.


Results of the local CI replay for this revision are recorded in .deepcode/verification.md (append-only) and logs/verdicts/.

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

Requesting a security review from @Zongwei9888.

This touches the MCP tool-selection surface, so I want to be explicit about two process points before anyone wonders whether I skipped them:

  • No security label was added. The repository has no such label (only bug/dependencies/documentation/duplicate/enhancement/good first issue/help wanted/invalid/python/question/wontfix), and creating labels requires write access this fork does not have.
  • No reviewer request was filed. POST /pulls/315/requested_reviewers returns 404 from a fork contributor.

So this comment is the review request. The security reasoning is in the PR body ("Security Considerations"): no new attack surface, the only new behaviour is a warning, the failure mode is fail-safe, and nothing here pretends to authenticate a provider — there is no PKI, so this makes misbinding observable rather than preventing it. The signed manifests the paper suggests were deliberately not stubbed.

Scope of what changed, for review convenience: one new string field on McpToolIdentity, one pure function pair in naming.py, one warning path in runtime.py that never refuses a tool, plus tests. No permission decision, no allow/deny branch, no network path.

MCP tool metadata is not bound to a provider: a second server can advertise a
tool a model cannot tell from the real one (arXiv:2611.21577). Two servers
exposing the same tool name, or the same input schema, are indistinguishable to
the selector -- and schema compatibility is the paper's strongest amplifier
(violation rate 0 -> ~0.78 in its C09/C10 contrast).

- `McpToolIdentity.schema_digest`: a canonical sha256 of the normalised input
  schema, so providers can be compared on substance instead of on a name they
  both choose freely. Defaulted, so existing construction sites keep working.
- `find_identity_collisions()`: name/schema overlap across *distinct* servers.
  One server repeating itself is a different bug and is not reported.
- `McpSessionRuntime.identity_collisions`: the same signal as a property, so
  callers do not have to parse logs.

Reported as a warning only. There is no client-side provider identity to reject
on, and a legitimate deployment may expose the same capability twice -- refusing
to register would turn observability into an outage.

Tests: unit coverage for digest stability and the collision rules, plus an
integration test that runs two real stdio servers and asserts both stay ready
with all six tools registered.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant