← Back to Pull requests

fix(mcp-server): revoke MCP tool registrations by their applied identity #8032

Merged
imDwAaY merged 2 files (239 lines) on Oct 24, 2026 03:31 UTC
View on GitHub
imDwAaY imDwAaY commented on Oct 23, 2026 06:42 UTC
Author

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

  • #8024 — rule updates arrive through handlerRule, and registerTool returns immediately when enabled=false. A tool registered while the rule was enabled stays in the SDK server and in CACHED_TOOL, and its retained callback keeps invoking the backend.

  • #8025 — addTool only removes an existing tool with the new name. Renaming the tool (via handle.name or a fallback to RuleData.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.name or fallback RuleData.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; addTool replaces 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 |

    removeRule and the new disable path share unregisterTool, 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; sameNameUpdateReplacesWithoutRevocation is the guard that keeps the unchanged path unchanged.

    ./mvnw -pl shenyu-plugin/shenyu-plugin-mcp-server test   # 154 tests, 0 failures (JDK 17)
    ./mvnw -pl shenyu-plugin/shenyu-plugin-mcp-server checkstyle:check
    

    Diff: 239 lines (+229 / -10) across 2 files Reviewer: Aias00 Review duration: 1248m
    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
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.35 · 1 substantive comment(s)
    0.35
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    63%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Aias00 Aias00 approved these changes on Oct 23, 2026 14:21 UTC
    Approved Reviewer

    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 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.

  • Dropping the 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.

    Reviewers
    Assignees
    imDwAaY imDwAaY
    Labels
    risk: low confidence: 63.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.2% (MEDIUM) · Higher = larger blast radius
    37.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 63.7% · Lower = rushed or shallow review
    63.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.5% · Safe to merge
    13.5%
    Repository