Skip to content

fix(mcp): sanitize bridged tool names to the API charset#2285

Open
indie-hub wants to merge 1 commit into
esengine:mainfrom
indie-hub:fix/mcp-tool-name-charset
Open

fix(mcp): sanitize bridged tool names to the API charset#2285
indie-hub wants to merge 1 commit into
esengine:mainfrom
indie-hub:fix/mcp-tool-name-charset

Conversation

@indie-hub
Copy link
Copy Markdown

What

Sanitizes bridged MCP tool names to the OpenAI/DeepSeek function-name charset ([a-zA-Z0-9_-], 64-char cap) at the single registration chokepoint in registerSingleMcpTool. The bridge closure still dispatches to the server with the original name, so no reverse mapping is needed. Sanitized names that collide get a numeric suffix and a startup warning.

Why

MCP servers whose tools are named with characters outside the API charset — e.g. unity/health, unity/changes/apply from a Unity MCP bridge — were sent to the DeepSeek API verbatim and rejected with a 400 before the agent loop could run, making the entire server unusable.

The bridge already separates the model-facing/registered name from the server-side name (the dispatch closure captures the original stableTool.name), so the fix only needs to make the registered name API-safe; dispatch is untouched.

Verified end-to-end against a live Unity MCP (streamable HTTP): tools bridge with rename notices (unity/healthunity_health), the model calls the sanitized name, and Unity receives the original endpoint.

How to verify

  • npm run verify (lint + typecheck + tests + comment-policy gate) — passes locally.
  • New tests/mcp-registered-name-sanitize.test.ts covers: / sanitized, dispatch hits the original endpoint, not the sanitized name (the key regression guard), collision auto-suffix, charset/length invariant, and no-op for already-valid names.

Checklist

  • npm run verify passes locally (lint + typecheck + tests + comment-policy gate)
  • No Co-Authored-By: Claude trailer in commits
  • Comments follow CONTRIBUTING.md (no module-essay headers, no incident history)
  • No edits to CHANGELOG.md — release notes are maintainer-written at release time

MCP tools whose names contain characters outside the OpenAI/DeepSeek
function-name charset (e.g. unity/health) were sent to the API verbatim
and rejected with a 400, making the whole server unusable.

Sanitize the model-facing/registered name to [a-zA-Z0-9_-] (64-char cap)
at the single registration chokepoint. The bridge closure still calls
the server with the original name, so no reverse mapping is needed.
Sanitized names that collide get a numeric suffix and a startup warning.
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.

1 participant