Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/agents/mcp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,17 @@ async def get_all_function_tools(
agent,
failure_error_function=failure_error_function,
)
server_tool_names = {tool.name for tool in server_tools}
server_tool_name_counts = Counter(tool.name for tool in server_tools)
intra_server_duplicate_tool_names = sorted(
name for name, count in server_tool_name_counts.items() if count > 1
)
if intra_server_duplicate_tool_names:
Comment on lines +280 to +284
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject intra-server duplicates when prefixing

This duplicate-name check only runs after the include_server_in_tool_names branch has already returned, so an MCP server that lists two tools with the same name is still accepted whenever an agent enables server-name prefixing. In that mode the two public tool names can be made unique, but invocation still uses server.call_tool(tool.name, ...), so both wrappers target the same underlying MCP name and the ambiguity this change is trying to reject remains.

Useful? React with 👍 / 👎.

raise UserError(
"Duplicate tool names found within MCP server "
f"'{server.name}': {', '.join(intra_server_duplicate_tool_names)}"
)

server_tool_names = set(server_tool_name_counts)
duplicate_tool_names = sorted(server_tool_names & tool_names)
if duplicate_tool_names:
raise UserError(
Expand Down