fix(tools): keep MCP tool names unique for non-ASCII inputs - #5360
Open
yancyyan058 wants to merge 2 commits into
Open
fix(tools): keep MCP tool names unique for non-ASCII inputs#5360yancyyan058 wants to merge 2 commits into
yancyyan058 wants to merge 2 commits into
Conversation
_sanitize_name collapsed fully non-ASCII names (e.g. Chinese) to a single "_", causing silent registration collisions. Fall back to a deterministic SHA-1-based name when the sanitized result is all underscores, and cover the fallback with regression tests. Co-Authored-By: Claude <noreply@anthropic.com>
The previous fallback only fired for fully non-ASCII names, but the real
call path always prepends ``mcp_{server}_``, so Chinese tool names still
collapsed to ``mcp_server_`` and collided. Detect non-ASCII anywhere in
the name and append a deterministic digest to the stripped core.
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Problem
_sanitize_namereplaces every character outside[a-zA-Z0-9_-]with_.A fully non-ASCII name such as
"获取天气"collapses to"_"after sanitization,causing silent name collisions when multiple such tools are registered from the
same MCP server.
Changes
_short_digest(value, length)to consolidate the repeatedhashlib.sha1pattern shared by_limit_tool_nameand the new fallback path._sanitize_mcp_tool_name: when sanitization produces anall-underscore result, return
tool_<8-char sha1 hex>instead._sanitize_nameand_limit_tool_nameare unchanged.Behavior
"获取天气""_""tool_a3f9c21b""日本語ツール""_""tool_8704490a""get_weather""get_weather""get_weather""My Tool""My_Tool""My_Tool"Related
Touches the same area as #3468 (spaces in MCP resource/prompt names), but
addresses a distinct failure mode: fully non-ASCII names that sanitize to
a single underscore rather than an invalid character.