Tool names easily exceed Claude Code's 64-character limit due to MD5 hash appending

Created on 7 June 2025, about 8 hours ago

Problem/Motivation

Not exactly a bug per se, but still annoying developement experience. But also I'm questioning the way that security is implemented here, however I parked those remarks in a comment here: 📌 Security improvements Active .

Claude Code enforces a 64-character limit for MCP tool names, but the current MCP module's tool naming scheme can easily exceed this limit when combined with Claude Code's prefixing system.

The issue occurs because:
1. The MCP module appends a 32-character MD5 hash to tool names in `src/Plugin/McpJsonRpc/ToolsList.php` at line 38:
```php
name: $instance->getPluginId() . '_' . md5($tool->name),
```
2. Claude Code adds its own prefix: `mcp____`
3. The combined length often exceeds Claude Code's 64-character limit

This results in API errors like:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools.15.custom.name: String should have at most 64 characters"}}

The docs currently state about the tool id:

Tool IDs
When the MCP module exposes tools to clients, it prefixes the tool name with the plugin ID and uses MD5 hash for security. In your executeTool() method, compare the incoming ID with the MD5 hash of your tool name.

The MD5 hash generation happens in the `ToolsList::execute()` method where all available plugins are processed and their tool names are transformed using:

$prefixizedTools = array_map(
  fn($tool) => new Tool(
    name: $instance->getPluginId() . '_' . md5($tool->name),
    description: "Original name: $tool->name, Description: $tool->description",
    inputSchema: $tool->inputSchema,
  ),
  $instanceTools
);

The tool->name should already be unique but is set in code and can also be long.

Steps to reproduce

1. Create an MCP plugin with a plugin ID longer than ~20 characters
2. Add the MCP server to Claude Code CLI: `claude mcp add myserver -- /path/to/mcp-server-drupal --drupal-url=http://example.com`
3. Try to use Claude Code
4. Observe the 64-character limit error

The character budget breakdown:
- `mcp__` = 5 characters (Claude Code prefix)
- `__` = variable (typically 7-15 characters)
- `
_` = variable (plugin ID + underscore)
- `` = 32 characters (always)

This leaves very little room for meaningful plugin IDs when using Claude Code.

Proposed resolution

**Option 1: Shorten the hash**
Replace the full 32-character MD5 hash with a shorter hash to provide more room for plugin IDs:

name: $instance->getPluginId() . '_' . substr(md5($tool->name), 0, 8),

This reduces the hash from 32 to 8 characters, providing 24 more characters for plugin IDs while maintaining reasonable collision resistance.

**Option 2: Documentation improvement**
At minimum, documenting the character limit constraint in the module documentation and provide guidelines for plugin ID naming.

Remaining tasks

- [ ] Decide on the preferred solution approach
- [ ] Implement the chosen solution
- [ ] Update documentation with character limit guidance
- [ ] Add tests to verify tool name length constraints
- [ ] Consider backward compatibility if changing hash length

User interface changes

None required.

API changes

If implementing Option 1: Tool names will have shorter hashes, but this should be backward compatible as tool names are internal identifiers which do not change.

Data model changes

None required.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands askibinski

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024