fix(mcp): sanitize bridged tool names to the API charset#2285
Open
indie-hub wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inregisterSingleMcpTool. 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/applyfrom 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/health→unity_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.tests/mcp-registered-name-sanitize.test.tscovers:/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 verifypasses locally (lint + typecheck + tests + comment-policy gate)Co-Authored-By: Claudetrailer in commitsCHANGELOG.md— release notes are maintainer-written at release time