Skip to content

fix(mcp-utils): cap gateway tool name slugs to prevent 128-char limit#3103

Open
viktormarinho wants to merge 1 commit intomainfrom
viktormarinho/fix-long-tool-name
Open

fix(mcp-utils): cap gateway tool name slugs to prevent 128-char limit#3103
viktormarinho wants to merge 1 commit intomainfrom
viktormarinho/fix-long-tool-name

Conversation

@viktormarinho
Copy link
Copy Markdown
Contributor

@viktormarinho viktormarinho commented Apr 10, 2026

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 from GatewayClient.namespace(), the total tool name exceeded the 128-character limit enforced by Anthropic's API, causing 400 invalid_request_error for 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 through sanitizeToolName() 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

  1. Create a Virtual MCP with connections that have long IDs
  2. Connect Claude Code to the Virtual MCP endpoint
  3. Verify tool calls succeed without 128-char API errors

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • No breaking changes

Summary by cubic

Caps gateway tool name slugs to 32 characters in mcp-utils so 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.

  • Bug Fixes
    • Added capSlug() and MAX_SLUG_LENGTH = 32; applied when generating slugs in GatewayClient and when stripping namespaces.
    • Ensures consistent truncated slugs via an internal keyToSlug map; exports capSlug from the aggregate index.
    • Added tests for slug truncation, namespace stripping with long IDs, and correct tool routing with truncated slugs.

Written for commit 6160129. Summary will update on new commits.

…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>
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

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.

1 participant