Skip to content

fix: truncate MCP tool names exceeding 64 characters#15595

Open
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-3523-mcp-name-length
Open

fix: truncate MCP tool names exceeding 64 characters#15595
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-3523-mcp-name-length

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Issue for this PR

Closes #3523

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

MCP tool names are generated by concatenating the MCP server name and tool name ({server}_{tool}). When this combined name exceeds 64 characters, the OpenAI API rejects it and OpenCode silently stops processing requests.

The fix truncates the combined tool name to 64 characters and logs a warning when truncation occurs. This matches what mcphub.nvim does (referenced in the issue).

Changed packages/opencode/src/mcp/index.ts — the tool registration loop now checks length and truncates with a log warning.

How did you verify your code works?

Verified the logic by reviewing the code path. The change is a simple conditional truncation on the name string before using it as the tool registry key.

Screenshots / recordings

N/A — no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The combined MCP server name + tool name can exceed the 64-character
limit imposed by LLM APIs (e.g. OpenAI), causing silent failures.
Truncate to 64 characters and log a warning when this occurs.
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.

[BUG] tools[21].function.name': string too long. Expected a string with maximum length 64, but got a string with length 65 instead.

1 participant