feat(mcp): add tool_name_prefix to disambiguate duplicate MCP tool names#3401
Open
adityasingh2400 wants to merge 1 commit into
Open
feat(mcp): add tool_name_prefix to disambiguate duplicate MCP tool names#3401adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withDuplicate tool names found across MCP servers. The existinginclude_server_in_tool_namesagent-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_prefixargument to theMCPServerbase class and theMCPServerStdio,MCPServerSse, andMCPServerStreamableHttpconstructors. When set,list_tools()returns tools namedf"{prefix}_{original_name}"andcall_tool()strips the prefix before dispatching to the upstream MCP server, so the server still receives its original tool name. The internal cache andtool_filtercontinue to operate on the upstream names, andrequire_approvalpolicy 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 raisesUserErrorearly atlist_tools()time rather than failing later.Tests cover the two-servers-with-different-prefixes case, prefix stripping on
call_tool()(both via theFakeMCPServerand an end-to-end check against the realMCPServerStdiowith the MCP client patched), composition withtool_filter, the 64-char overflow error, and cache invariants. Docs indocs/mcp.mdget a short new section showing how to use it. Closes #464.