Files
magpie/docs
yetone e183604f06 claude: a tool named with a dot comes back under the name the client declared (#2649)
tsy0716's client offers a tool named "spawn.agent". Through a Claude
subscription the reply's tool_use called "spawn_agent", a tool the client
never offered: Claude Code keeps only [A-Za-z0-9_-] of an MCP tool's name,
and magpie handed the call back under the name Claude Code used.

The MCP helper now offers each tool under bridgeToolName: a name Claude
Code keeps as it is (and at most 51, 64 with mcp__magpie__) is unchanged;
any other, or one ending as a changed name ends (_ and 12 hex digits), is
cut to 38 of [A-Za-z0-9_-] and given 12 hex digits of its SHA-256. So
"a.b" and "a_b" stay apart, and the name is the same in every run: a
resumed session, the history told to a new run (renderParts) and the
tool-choice line (toolChoiceAsk) name it as the run was offered it.
subscriptionRun.names maps it back to the declared name in toolStart (Claude
Code's streamed and whole messages, so every API the bridge serves) and in
mcpCall (what an agent like Cursor is told through onCall). A name Claude
Code already kept goes upstream exactly as before.

What was run:
- New TestClaudeToolNamesComeBackAsDeclared: tools "spawn.agent",
  "fs/read", "has space", an 83-character name, "a.b" and "a_b", through
  /v1/messages, chat/completions and responses, client stream on and off,
  Claude Code's reply streamed and whole (12 cases); a fake Claude Code
  that changes names as Claude Code does and calls every tool it was
  offered. Checks the client gets exactly the declared names, and Claude
  Code was offered six valid, unique names of at most 51; and the history
  and tool-choice text use the offered name.
- Broken by hand: with the encoding taken out the test fails; with only
  the decoding in toolStart taken out, every case fails ("the calls name
  [a_b a_b_2e7336dc8eba fs_read_96379919f693 ...], want the declared").
- go test -run 'Claude|Bridge|MCP|Mcp|Tool' ./internal/gateway/
  ./internal/claudebridge/: ok.
- gofmt -l clean; go vet -tags nogui ./... on darwin, linux, windows: ok.
- Full suite at this head (8b1fad8f5 before the message change), as
  recorded in the #2651 commit: ok but three timing reds outside this
  change (#2719, #1889, and one fixed on main by bad4508c4), each green alone.
- Rebased onto origin/main 17557132c (7 commits, none in these files):
  gofmt and vet on all three systems, then internal/gateway,
  internal/provider, internal/netproxy and internal/claudebridge at
  9af3bb98b: ok. The whole suite wasn't run again at this head.

Not tried: a real Claude Code run with such a tool name.
2026-10-17 19:55:50 +08:00
..