Skip to content

fix: improve MCP server plugin path handling and backward compatibility for argsPosition#6293

Open
Aias00 wants to merge 6 commits intomasterfrom
fix/fix_mcp_server_plugin
Open

fix: improve MCP server plugin path handling and backward compatibility for argsPosition#6293
Aias00 wants to merge 6 commits intomasterfrom
fix/fix_mcp_server_plugin

Conversation

@Aias00
Copy link
Contributor

@Aias00 Aias00 commented Feb 9, 2026

improve MCP server plugin path handling and backward compatibility for argsPosition

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

Copilot AI review requested due to automatic review settings February 9, 2026 11:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nested argsPosition.
  • Rework MCP server path handling (normalization, route registration, supported-protocol lookup) and update tests to match the new path semantics.
  • Ensure ShenyuMcpExchangeHolder entries 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.

Comment on lines 121 to 127
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);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Aias00 and others added 5 commits February 10, 2026 10:39
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments