Python: Fix duplicate tool names between supplied tools and MCP servers#4649
Merged
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom Mar 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens tool-name collision detection in the Python Agent Framework by making duplicate tool names fail fast with a ValueError instead of silently deduplicating. It also adds tool_name_prefix support to MCP tools as an escape hatch for legitimate name collisions across MCP servers.
Changes:
- Introduced
_append_unique_tools/_ensure_unique_tool_nameshelpers and moved_get_tool_nameto_tools.py; agent runtime and AG-UI tooling now raise on duplicate tool names instead of silently dropping duplicates. - Added
tool_name_prefixparameter toMCPTooland its transport subclasses, with prefix-aware allowed_tools/approval_mode matching viaadditional_properties. - Added comprehensive test coverage for collision detection, prefixed MCP tools, and updated existing deduplication tests to expect
ValueError.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
_tools.py |
Moved _get_tool_name here; added _append_unique_tools, _ensure_unique_tool_names, _raise_duplicate_tool_name helpers |
_agents.py |
Rewired tool merging to use _append_unique_tools with fail-fast duplicate detection |
_mcp.py |
Added tool_name_prefix support, _build_prefixed_mcp_name, prefix-aware filtering/approval, additional_properties on MCP functions |
_tooling.py (ag-ui) |
Replaced silent dedup with _append_unique_tools in collect_server_tools and merge_tools |
test_agents.py |
Added collision/prefix tests; updated merge_options tests to expect ValueError |
test_mcp.py |
Added tests for prefix construction, prefixed tool/prompt loading |
test_tooling.py |
Updated merge_tools tests to expect ValueError |
script_approval.py |
Removed unnecessary f-string |
You can also share your feedback on Copilot code review. Take the survey.
Contributor
TaoChenOSU
reviewed
Mar 12, 2026
dmytrostruk
approved these changes
Mar 13, 2026
moonbox3
approved these changes
Mar 13, 2026
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.
Motivation and Context
This change closes the remaining tool-name collision paths between supplied tools and MCP-provided tools in the Python Agent Framework. Without an explicit collision check, duplicate names could still reach the final tool map and silently overwrite one another, including approval-sensitive cases.
It also adds a supported escape hatch for MCP users by allowing MCP-exposed tool names to be prefixed when two MCP servers expose the same underlying tool name.
Description
This PR hardens tool assembly before execution so distinct tools with the same exposed name now fail fast instead of silently replacing one another.
The core agent runtime now performs single-pass duplicate-name checks while merging configured tools, runtime tools, and MCP tool expansions. AG-UI applies the same behavior when collecting server tools and merging client tools so approval execution sees a consistent tool set.
On the MCP side,
MCPTooland its transport subclasses now supporttool_name_prefix, and_mcp.pyis responsible for constructing the final exposed MCP tool names. The MCP loader also keepsallowed_toolsand per-tool approval configuration working with prefixed names by storing the original and normalized MCP names inFunctionTool.additional_properties.The PR also adds regression coverage for runtime local/MCP collisions, duplicate names across MCP servers, AG-UI collision handling, and prefixed MCP tool/prompt loading. A small sample cleanup updates
samples/02-agents/skills/script_approval/script_approval.pyto avoid an unnecessary f-string.Contribution Checklist