Repository navigation
fix(mcp): overlong minted MCP tool names no longer 400 every turn on strict providers (#81331, salvage #81417) - #92659
Conversation
૮ >ﻌ< ა ci reviewran on d0b0c45 — fix(mcp): clamp generated MCP tool names to 64 chars
|
Overall: correct fix for a nasty failure mode (one overlong name poisoning the whole tools array on strict providers) — deterministic SHA-256 suffix keeps registry names stable across sessions, the length arithmetic (
|
Portable Agent Plugin packages fold the plugin name into the MCP registry name three times over (slug, digest, and again as the server key), so mcp__<server>__<tool> routinely exceeds the 64-char function name limit OpenAI-compatible providers enforce — while the same server registered via `hermes mcp add` stays well under it. The oversized name is never rejected loudly; the tool just becomes unreachable. Clamp mcp_prefixed_tool_name() to 64 chars with a deterministic, collision- safe hash suffix, mirroring the existing property-key clamp in schema_sanitizer.py. Dispatch is unaffected since handlers already close over the original unprefixed tool name. Fixes #81331
820c9b7 to
d0b0c45
Compare
Summary
MCP tool names longer than 64 chars no longer make OpenAI-compatible providers reject the whole request with HTTP 400 —
mcp_prefixed_tool_name()now clamps overlong names deterministically with a stable hash suffix.Salvage of #81417 by @chelsealong (cherry-picked, authorship preserved), whose fix independently matches the same mechanism oh-my-pi shipped this week for the identical bug (can1357/oh-my-pi#9131:
chrome-devtools-mcp'sperformance_analyze_insightminted a 68-char name and every turn failed withname must be at most 64 characters).Root cause:
mcp__<server>__<tool>minting had no length cap while OpenAI/Meta Responses validate function names against^[a-zA-Z0-9_-]{1,64}$. Portable Agent Plugin server keys embed the plugin name three times, so their minted names routinely overflow (#81331). Hermes already fixed the sibling defect for Codexcall_ids (#73492) — this closes the tool-name half.Changes
tools/mcp_tool.py:mcp_prefixed_tool_name()clamps names >64 chars to a readable prefix +_<8-hex sha256>suffix; deterministic across processes, distinct long names never collide. Warning logged when clamping fires. All mint sites (tool schemas, resource/prompt utility tools) go through this one choke point.tests/tools/test_mcp_tool.py: clamp length, determinism, and collision tests.Validation
^[a-zA-Z0-9_-]{1,64}$-validtests/tools/test_mcp_tool.pyE2E: real
mcp_prefixed_tool_nameimport, regex-validated output against the provider pattern, determinism + uniqueness asserted.Related open PRs covering adjacent surfaces (not superseded): #54881/#90016 (Bedrock adapter aliasing), #35843 (chat-completions-side truncation — broader, unfocused), #15617 (older single-underscore-era equivalent of this fix).
Infographic