Repository navigation
feat(mcp): pin MCP tool-set digests and quarantine drifted servers (SK2) - #171
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| settings.pin = server | ||
| .pin() | ||
| .map(|pin| pin.parse().expect("the validated pin is a tool-set digest")); |
There was a problem hiding this comment.
🟡 Pinned and unpinned plans share an identity
Adding a matching pin changes server behavior without changing the plan digest. describe_server omits the pin, while both configurations produce identical catalogs until drift occurs.
Learn more
The plan descriptor is the durable identity of a compiled plan, and its digest represents behavior-affecting settings. A matching pin changes how future listing changes affect tool calls, but the MCP server descriptor omits it. The plan cache creates a new live generation when the registry changes, yet the persisted plan digest remains identical if both catalogs are currently healthy. This makes pinned and unpinned executions indistinguishable by plan digest.
Example: An unpinned linear server lists tools with digest abc…; adding pin: "abc…" keeps its catalog and readiness unchanged. Both plans get the same digest, although the pinned plan refuses calls after a later listing change.
Recommended fix: Include the configured pin in McpServerDescriptor and populate it in describe_server. Follow the descriptor version and fixture requirements for changing its canonical encoding.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let tools = self.namespaced_tools(tools); | ||
| let listing = Arc::new(Listing { | ||
| digest: McpToolSetDigest::of_tools(&tools), | ||
| tools, | ||
| }); |
There was a problem hiding this comment.
🟥 Skipped tools escape the server pin
When namespaced_tools skips a declared tool, of_tools leaves it out of the pin digest. McpManager::call still dispatches its nonempty name, so a matching pin does not prevent an explicitly granted call to a changed, skipped tool.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Thanks for this contribution — the tool-set pinning idea is one we want in QQ, and the reviewed design has now landed as a single integration PR: #194 ( #194 ports the MCP pinning delta from this stack and repairs the issues found in review (details and reproducing probes in the PR description and
This PR will be closed as superseded once #194 merges. |
… dispatch; add qq mcp inspect (#194) * feat(mcp)!: pin MCP tool sets in config and plan identity; enforce at dispatch; add qq mcp inspect An MCP server's tool descriptors are untrusted text the model reads as instructions, and the server may change them at any time. A server declaration may now carry `pin`: the SHA-256 tool-set digest (64 hex digits, validated at load) of the listing an operator reviewed. A pinned server whose listing digests differently is quarantined: it contributes no tools, the readiness message names both digests, and every call to it is refused (`McpCallFailure::Quarantined` -> `HostCallError::Refused`). This takes over the contributed stack #163 / #165 / #171 and ships only the MCP pinning delta, repaired against QQ's own contracts (ADR-0046): - Dispatch-time enforcement. A pinned call resolves the cached listing before waiting for a permit, re-checks the listing generation and the `list_changed` flag after it, requires the tool to be in that listing, and sends exactly one `tools/call` whose enqueue poll runs under a synchronous dispatch gate shared with `on_tool_list_changed`, `bump_generation`, and `shutdown`. Previously a queued call that passed the pin check executed after the server was quarantined. - Durable identity. `McpServerDescriptor.pin` is recorded and `DESCRIPTOR_VERSION` moves 9 -> 10; pinned and unpinned plans no longer share a digest. - Injective digest. Domain `qq-mcp-tool-set-v2` with length-prefixed fields replaces the `\0`-separated v1 encoding. - Whole listings only. Malformed or duplicate tool names fail the listing instead of being skipped before hashing; fetches are bounded to 32 pages, 512 tools, and 1 MiB; a `list_changed` during a fetch discards it. - Inspection. `McpManager::inspect` and `qq mcp inspect NAME` print the live digest and every descriptor as JSON without calling a tool, so the digest is reviewed before it is pinned rather than copied out of a quarantine error. The per-event audit hash chain from #165 is not ported: it has no consumer, checkpoint, or retention contract yet, and its verifier accepted a cursor rewrite. Approval/argument binding is deferred. Breaking: `DESCRIPTOR_VERSION` 9 -> 10 invalidates cached plan digests (recompiled on next load; no store migration). No protocol change. Verification: fmt, clippy (-D warnings), workspace build and tests, the minimal qq-provider profile, and `plan_compile` bench within noise of the baseline (ledger `docs/plans/progress/mcp-pinning.md`). Closes ENG-939. Supersedes #163, #165, #171. Co-Authored-By: romy <[email protected]> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(mcp): count listing descriptor bytes without buffering an encoded copy Codex review on #194: `serde_json::to_vec(tool)` allocated the whole encoded descriptor before the 1 MiB check, doubling the resident bytes for a page `rmcp` had already decoded. Measure through a counting `ByteBudget` writer instead; the write that crosses the budget is rejected and nothing is allocated. The check now bounds only what it claims to bound; the transport read limit remains an `rmcp` concern (SSE events are capped at 16 MiB there, stdio lines are unbounded) and is noted in the ledger. Co-Authored-By: romy <[email protected]> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: romy <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
What changes for users
An MCP server declaration accepts an optional
pin:QQ digests every server's tool listing (SHA-256 over each tool's namespaced name, description, compact sorted-key input schema, and hints, in name order — listing order is irrelevant). A pinned server whose live listing digests differently is quarantined: its tools leave the catalog, every call to it — including a tool whose own schema did not change — is refused with
McpCallFailure::Quarantined, and the readiness message readsA
list_changedthat drifts a pinned server quarantines it before the next call executes even if no catalog is fetched in between; a server that reverts to the pinned listing leaves quarantine on its next notification. A malformedpin(wrong length, uppercase, non-hex) fails config load:mcp server "x" pin must be the 64 lowercase hex digits of a tool-set digest. Unpinned servers behave exactly as before.Why / design
Slice SK2 (A2) of ADR-0042: Axiom's tool-set digest pinning and drift quarantine, as library code in
qq-mcprather than anaxiom-mcpdependency or a service.McpToolSetDigest([u8; 32])inqq-mcpwithDisplay/FromStras 64 lowercase hex and a versioned domain separator (qq-mcp-tool-set-v1\0). The schema is hashed asToolSpec::input_schema().get()— the compact sorted-key textserde_json::Valuealready produces, which is whatToolSpecequality relies on too — so no extra canonicalization pass exists.ServerStatecachesListing { tools, digest }instead of bare tools; the digest is computed once per fetch.ServerHandle::listing()compares againstsettings.pinon every use (a 32-byte compare) and returnsListingFault::Quarantined { expected, actual }without dropping the cache, so a quarantined server is reported, not refetched, per catalog/call.ServerHandle::executerunslisting()for pinned servers before connecting for the call. This is what makeslist_changedfail closed: the notification only marks the cache dirty; the next call refetches and re-verifies. Unpinned servers skip the check, so their call path is unchanged.McpCataloggainsservers: Vec<McpServerListing>(digest of every server that answered, quarantined included — that is the value an operator copies intopin) andquarantined: Vec<McpQuarantine>. Quarantined tools never reachtools.unavailablesemantics are unchanged.qq-configvalidates the pin text at load (valid_mcp_tool_set_pin) so a typo is a config error, not a silent quarantine; the composition root (src/mcp.rs) parses it intoMcpServerSettings::pinand mapsQuarantinedtoHostCallError::Refused(the server is reachable; the kernel declines to use it).Deliberately not ported: Axiom's separate
ServerIdentityChangedreason — qq names servers in configuration and the name is inside the digest, so a rename is a digest change; BLAKE3 (the workspace already carriessha2); per-tool pins; a CLI that prints a server's digest (the quarantine message carries the actual digest; the guide documents pinning via a placeholder pin — aqq mcp digest <server>command is a possible follow-up).Stacked on #165 (SK1) so the security-kernel ledger edits do not conflict; no code dependency on SK1.
Linear: ENG-
Slice: docs/plans/security-kernel.md#sk2
How verified
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace— all green;qq-mcp18 passed (13 existing + 5 new),qq-config98 passed,qq-core727 passedcargo test -p qq-provider --no-default-features --features test-support— not run;qq-providerunchangedNew tests,
crates/qq-mcp/src/tests.rs:tool_set_digest_ignores_listing_order_and_tracks_every_field— same digest for reordered listings and reordered schema keys; different digest for a renamed, re-described, reshaped, or re-hinted tool, pairwise distinct; hex round-trip, uppercase/short text rejected.unpinned_servers_list_tools_and_expose_their_digesta_matching_pin_leaves_the_server_usable— pin taken from one fixture, applied to a fixture listing the same tools in the opposite order.a_drifted_pin_quarantines_the_catalog_and_every_call— catalogquarantined/servers/toolsshape, unchanged tool refused too, listing cached (onetools/list), sibling server untouched, quarantine clears when the server reverts and notifies.a_list_changed_drift_quarantines_before_the_next_call— description change + notification with no catalog fetch in between; the next call isQuarantined.Extended,
crates/qq-config/src/tests.rs:mcp_servers_parse_layer_by_name_and_apply_defaults(pin surfaced, unpinned isNone),rejects_invalid_mcp_declarations(short / uppercase / non-hex pins rejected, well-formed pin accepted).Impact
tools/listfetch (already off the call path — fetches happen on first use and afterlist_changed). Pinned calls add a mutex lock and a 32-byte compare before the existing connect step; unpinned calls are unchanged.McpCataloggains two public fields (servers,quarantined) andMcpCallFailureone variant (Quarantined);McpServerSettingsgainspin(defaults toNonevianew). Existing configs withoutpinare unaffected.docs/design/tools.md§ MCP (digest + quarantine) and § MCP Configuration (pin);docs/guide/mcp.md(pinkey, "Pinning a server's tools");docs/plans/security-kernel.mdanddocs/plans/progress/security-kernel.md(SK2 → In review, implementation entry).Link to Devin session: https://app.devin.ai/sessions/4a83e789a14d4b4190950fb8678d668e
Open in Devin Desktop: https://app.devin.ai/desktop/session/4a83e789a14d4b4190950fb8678d668e?variant=devin
Requested by: @integrate-your-mind