fix(mcp-utils): cap gateway tool name slugs to prevent 128-char limit#3103
Open
viktormarinho wants to merge 1 commit intomainfrom
Open
fix(mcp-utils): cap gateway tool name slugs to prevent 128-char limit#3103viktormarinho wants to merge 1 commit intomainfrom
viktormarinho wants to merge 1 commit intomainfrom
Conversation
…imit MCP clients like Claude Code prepend their own prefix (e.g. mcp__cms__) to tool names. Combined with long connection ID slugs, this exceeded the 128-character tool name limit enforced by Anthropic's API. Cap the slug portion to 32 characters so the full namespaced name stays within limits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
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.
What is this contribution about?
MCP clients like Claude Code prepend their own prefix to tool names (e.g.
mcp__cms__). When combined with long connection ID slugs fromGatewayClient.namespace(), the total tool name exceeded the 128-character limit enforced by Anthropic's API, causing400 invalid_request_errorfor Claude Code users.This adds a
capSlug()function that truncates the slug portion of namespaced tool names to 32 characters. Proxied AI providers already went throughsanitizeToolName()which truncates to 128 chars, but direct MCP clients (Claude Code, Codex) received raw untruncated names. Normal connection IDs (conn_<nanoid>≈ 26 chars slugified) are unaffected.How to Test
Review Checklist
Summary by cubic
Caps gateway tool name slugs to 32 characters in
mcp-utilsso full tool names stay under Anthropic’s 128-char limit. Fixes 400 errors in Claude Code and other MCP clients when connection IDs are long.capSlug()andMAX_SLUG_LENGTH = 32; applied when generating slugs inGatewayClientand when stripping namespaces.keyToSlugmap; exportscapSlugfrom the aggregate index.Written for commit 6160129. Summary will update on new commits.