fix(mcp-server): revoke MCP tool registrations by their applied identity #8032
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.64)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 239 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.35 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.328
Real PR Conversation Timeline
2 items
Approved
Tracking the applied identity separately from the newest desired rule is the right decomposition — it is what makes rename, move and disable all revocable from one place instead of three ad-hoc recomputations of the tool name.
I checked the parts that are easy to get wrong:
previous before rules.put overwrites it, and isRegistered(previous) makes repeated disabled updates a no-op, so removeTool cannot fire twice. The reEnablingARuleRegistersTheToolExactlyOnce test pins exactly that.registrations entry in removeSelector without calling removeTool is safe: the method ends with shenyuMcpServerManager.removeMcpServer(path), which takes the tools with the server. Worth a one-line comment next to registrations.remove(...), because the invariant lives 9 lines below and is not obvious at that point.removeRule now delegates to unregisterTool, which prefers the tracked identity and only falls back to the handle-derived name — that is the right precedence, since a renamed rule no longer matches what the incoming handle describes.Minor: ToolRegistration's private getters are redundant — a nested class's private fields are already reachable from the enclosing class, so the getters only add noise.
Approving.
Aias00
imDwAaY
Fixes #8024
Fixes #8025
Both issues share one root cause: the handler keeps only the newest desired rule (
rules), never a record of what it actually registered in the SDK. Every cleanup path therefore has to infer the old state from incoming data, and it gets it wrong after a disable or a rename.Problem
handlerRule, andregisterToolreturns immediately whenenabled=false. A tool registered while the rule was enabled stays in the SDK server and inCACHED_TOOL, and its retained callback keeps invoking the backend.addToolonly removes an existing tool with the new name. Renaming the tool (viahandle.nameor a fallback toRuleData.name) or moving its selector leaves the previous name registered next to the new one; a later delete then removes only the current name and orphans the old one.Fix
The handler now records the identity it applied per rule —
ToolRegistration(selectorId, serverPath, toolName)— separately from the desired configuration:| Transition | Behaviour |
| --- | --- |
| enabled -> disabled (#8024) | revoke the tracked registration and the cached handle, then keep the disabled snapshot for a later enable |
| renamed:
handle.nameor fallbackRuleData.name(#8025) | revoke the tracked name before registering the new one || selector moved to another server path (#8025) | revoke on the previous path before registering on the new one |
| same-name update | identity unchanged, no revocation;
addToolreplaces the callback as before || duplicate update events | identity unchanged, no repeated
removeTool|| disable / delete after a rename | the tracked identity decides what to remove, not the incoming payload |
| rule never registered against a server | falls back to the previous handle-based behaviour |
|
removeSelector| drops the tracked identities of the removed rules |removeRuleand the new disable path shareunregisterTool, which prefers the tracked identity and falls back to the passed rule data.Tests
Seven regression tests added to
McpServerPluginDataHandlerTest:disablingAnActiveRuleRevokesTheRegisteredTool,reEnablingARuleRegistersTheToolExactlyOnce,disablingARenamedRuleRevokesTheRenamedTool(#8024)renamingACustomToolNameReplacesTheRegistration,renamingThroughTheRuleNameReplacesTheRegistration,sameNameUpdateReplacesWithoutRevocation,movingASelectorRevokesTheToolFromThePreviousServer(#8025)All the transition tests fail against the previous implementation;
sameNameUpdateReplacesWithoutRevocationis the guard that keeps the unchanged path unchanged.