Repository navigation
Conversation
Registering two tools with the same name silently produced an inconsistent server: the routing dict collapsed the duplicates (last definition wins) while the advertised tools/list kept both entries, and because the advertised entries read from the collapsed schema dict, the first entry paired the first definition's description with the second definition's schema and handler. Reject duplicates with a ValueError at construction so the mistake is caught immediately. Tool names must be unique within a server; the same name on different servers remains fine. Fixes anthropics#1523
This branch has not been deployed
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.
Summary
Fixes #1523.
Registering two tools with the same name silently produced an inconsistent server: the
tools_by_name/schemasrouting dicts collapsed the duplicates (last definition wins) while the advertisedtools/listkept both entries — and because the advertised entries read from the collapsed schema dict, the first entry paired the first definition's description with the second definition's schema and handler. A copy-paste or merge mistake that duplicates a tool name therefore shadows the first tool and advertises a self-contradictory tool list to the model.create_sdk_mcp_servernow rejects duplicates with aValueErrornaming the tool and the server, so the mistake is caught at construction. The same name on different servers remains fine (uniqueness is per-server). Thecreate_sdk_mcp_serverdocstring documents the newRaises:contract.Test plan
test_duplicate_tool_names_are_rejected: two same-named@tooldefinitions raiseValueError: Duplicate tool name 'dup'; verified it fails on unpatchedmain(construction silently succeeds) and passes with the fix on both anyio backends.pytest tests/: 1759 passed, 6 skipped.ruff check,ruff format --check,mypy src/ scripts/all clean.