Sean-Walker0 opened a new pull request, #7493:
URL: https://github.com/apache/shenyu/pull/7493
Fixes #7472
## Modifications
`McpServerPluginDataHandler#handlerSelector` overwrote the cached server
handle and created transports for the new path, but the server registered under
the **previous** path was never removed (`removeMcpServer` was only called from
`removeSelector`). After an MCP selector update from `/mcp/old/**` to
`/mcp/new/**`, the old path's server, routes and transports stayed alive and
the old endpoint kept serving sessions.
Before replacing the cached handle, the previous server is looked up and —
when its path differs from the new one — closed via the existing
`removeMcpServer` path:
```java
ShenyuMcpServer previousServer =
CACHED_SERVER.get().obtainHandle(selectorData.getId());
if (Objects.nonNull(previousServer) &&
StringUtils.isNotBlank(previousServer.getPath())
&& !previousServer.getPath().equals(path) &&
shenyuMcpServerManager.hasMcpServer(previousServer.getPath())) {
shenyuMcpServerManager.removeMcpServer(previousServer.getPath());
}
```
## Verifying this change
- [x] New
`McpServerPluginDataHandlerTest#testHandlerSelectorPathUpdateRemovesPreviousServer`
— a selector cached at `/mcp/old` is updated to `/mcp/new/**` and the old
server must be removed. Red on the pre-fix code (`Wanted but not invoked:
removeMcpServer`), green after.
- [x] `./mvnw -pl shenyu-plugin/shenyu-plugin-mcp-server -am test -B` —
103/103 module tests green, checkstyle clean.
## Notes
- Behavior change: only when a selector's path actually changes — the stale
endpoint is closed instead of remaining live; same-path updates and creations
are unchanged.
- Known follow-up (out of scope, disclosed): tools registered under the old
server are removed with it; they are re-registered onto the new server only
when the rule update events arrive, which matches the issue's second
observation. Migrating cached tools on a path change needs a selector-scoped
tool cache iteration and is better addressed separately.
- Orthogonality: no open PR modifies `McpServerPluginDataHandler` (verified
against the file lists of all 99 open PRs).
Make sure that:
- [x] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your
changes.
- [x] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true` (module-scoped:
`shenyu-plugin/shenyu-plugin-mcp-server` with `-am`, tests + checkstyle green).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]