claude: a deferred built-in the bridge's model calls reaches the client as WebFetch, not mcp__magpie__WebFetch

Claude Code with tool search on leaves WebFetch, WebSearch, CronCreate and
the other deferred built-ins out of tools until a ToolSearch loads them.
The run's model, offered the client's tools as mcp__magpie__<name>, called
mcp__magpie__WebFetch, and toolStart handed that over whole: the 11-02
fix for an unloaded magpie MCP tool (packinggoods) kept the full name for
every cut name the client hadn't declared. The client answered "No such
tool available: mcp__magpie__WebFetch", the model retried, and
status lines such as claude-hud showed a "magpie" MCP failure.

toolStart now keeps the prefix only when the cut name has the router's
form, <server>__<tool> (magpieServerTool): the client names magpie's MCP
tools mcp__magpie__<server>__<tool>, and its built-ins (WebFetch,
WebSearch, CronCreate, CronDelete, CronList, NotebookEdit, Monitor,
TaskStop, SendMessage, EnterWorktree, ExitWorktree: the deferred list of
a real Claude Code session) have no __ and no prefix. A sibling the same
line got wrong: another MCP server's deferred tool, called as
mcp__magpie__mcp__linear__get_issue, is handed over as
mcp__linear__get_issue, the client's name (it was handed over whole too).
toolStart is the one place a called name is mapped back for the client:
streamed and whole messages and the interactive mode's early call
(r.onCall) all go through it; mcpCall's declaredName serves offered
tools only, and the history's names (bridgeName) are unchanged.

