Skip to content

fix(mcp): keep wire-name server segment unambiguous for parsing - #539

Open
BlueX888 wants to merge 1 commit into
OpenBMB:mainfrom
BlueX888:fix/mcp-wire-name-double-underscore
Open

BlueX888 wants to merge 1 commit into
OpenBMB:mainfrom
BlueX888:fix/mcp-wire-name-double-underscore

Conversation

@BlueX888

@BlueX888 BlueX888 commented Sep 1, 2026

Copy link
Copy Markdown

What

buildMcpToolWireName now normalizes the server segment so it can never contain __ or edge underscores: underscore runs are collapsed and leading/trailing underscores trimmed, mirroring normalizeMcpName in src/tool/builtin/mcpTool.ts. Tool names keep __ as before, since parsing splits at the first separator only.

Why

parseMcpToolWireName splits at the first __ after the mcp__ prefix, but the builder accepted server IDs containing __ — directly, via sanitization (a..ba__b), or ending in _. Such wire names parsed back to a different server/tool pair. Reproduced on main:

buildMcpToolWireName("0__A", "a")      // => "mcp__0__A__a"
parseMcpToolWireName("mcp__0__A__a")   // => { serverId: "0", toolName: "A__a" }

With this change every built wire name parses back to a stable server/tool identity, and wire names for ordinary server IDs (including single underscores) are unchanged.

How verified

  • Added tests/mcp/wire-name.spec.ts (6 cases: plain round-trip, __ in server ID, trailing underscore, sanitization-induced __, __ in tool name preserved, single underscore preserved) — all pass via tsx --test.
  • Existing tests/mcp/client/McpClient.spec.ts (3 cases) still passes.
  • tsc --noEmit -p tsconfig.json passes.

Fixes #424

parseMcpToolWireName splits at the first '__' after the 'mcp__' prefix,
but buildMcpToolWireName allowed server IDs containing '__' (directly or
via sanitization, e.g. 'a..b' -> 'a__b') or ending in '_'. Such wire
names parsed back to a different server/tool pair.

Collapse underscore runs and trim edge underscores in the server
segment, mirroring normalizeMcpName in tool/builtin/mcpTool.ts, so
every built wire name parses back to a stable server/tool identity.
Tool names keep '__' as before since parsing splits at the first
separator only.

Fixes OpenBMB#424
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.

MCP wire names mis-parse server IDs containing double underscores

1 participant