You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Registering a tool with an existing name silently replaces the existing tool (no error, no log), including MCP tools shadowing local tools #3328
Describe the bug
Registering a tool whose name is already registered silently replaces the existing tool. ToolRegistry.registerTool just does tools.put(toolName, tool): no exception, no log. The toolkit ends up with only the last tool under that name, its description and schema are what the model sees, and it is what gets executed.
This matters most for MCP. MCP tools are registered after the agent's own tools, so with prefixToolNames off, a remote tool that happens to share a name with a local tool silently takes its place. Anything keyed by tool name (permission rules, tool groups, confirmation handling) then applies to the remote tool instead of the local one, and nothing tells the developer. The same happens when two local tool classes declare the same @Tool name.
Verified on 2.0.3; ToolRegistry.registerTool is unchanged on main (857e3e6).
Expected behavior
Registering a duplicate name should fail fast (e.g. IllegalStateException naming both tools), or at least log a warning, with an explicit API for intentional replacement. For MCP, a name clash with an existing tool should be reported when the server's tools are registered, so the developer can enable prefixToolNames or rename.
Environment
AgentScope-Java 2.0.3 and main (857e3e6), JDK 21.
Category: bug | Status: Confirmed (verified against main)
The silent last-write-wins behaviour is real. Evidence from the current code:
ToolRegistry.registerTool (agentscope-core/src/main/java/io/agentscope/core/tool/ToolRegistry.java, the tools.put(...) / registeredTools.put(...) block) performs only a null/blank-name check — no duplicate detection, no warning, no explicit replace API.
Every registration path funnels through the private Toolkit.registerAgentTool (Toolkit.java), which logs INFO "Registered tool ..." identically for a first registration and a replacement. So there is a success log, but nothing indicates that an existing tool was overwritten — the "no log" part of the report is slightly imprecise, the underlying problem is not.
Contrast within the same subsystem: ToolGroupManager.createToolGroup does fail fast (IllegalArgumentException("Tool group '%s' already exists")). The tool layer simply does not.
MCP path confirmed: McpClientManager.registerMcpClient builds the tool key as toolNamePrefix + mcpTool.name(), and McpServerRegistrar.registerClient only applies the <name>__ prefix when cfg.isPrefixToolNames(). McpServerConfig.prefixToolNames defaults to false.
Ordering claim confirmed: HarnessAgent.Builder.build() registers all local/harness tools first and runs McpServerRegistrar.register afterwards, so by default a same-named remote MCP tool replaces the local tool.
Impact
Both the tools and registeredTools entries are replaced, so RegisteredToolFunction metadata (preset parameters, extended model, mcpClientName) and group wiring silently move to the winning tool.
ToolExecutor resolves by name at call time, so permission rules, tool groups and confirmation/HITL handling keyed by tool name end up applying to the remote implementation. With an untrusted MCP server exposing generic names (read_file, shell, search), this is a real integrity risk, not just an ergonomic one.
Stale group state: the old name→group mapping stays in ToolGroupManager while the registry holds a different tool, so schema visibility can diverge from the executed implementation.
Severity: high
Suggested direction (important caveat)
A plain throw on duplicate is not safe as-is, because same-name re-registration is relied on today:
Toolkit.copy() → copy.registerMetaTool() re-registers reset_equipped_tools after ToolRegistry.copyTo already copied it — production path, hit on every copy of a toolkit that has the meta tool (also ReActAgent.Builder.build() / toBuilder(), HarnessAgent.Builder.build()).
ToolkitTest.removeToolIfSame_noOpWhenReplaced asserts that the second registration wins, i.e. replacement is an explicitly contracted behaviour.
SkillToolFactory.registerRuntimeLoadTool and SkillBox.registerSkillLoadTool already work around the overwrite with their own existence checks.
McpServerRegistrar.registerClient would re-register identical MCP names if register were ever re-invoked on the same toolkit (reload/reconnect).
A change that keeps those paths working: detect an existing different instance at registration time, logger.warn naming both tools (old class → new class, plus the MCP server for MCP registrations), and add an explicit replace API/flag that the intentional re-registration paths above opt into. Report MCP-vs-local name clashes at MCP registration time so users can enable prefixToolNames or rename.
Maintainers: before any PR is generated, please confirm the intended contract — is silent replacement of a same-named tool a supported feature (as removeToolIfSame_noOpWhenReplaced suggests) or an accident to be closed?
Activity
amyaxy commentedon Sep 28, 2026
I can fix this. I'll submit a PR soon.
oss-maintainer commentedon Sep 28, 2026
Issue Evaluation
Category:
bug| Status: Confirmed (verified againstmain)The silent last-write-wins behaviour is real. Evidence from the current code:
ToolRegistry.registerTool(agentscope-core/src/main/java/io/agentscope/core/tool/ToolRegistry.java, thetools.put(...)/registeredTools.put(...)block) performs only a null/blank-name check — no duplicate detection, no warning, no explicit replace API.Toolkit.registerAgentTool(Toolkit.java), which logsINFO "Registered tool ..."identically for a first registration and a replacement. So there is a success log, but nothing indicates that an existing tool was overwritten — the "no log" part of the report is slightly imprecise, the underlying problem is not.ToolGroupManager.createToolGroupdoes fail fast (IllegalArgumentException("Tool group '%s' already exists")). The tool layer simply does not.McpClientManager.registerMcpClientbuilds the tool key astoolNamePrefix + mcpTool.name(), andMcpServerRegistrar.registerClientonly applies the<name>__prefix whencfg.isPrefixToolNames().McpServerConfig.prefixToolNamesdefaults tofalse.HarnessAgent.Builder.build()registers all local/harness tools first and runsMcpServerRegistrar.registerafterwards, so by default a same-named remote MCP tool replaces the local tool.Impact
toolsandregisteredToolsentries are replaced, soRegisteredToolFunctionmetadata (preset parameters, extended model,mcpClientName) and group wiring silently move to the winning tool.ToolExecutorresolves by name at call time, so permission rules, tool groups and confirmation/HITL handling keyed by tool name end up applying to the remote implementation. With an untrusted MCP server exposing generic names (read_file,shell,search), this is a real integrity risk, not just an ergonomic one.ToolGroupManagerwhile the registry holds a different tool, so schema visibility can diverge from the executed implementation.Severity: high
Suggested direction (important caveat)
A plain
throwon duplicate is not safe as-is, because same-name re-registration is relied on today:Toolkit.copy()→copy.registerMetaTool()re-registersreset_equipped_toolsafterToolRegistry.copyToalready copied it — production path, hit on every copy of a toolkit that has the meta tool (alsoReActAgent.Builder.build()/toBuilder(),HarnessAgent.Builder.build()).ToolkitTest.removeToolIfSame_noOpWhenReplacedasserts that the second registration wins, i.e. replacement is an explicitly contracted behaviour.SkillToolFactory.registerRuntimeLoadToolandSkillBox.registerSkillLoadToolalready work around the overwrite with their own existence checks.McpServerRegistrar.registerClientwould re-register identical MCP names ifregisterwere ever re-invoked on the same toolkit (reload/reconnect).A change that keeps those paths working: detect an existing different instance at registration time,
logger.warnnaming both tools (old class → new class, plus the MCP server for MCP registrations), and add an explicit replace API/flag that the intentional re-registration paths above opt into. Report MCP-vs-local name clashes at MCP registration time so users can enableprefixToolNamesor rename.Maintainers: before any PR is generated, please confirm the intended contract — is silent replacement of a same-named tool a supported feature (as
removeToolIfSame_noOpWhenReplacedsuggests) or an accident to be closed?Automated evaluation by github-manager-bot
fix(tool): fail fast on duplicate tool registration instead of silent…
fix(tool): fail fast on duplicate tool registration instead of silent…
fix(tool): fail fast on duplicate tool registration instead of silent…
fix(tool): fail fast on duplicate tool registration instead of silent…
fix(tool): fail fast on duplicate tool registration instead of silent…