Repository navigation
fix(mcp-server): revoke MCP tool registrations by their applied identity - #8032
Merged
yuluo-yx merged 1 commit intoOct 24, 2026
Merged
Conversation
…by their applied identity
Aias00
approved these changes
Oct 23, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
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:
- The enabled → disabled transition is caught via
previousbeforerules.putoverwrites it, andisRegistered(previous)makes repeated disabled updates a no-op, soremoveToolcannot fire twice. ThereEnablingARuleRegistersTheToolExactlyOncetest pins exactly that. - Dropping the
registrationsentry inremoveSelectorwithout callingremoveToolis safe: the method ends withshenyuMcpServerManager.removeMcpServer(path), which takes the tools with the server. Worth a one-line comment next toregistrations.remove(...), because the invariant lives 9 lines below and is not obvious at that point. removeRulenow delegates tounregisterTool, 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.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:handle.nameor fallbackRuleData.name(#8025)addToolreplaces the callback as beforeremoveToolremoveSelectorremoveRuleand 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([BUG] Disabling an active MCP rule leaves its tool registered and callable #8024)renamingACustomToolNameReplacesTheRegistration,renamingThroughTheRuleNameReplacesTheRegistration,sameNameUpdateReplacesWithoutRevocation,movingASelectorRevokesTheToolFromThePreviousServer([BUG] Renaming an MCP rule tool leaves the previous tool name registered #8025)All the transition tests fail against the previous implementation;
sameNameUpdateReplacesWithoutRevocationis the guard that keeps the unchanged path unchanged.