apache / apache/shenyu

[BUG] MCP rule removal can leave custom-named tools registered

Open Beginner friendly
#6,473 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Current Behavior

MCP tool registration and removal use different names when the rule handle defines a custom tool name.

During registration, `handlerRule()` prefers the tool name from the rule handle and only falls back to the rule name:

```java
shenyuMcpServerManager.addTool(server.getPath(),
StringUtils.isBlank(mcpServerTool.getName()) ? ruleData.getName() : mcpServerTool.getName(),
...);
```

During removal, `removeRule()` always removes by `ruleData.getName()`:

```java
shenyuMcpServerManager.removeTool(server.getPath(), ruleData.getName());
```

If `mcpServerTool.getName()` differs from `ruleData.getName()`, deleting or updating the rule removes the cache entry but leaves the live MCP server tool registered under the custom name.

### Expected Behavior

Rule removal should remove the same tool name that was used during registration.

### Impact

Renamed/custom-named MCP tools can remain callable after the backing rule is removed or updated, leaving stale tool definitions in the live MCP server.

### Code Location

- `shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandler.java`
- `handlerRule()` registers by handle tool name when present.
- `removeRule()` removes only by `ruleData.getName()`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Read shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandler.java, focusing first on handlerRule() and removeRule(). Trace how custom and fallback tool names are selected, then verify the relevant MCP registration and removal behavior for rule deletion and updates. Done means a custom-named tool is no longer left registered after its rule is removed or updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.