mcp: enforce 64-char tool name limit after server ID prefixing#133
mcp: enforce 64-char tool name limit after server ID prefixing#133birdayz wants to merge 2 commits into
Conversation
namespaceTool() concatenates serverID + "__" + toolName but never checked the result length. LLM providers (at minimum Bedrock) enforce a 64-character limit on tool names, so names like "servicenow-catalog__delete_api_sn_sc_servicecatalog_cart_by_sys_id_empty" (73 chars) get rejected. Apply the same hash-prefix + tail mangling that protoc-gen-go-mcp already uses: SHA-256 the full name, take 10 base-36 chars as prefix, keep as much of the tail as fits. Deterministic, collision-resistant. Since mangled names can no longer be reversed via TrimPrefix, store the original server tool name on the toolWrapper and look it up in ExecuteTool instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@claude plx review |
Code Review
Overall this looks solid — small, surgical change that addresses a real provider-side problem with a deterministic, well-tested mangling scheme. The wrapper-based reverse lookup is the right call given mangled names are not trivially invertible. A few notes: 1. Entropy comment is off by ~18 bits (cosmetic but misleading)
10 base36 chars carry up to 2. Silent collision in
|
What
Enforce the 64-character tool name limit in the MCP client's
namespaceTool()by mangling names that exceed the limit after theserverID__prefix is applied.Why
namespaceTool()concatenatesserverID__toolNamewithout checking length. LLM providers (at minimum Bedrock) reject tool names exceeding 64 characters. protoc-gen-go-mcp already mangles proto-generated names to 64 chars, but the server ID prefix pushes them right back over:servicenow-catalog__delete_api_sn_sc_servicecatalog_cart_by_sys_id_empty(73 chars)servicenow-catalog__post_api_sn_sc_servicecatalog_items_by_sys_id_versioning_checkout(85 chars)Implementation details
Reuses the same mangling algorithm from protoc-gen-go-mcp: SHA-256 the full name, take 10 base-36 chars as a deterministic hash prefix, keep as much of the tail (the most human-readable part) as fits within 64 chars.
Names within the limit pass through unchanged -- zero behavioral change for short names.
Since mangled names cannot be reversed via
strings.TrimPrefix,toolWrappernow stores the original server tool name.ExecuteTool()looks it up from the wrapper, falling back toTrimPrefixfor direct API callers.References
AI-1106