Skip to content

feat(mcp): add tool_name_prefix to disambiguate duplicate MCP tool names#3401

Open
adityasingh2400 wants to merge 1 commit into
openai:mainfrom
adityasingh2400:fix-mcp-tool-name-prefix
Open

feat(mcp): add tool_name_prefix to disambiguate duplicate MCP tool names#3401
adityasingh2400 wants to merge 1 commit into
openai:mainfrom
adityasingh2400:fix-mcp-tool-name-prefix

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

When two MCP servers expose tools with the same name (e.g. both a GitHub and a Linear server expose create_issue), wiring both into an agent fails with Duplicate tool names found across MCP servers. The existing include_server_in_tool_names agent-level flag auto-generates a server-derived prefix, but users have no way to pick a short, friendly prefix per server – the original ask in the issue.

This PR adds an optional keyword-only tool_name_prefix argument to the MCPServer base class and the MCPServerStdio, MCPServerSse, and MCPServerStreamableHttp constructors. When set, list_tools() returns tools named f"{prefix}_{original_name}" and call_tool() strips the prefix before dispatching to the upstream MCP server, so the server still receives its original tool name. The internal cache and tool_filter continue to operate on the upstream names, and require_approval policy lookups continue to match the original tool name even with a prefix configured. A prefixed name that would exceed the 64-character MCP tool-name limit raises UserError early at list_tools() time rather than failing later.

Tests cover the two-servers-with-different-prefixes case, prefix stripping on call_tool() (both via the FakeMCPServer and an end-to-end check against the real MCPServerStdio with the MCP client patched), composition with tool_filter, the 64-char overflow error, and cache invariants. Docs in docs/mcp.md get a short new section showing how to use it. Closes #464.

Adds an optional keyword-only `tool_name_prefix` argument to `MCPServer`,
`_MCPServerWithClientSession`, and the `MCPServerStdio`, `MCPServerSse`, and
`MCPServerStreamableHttp` constructors. When set, `list_tools()` returns tools
named `f"{prefix}_{original_name}"`, `call_tool()` strips the prefix before
dispatching upstream, and `require_approval` policy lookups continue to match
the original tool name. The internal cache and `tool_filter` still operate on
the upstream tool names. Raises `UserError` early when a prefixed name would
exceed the 64-character MCP tool-name limit.

Closes openai#464
@seratch seratch added the duplicate This issue or pull request already exists label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate tool names across MCP servers cause errors

2 participants