Skip to content

fix: reject duplicate tool names in create_sdk_mcp_server - #1567

Open
doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/sdk-mcp-duplicate-tool-names
Open

doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/sdk-mcp-duplicate-tool-names

Conversation

@doge-th

@doge-th doge-th commented Nov 21, 2026

Copy link
Copy Markdown

Summary

Fixes #1523.

Registering two tools with the same name silently produced an inconsistent server: the tools_by_name/schemas routing dicts 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. 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_server now rejects duplicates with a ValueError naming the tool and the server, so the mistake is caught at construction. The same name on different servers remains fine (uniqueness is per-server). The create_sdk_mcp_server docstring documents the new Raises: contract.

Test plan

  • Added test_duplicate_tool_names_are_rejected: two same-named @tool definitions raise ValueError: Duplicate tool name 'dup'; verified it fails on unpatched main (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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate MCP tool names collapse routing while tools/list keeps both entries

1 participant