Skip to content

agent: Sanitize MCP server IDs in tool name disambiguation#45789

Merged
bennetbo merged 4 commits intozed-industries:mainfrom
kung-foo:fix/mcp-server-id-sanitization
Feb 12, 2026
Merged

agent: Sanitize MCP server IDs in tool name disambiguation#45789
bennetbo merged 4 commits intozed-industries:mainfrom
kung-foo:fix/mcp-server-id-sanitization

Conversation

@kung-foo
Copy link
Contributor

@kung-foo kung-foo commented Dec 28, 2025

Release Notes:

  • Fixed an issue where a request could fail if an MCP server with names containing whitespace was used

Summary

When multiple MCP servers expose tools with the same name, Zed disambiguates them by prefixing the tool name with the server ID from settings.json. If the server ID contains spaces or special characters (e.g., "Azure DevOps"), the resulting tool name like Azure DevOps_echo violates Anthropic's API pattern ^[a-zA-Z0-9_-]{1,128}$, causing API errors:

"Received an error from the Anthropic API: tools.0.custom.name: String should match pattern '^[a-zA-Z0-9_-]{1,128}$'"

Solution

Convert server IDs to snake_case (using the heck crate already available in the workspace) before using them as prefixes during tool name disambiguation.

Server ID in settings.json Disambiguated Tool Name
"Azure DevOps" azure_dev_ops_echo
"My MCP Server" my_mcp_server_echo

Test plan

  • Added test case for server name with spaces ("Azure DevOps") in test_mcp_tool_truncation
  • Verified existing tests pass
  • Manually tested with two MCP servers having overlapping tool names

After (left), Before (right):

Screenshot_20251228_163249

🤖 Generated with (some) help from Claude Code

@cla-bot
Copy link

cla-bot bot commented Dec 28, 2025

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Jonathan Camp.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

When multiple MCP servers expose tools with the same name, Zed
disambiguates them by prefixing the tool name with the server ID.
If the server ID contains spaces or special characters (e.g.,
"Azure DevOps"), the resulting tool name violates Anthropic's API
pattern `^[a-zA-Z0-9_-]{1,128}$`, causing API errors.

This fix converts server IDs to snake_case before using them as
prefixes, ensuring valid tool names are sent to the API.

Fixes zed-industries#40928

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kung-foo kung-foo force-pushed the fix/mcp-server-id-sanitization branch from 02b22bf to 53a3736 Compare December 28, 2025 15:43
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 28, 2025
@kung-foo kung-foo marked this pull request as ready for review December 28, 2025 15:46
@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Dec 28, 2025
Copy link
Member

@bennetbo bennetbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bennetbo bennetbo enabled auto-merge (squash) February 12, 2026 14:31
@bennetbo bennetbo merged commit 1ea2f2f into zed-industries:main Feb 12, 2026
27 checks passed
@kung-foo kung-foo deleted the fix/mcp-server-id-sanitization branch February 12, 2026 15:06
@kung-foo
Copy link
Contributor Author

np. though I noticed that anthropic recently stopped returning that error when there was a space in the name. so maybe they changed their regex on what is valid? oh well.

@bennetbo
Copy link
Member

Could be, but I think it still makes sense to normalise as other providers might have similar limitations (e.g. OpenAI)

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

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants