Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
fadeoreo wants to merge1 commit intoopenai:main
base:main
Choose a base branch
Loading
fromfadeoreo:Fix_mcps_tools_with_the_same_name

Conversation

fadeoreo
Copy link

Problem

When two MCP servers have tools with the same internal tool name, runningagent 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:

  1. Prefixes tool names with server name: Tool names are prefixed with{server_name}_{tool_name} format (e.g.,serverA_run,serverB_run)
  2. Preserves original names: The original tool name is stored in theoriginal_name attribute for actual tool calls
  3. Maintains backward compatibility: Tool invocation still uses the original name when calling the MCP server

Changes Made

Core Implementation

  • src/agents/mcp/server.py: Modifiedlist_tools() method to add server name prefixes and preserve original names
  • src/agents/mcp/util.py: Updatedinvoke_mcp_tool() to use original names for tool calls

Testing

  • tests/mcp/test_tool_name_conflicts.py: Comprehensive test suite with 9 test cases covering:
    • Basic prefixing functionality
    • Multiple server conflict resolution
    • MCPUtil integration
    • Legacy behavior regression testing
    • Edge cases (empty names, special characters)
    • Tool invocation verification

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

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 toolsSolution:- 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 charactersChanges:- 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 debuggingThis resolves the hanging issue and ensures tools from different serversare properly distinguished while maintaining full backward compatibility.
@seratchseratch added enhancementNew feature or request feature:mcp labelsJul 18, 2025
@seratch
Copy link
Member

At a glance, the changes look good to me. Can you resolve the lint and typecheck failures?

@fadeoreo
Copy link
Author

Okay, I'll try it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
enhancementNew feature or requestfeature:mcp
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Please fix the issue where duplicate tool names in multiple MCP tools cause the agent list to hang
2 participants
@fadeoreo@seratch

[8]ページ先頭

©2009-2025 Movatter.jp