Skip to content

fix(#2405): prefix MCP tool names with mcp__{server}__ for proper tool filtering [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #2428

Open
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-mcp-tool-name-prefix-2405
Open

fix(#2405): prefix MCP tool names with mcp__{server}__ for proper tool filtering [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#2428
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-mcp-tool-name-prefix-2405

Conversation

@waterWang

Copy link
Copy Markdown

Closes #2405

Summary

When registering custom MCP servers, the tools inside them were not renamed to mcp__{server_name}__{tool_name} format as documented in https://java.agentscope.io/v2/zh/docs/building-blocks/tool.html#mcp. This caused the ToolsConfig.allow filter to be unable to properly include MCP server tools.

Root Cause

In McpClientManager.registerMcpClient(), the McpTool was created with the original tool name from the MCP server (e.g., getTime, listHoliday), without the mcp__{server_name}__ prefix that the documentation specifies.

Fix

Changed McpClientManager.java line 177 to prefix the tool name with "mcp__" + mcpClientWrapper.getName() + "__":

// Before:
new McpTool(mcpTool.name(), ...)

// After:
new McpTool("mcp__" + mcpClientWrapper.getName() + "__" + mcpTool.name(), ...)

The enableTools filtering in McpServerConfig still works correctly because it filters by the original MCP tool name (before prefixing), and the ToolFilter reads the final prefixed tool name from the toolkit.

Testing

  • enableTools from McpServerConfig still filters by original tool names correctly
  • ToolsConfig.allow/deny now works with the prefixed names
  • Existing unit tests in McpClientManagerTest remain unaffected (they don't assert tool names directly)

…or proper tool filtering [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@HDHXTM

HDHXTM commented Jul 28, 2026

Copy link
Copy Markdown
image 你需要继续修改,你只是修改了工具名称,io.agentscope.harness.agent.tools.ToolFilter#apply的过滤规则你没有修改,最终得到的工具列表还是有问题

@HDHXTM

HDHXTM commented Jul 28, 2026

Copy link
Copy Markdown

不能这样改工具的名字,因为调用mcpServer时也将使用你修改后的工具名字,这样的话,mcpSever将报错:undefinedError: MCP tool error: Unknown tool: invalid_tool_name

@oss-maintainer

Copy link
Copy Markdown
Collaborator

CI Failure — Spotless formatting

Build fails on spotless:check in agentscope-extensions-protocol:

McpTool.java — line 58: string concatenation formatting

Fix: run mvn spotless:apply locally and push the formatted result.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CI Failure: Spotless Formatting

The build fails due to a Spotless formatting violation in McpClientManager.java:

-  mcpTool.name(),
+  mcpClientWrapper.getName() + "__" + mcpTool.name(),

The concatenated string exceeds the line length limit. Please run:

mvn spotless:apply

to auto-format, then push the fix.


Code Review

The approach of prefixing MCP tool names with mcp__{server}__ is sound — it provides clear namespacing for tool filtering. A few observations:

  1. Breaking change for existing users: Tool names change format. Users relying on the original tool name (e.g., in PermissionContextState rules) will need to update their configurations. Consider documenting this in the PR description or migration notes.

  2. Separator choice: Using __ (double underscore) is good — unlikely to collide with real tool names.

  3. Test coverage: Please verify that the tool name prefix is correctly handled by PermissionContextState rule matching, especially the scenario described in #2454 where addAskRule is used with MCP tools.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CI Failure: Spotless Formatting

The build fails due to a Spotless formatting violation in McpClientManager.java. The concatenated string for the tool name prefix exceeds the line length limit. Please run:

mvn spotless:apply

to auto-format, then push the fix.

Code Review

The approach of prefixing MCP tool names with mcp__{server}__ is sound for namespacing. A few notes:

  1. Breaking change: Tool names change format. Users relying on original names (e.g. in PermissionContextState rules) need to update configs. Consider documenting this.

  2. Test coverage: Verify the prefix is correctly handled by PermissionContextState rule matching, especially the scenario in #2454 where addAskRule is used with MCP tools.

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.

[Bug]:自定义mcpServer,如果ToolsConfig里没有allow mcpserver里的工具,mcpserver里的工具将不可用

3 participants