Run (on mote, at this tree):
- go test ./internal/gateway -count=1 -timeout 45m: ok
- gofmt -l: nothing; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok; go build: ok
Broken by hand: magpieServerTool returning true (the old behaviour)
turns TestClaudeBridgeHandsOverAnUnloadedMagpieTool red on the new
WebFetch and mcp__linear__ cases ("handed a call of
mcp__magpie__WebFetch, want WebFetch").
Not tried: a real Claude Code client with tool search on (the reporter's
Windows setup); a deferred tool the run's model calls by the bare client
name (WebFetch) is still the run's Claude Code's to answer and isn't
handed over. A client MCP server of its own named "magpie" with a tool
lacking __ would now be cut; magpie's router names every tool
<server>__<tool>.
Rebased on eadc6cdb9 (GUI routing files only); at the pushed head
go test ./internal/gateway -run 'TestClaudeBridge|TestClaudeToolChoice|
BridgeToolName': ok.
Full suite: not run at push.

Reported-by: steven_4422 (Discord)
This commit is contained in:
yetone
2026-11-08 16:05:42 +08:00
parent eadc6cdb96
commit 0f8c3d8672
3 changed files with 43 additions and 11 deletions
+10 -2
View File
@@ -84,8 +84,16 @@ the full name, which is the client's own, when the cut name maps to
nothing and isn't in `subscriptionRun.tools`: handed over cut, as
`<server>__<tool>`, the client answered "No such tool available" and the
model had to load it and call again (packinggoods, 11-02,
`TestClaudeBridgeHandsOverAnUnloadedMagpieTool`). A deferred tool of
another client MCP server (`mcp__linear__…`) is still not handed over.
`TestClaudeBridgeHandsOverAnUnloadedMagpieTool`). Only a cut name of the
router's form, `<server>__<tool>` (`magpieServerTool`), keeps the prefix.
A deferred built-in (`WebFetch`, `WebSearch`, `CronCreate`: no `__` in
the name, no prefix on the client) called as `mcp__magpie__WebFetch` is
handed over as `WebFetch`; handed over whole, the client answered "No
such tool available: mcp__magpie__WebFetch" (steven_4422, 11-08). One of
another client MCP server called as `mcp__magpie__mcp__linear__…` is
handed over as `mcp__linear__…`. A deferred tool the run's model calls
by the bare client name (`WebFetch`, `mcp__linear__…`) is the run's
Claude Code's to answer and is not handed over.
A turn with `tool_choice` none is offered every tool the client sent, as
any other turn is (bbfatx on X). Anthropic caches a prompt as tools, then
+21 -6
View File
@@ -3860,12 +3860,17 @@ func (r *subscriptionRun) readOutput(rd io.Reader) {
search := r.search != nil && name == r.searchName || r.answerName != "" && name == r.answerName
refused := r.allowed != nil && !r.allowed[name]
// a tool the client announced but hasn't loaded yet (Claude
// Code's deferred MCP tools, told by name in the conversation
// and not in tools until a ToolSearch) is called by the
// client's own name, which is the name the run's agent called:
// the bare name cut from it is no tool the client has, and it
// answered "No such tool available" before a retry (packinggoods)
if ok && !search && name == rest && r.tools != nil && !r.tools[rest] {
// Code's deferred tools, told by name in the conversation and
// not in tools until a ToolSearch) is called by the client's
// own name. A tool of magpie's MCP server is
// mcp__magpie__<server>__<tool> there, the name the run's agent
// called: cut to <server>__<tool> it is no tool the client has,
// and it answered "No such tool available" before a retry
// (packinggoods). A deferred built-in (WebFetch, CronCreate) has
// no __ in its name and the client no prefix on it: handed over
// as mcp__magpie__WebFetch it was no tool either (steven_4422).
// Another server's (mcp__linear__…) is the client's name as cut.
if ok && !search && name == rest && r.tools != nil && !r.tools[rest] && magpieServerTool(rest) {
name = called
}
r.mu.Unlock()
@@ -5027,6 +5032,16 @@ func declaredName(names map[string]string, name string) string {
return name
}
// magpieServerTool says whether rest, a name the run's agent called with
// mcp__magpie__ cut off, is a tool of magpie's MCP server as the client
// names it after that prefix: <server>__<tool> (the router's names,
// hub_mcp.go). Claude Code's built-ins (WebFetch, WebSearch, CronCreate,
// NotebookEdit…) have no __ in their names, and another MCP server's tool
// is mcp__<server>__<tool> whole.
func magpieServerTool(rest string) bool {
return strings.Contains(rest, "__") && !strings.HasPrefix(rest, "mcp__")
}
// offeredTools is the names of the caller's tools, whose past calls a run
// is told under bridgeName: a conversation told in text with hundreds of
// calls of the bare names had the model call those, not the run's.
+12 -3
View File
@@ -21,8 +21,13 @@ import (
// under the full name, and the client is handed that name, which it runs:
// not the bare magpie-web-search__web_search it has no tool of, which it
// answered "Error: No such tool available: magpie-web-search__web_search"
// before the model retried (packinggoods, #feedback 11-02). A tool it
// declared still comes back under its declared name.
// before the model retried (packinggoods, #feedback 11-02). A deferred
// built-in has no prefix on the client: called as mcp__magpie__WebFetch it
// is handed over as WebFetch, which the client answered "No such tool
// available: mcp__magpie__WebFetch" before (steven_4422, #feedback 11-08).
// Another MCP server's tool is handed over as the client names it,
// mcp__linear__…, and a tool it declared still comes back under its
// declared name.
func TestClaudeBridgeHandsOverAnUnloadedMagpieTool(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
@@ -33,6 +38,8 @@ while read -r line; do
case "$line" in
*call-search*) name=mcp__magpie__magpie-web-search__web_search ;;
*call-browser*) name=mcp__magpie__magpie-browser__browser_click ;;
*call-fetch*) name=mcp__magpie__WebFetch ;;
*call-linear*) name=mcp__magpie__mcp__linear__get_issue ;;
*) name=mcp__magpie__Read ;;
esac
echo '{"type":"stream_event","event":{"type":"message_start","message":{"id":"m","model":"claude-sonnet-5","usage":{"input_tokens":1}}}}'
@@ -50,7 +57,7 @@ done
// the client's tools: ToolSearch, Read and the one MCP tool it loaded;
// web_search is announced in the conversation only
tools := `[{"name":"ToolSearch","input_schema":{"type":"object"}},{"name":"Read","input_schema":{"type":"object"}},{"name":"mcp__magpie__magpie-browser__browser_click","input_schema":{"type":"object"}}]`
announced := "<system-reminder>\nThe following deferred tools are now available via ToolSearch. Their schemas are NOT loaded — calling them directly will fail with InputValidationError. Use ToolSearch with query \"select:<name>[,<name>...]\" to load tool schemas before calling them:\nmcp__magpie__magpie-web-search__web_search\n</system-reminder>\n"
announced := "<system-reminder>\nThe following deferred tools are now available via ToolSearch. Their schemas are NOT loaded — calling them directly will fail with InputValidationError. Use ToolSearch with query \"select:<name>[,<name>...]\" to load tool schemas before calling them:\nmcp__magpie__magpie-web-search__web_search\nWebFetch\nmcp__linear__get_issue\n</system-reminder>\n"
p := provider.Provider{ID: "claude", Account: &provider.Account{Agent: "claude", User: "u"}}
call := func(what string) string {
t.Helper()
@@ -79,6 +86,8 @@ done
for what, want := range map[string]string{
"call-search: search the web for magpie": "mcp__magpie__magpie-web-search__web_search",
"call-browser: click the button": "mcp__magpie__magpie-browser__browser_click",
"call-fetch: fetch usemagpie.ai": "WebFetch",
"call-linear: read issue MAG-1": "mcp__linear__get_issue",
"read a file": "Read",
} {
if got := call(what); got != want {