-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix MCP tool name conflicts by adding server name prefixes #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Problem: - When multiple MCP servers have tools with the same name, agent list MCP would hang - Tool name conflicts made it impossible to distinguish tools from different servers - This caused the agent SDK to malfunction when listing tools Solution: - Add server name prefixes to tool names (e.g., server1_run, server2_run) - Store original tool names in 'original_name' attribute for actual tool calls - Maintain backward compatibility - tool invocation still uses original names - Handle edge cases like empty server names and special characters Changes: - Modified src/agents/mcp/server.py: Added tool name prefixing in list_tools() - Modified src/agents/mcp/util.py: Updated invoke_mcp_tool() to use original names - Enhanced call_tool() to handle both prefixed and original tool names - Added comprehensive logging for debugging This resolves the hanging issue and ensures tools from different servers are properly distinguished while maintaining full backward compatibility.
At a glance, the changes look good to me. Can you resolve the lint and typecheck failures? |
Okay, I'll try it. |
…name and handle both prefixed and original names. Updated invoke_mcp_tool method in util.py to ensure calls are made using original tool names. Added test cases in test_tool_name_conflicts.py to verify the correctness of tool name prefixes and preservation of original names.
Can you check the mypy errors in tests?
|
Ok, I will handle these errors. |
@fadeoreo if you need help, I can fix this. |
There are still lint issues:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea! But we can't just prefix the tool name with server name by default. It should be opt-in (i.e. a param that says prefix_tool_names...
)
Okay, I'll add it and update the code |
Problem
When two MCP servers have tools with the same internal tool name, running
agent list MCP: list tools from server xxxx
will hang, and after the tool list is (supposedly) returned, the agent cannot work properly.During troubleshooting, issues such as network, protocol, registration, or async problems were suspected, but the real cause was that one of the MCP tools had a conflicting tool name, making it impossible for the agent SDK to distinguish between tools from different servers.
Solution
This PR implements server name prefixing for MCP tool names to ensure global uniqueness and avoid conflicts:
{server_name}_{tool_name}
format (e.g.,serverA_run
,serverB_run
)original_name
attribute for actual tool callsChanges Made
Core Implementation
src/agents/mcp/server.py
: Modifiedlist_tools()
method to add server name prefixes and preserve original namessrc/agents/mcp/util.py
: Updatedinvoke_mcp_tool()
to use original names for tool callsTesting
tests/mcp/test_tool_name_conflicts.py
: Comprehensive test suite with 9 test cases covering:Example
Before (Conflict)
Server1: [run, echo]
Server2: [run, list]
Result: ❌ Conflict on 'run' tool name → agent list hangs
After (Resolved)
Server1: [server1_run, server1_echo]
Server2: [server2_run, server2_list]
Result: ✅ All tool names are unique → agent list works correctly
Fixes #1167