fix: improve MCP server plugin path handling and backward compatibility for argsPosition#6293
fix: improve MCP server plugin path handling and backward compatibility for argsPosition#6293
Conversation
…ty for argsPosition
There was a problem hiding this comment.
Pull request overview
This PR improves MCP server path normalization/registration in the gateway plugin, adds backward compatibility for nested argsPosition configs (while making root-level argsPosition canonical), and tightens session cleanup to avoid leaking exchange references.
Changes:
- Add backward-compatible parsing for nested
requestTemplate.argsPosition, and update the MCP client generator to emit both root-level and nestedargsPosition. - Rework MCP server path handling (normalization, route registration, supported-protocol lookup) and update tests to match the new path semantics.
- Ensure
ShenyuMcpExchangeHolderentries are removed when SSE/Streamable HTTP sessions are closed/shutdown.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelper.java | Adds fallback parsing for nested argsPosition. |
| shenyu-client/shenyu-client-mcp/shenyu-client-mcp-common/src/main/java/org/apache/shenyu/client/mcp/generator/McpRequestConfigGenerator.java | Generates canonical root-level argsPosition and keeps nested form for compatibility. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java | Updates normalization + route registration logic; adds helpers for joining/normalizing paths. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandler.java | Normalizes selector paths and uses normalized paths when creating/removing servers/transports. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/transport/ShenyuSseServerTransportProvider.java | Cleans ShenyuMcpExchangeHolder on cancel/dispose and during graceful shutdown. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/transport/ShenyuStreamableHttpServerTransportProvider.java | Cleans ShenyuMcpExchangeHolder when removing sessions. |
| shenyu-client/shenyu-client-mcp/shenyu-client-mcp-register/src/main/java/org/apache/shenyu/client/mcp/McpServiceEventListener.java | Avoids AIOOBE when no servers[]; uses merged URL for metadata path. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/test/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelperTest.java | Adds coverage for nested argsPosition compatibility. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/test/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManagerTest.java | Updates expectations to match new path normalization behavior. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/test/java/org/apache/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandlerTest.java | Updates expected transport/server paths (no /** passed to manager). |
| shenyu-plugin/shenyu-plugin-mcp-server/src/test/java/org/apache/shenyu/plugin/mcp/server/McpServerPluginIntegrationTest.java | Updates integration assertions to use the normalized server path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...er/src/main/java/org/apache/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandler.java
Show resolved
Hide resolved
...server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java
Show resolved
Hide resolved
| public void handlerRule(final RuleData ruleData) { | ||
| if (Objects.isNull(ruleData)) { | ||
| return; | ||
| } | ||
| Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> { | ||
| ShenyuMcpServerTool mcpServerTool = GsonUtils.getInstance().fromJson(s, ShenyuMcpServerTool.class); | ||
| CACHED_TOOL.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData), mcpServerTool); |
There was a problem hiding this comment.
handlerRule now guards against ruleData == null, but it can still call addTool(server.getPath(), ...) later with a null/blank server.getPath() (e.g., selector had no URI condition or cached server path is empty). That can throw inside ShenyuMcpServerManager (ConcurrentHashMap null key). Consider also gating tool registration on server != null && StringUtils.isNotBlank(server.getPath()) (consistent with the removeRule check).
…e/shenyu/plugin/mcp/server/handler/McpServerPluginDataHandler.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…e/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
improve MCP server plugin path handling and backward compatibility for argsPosition
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.