Enforce Character limits for MCP tools with Tool API
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3569862. -->
Reported by: [yautja_cetanu](https://www.drupal.org/user/626050)
Related to !45
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p> McpPluginBase::generateToolId() enforces a 64-character limit on tool names for MCP client compatibility. However, MCP clients add their own prefix to tool names. For example, Claude Code prepends mcp__{server-name}__ (10-19+ characters), causing the final tool name to exceed 64 characters and triggering API errors:</p>
<p> messages.2.content.0.tool_result.content.1.tool_reference.tool_name:<br>
String should have at most 64 characters</p>
<p> The longest names come from the ToolApi plugin, which replaces : with ___ (triple underscore). For example:</p>
<p> - Tool API name: ai_agent_agent:add_default_information_tool<br>
- After ToolApi.php:108: ai_agent_agent___add_default_information_tool<br>
- After generateToolId(): tools_ai_agent_agent___add_default_information_tool (52 chars)<br>
- After Claude Code prefix: mcp__drupal-local__tools_ai_agent_agent___add_default_information_tool (69 chars — over<br>
limit)</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>- Install MCP<br>
- Install Tool API<br>
- Set up the binary MCP server<br>
- Try and use the default information tool.</p>
<p><a href="https://www.drupalforge.org/template/visual-flow-builder-agents-flowdrop-ui-drupal-cms">https://www.drupalforge.org/template/visual-flow-builder-agents-flowdrop-ui-drupal-cms</a> - example.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p> Suggested fixes</p>
<p> 1. Reduce the internal character limit in generateToolId() from 64 to ~50, leaving headroom for the client-side prefix.<br>
The docblock already notes this is for client compatibility — a lower limit would account for the prefix clients add.</p>
<p> 2. Use single underscore instead of triple for colon replacement in ToolApi.php:108. Changing str_replace(':', '___',<br>
$name) to str_replace(':', '_', $name) saves 2 characters per colon and is still unambiguous since tool names don't<br>
naturally contain colons.</p>
<p> Workaround</p>
<p> Shorten the MCP server name in the client configuration (e.g., dl instead of drupal-local in .mcp.json).</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue