gateway: the Claude bridge offers a magpie Library tool under its own name, not mcp__magpie__ twice
packinggoods (Discord, 11-01): through the Claude bridge the model saw mcp__magpie__mcp__magpie__magpie-browser__browser_click for each tool the client sent up front, while deferred tools named in the client's text kept one prefix. The client (Claude Code with magpie's Library MCP) already names those tools mcp__magpie__<server>__<tool>, and the bridge's MCP helper is also called "magpie", so bridgeToolName put the prefix on again. bridgeToolName, which the tool list, tool_choice, history and the call's mapping back (bridgeNames/declaredName) all go through, now offers such a tool under the rest of its name, so the run's model sees the client's own name and a call comes back as declared. Siblings: only the Claude bridge wraps a client's tools in an MCP server (grep of mcpServers / mcp__ in internal); Codex and direct Claude Code pass names as written. Other servers' tools (mcp__linear__x) still show as mcp__magpie__mcp__linear__x through the bridge; that is nesting, not a doubled prefix, and is left as it was. A client offering both "mcp__magpie__x" and a bare "x" would have them offered alike (not handled). A resumed bridge session's older turns name the tool with the doubled prefix. Run (on mote, via mote-run, at this tree before a comment-only reword): - TestClaudeBridgeKeepsMagpieMCPNames with the old bridgeToolName put back: FAIL, "mcp__magpie__magpie-browser__browser_click is shown to the run's model as mcp__magpie__mcp__magpie__magpie-browser__browser_click", and the same for history and tool choice. Passes with the fix. - go vet ./internal/gateway, GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. - go test -tags nogui -timeout 45m ./internal/gateway: ok (895s). - gofmt -l internal/gateway: nothing. Not run: the full ./... suite, Windows/Linux test runs, and a real Claude Code bridge session with the reporter's Library servers.
This commit is contained in:
@@ -3909,7 +3909,20 @@ func bridgeName(name string) string {
|
||||
// change, or one ending as a changed name ends, is told apart by a hash of
|
||||
// it, the same in every run, so a resumed session and a conversation's
|
||||
// history name the tool as before; declaredName maps it back.
|
||||
//
|
||||
// A tool of magpie's own MCP server, which the client (Claude Code with
|
||||
// magpie's Library) already names mcp__magpie__<server>__<tool>, is
|
||||
// offered under the rest of its name: with the helper's mcp__magpie__
|
||||
// before it again, the run's model was shown
|
||||
// mcp__magpie__mcp__magpie__magpie-browser__browser_click, while a
|
||||
// deferred tool the client named in its text kept the single prefix
|
||||
// (packinggoods on Discord, 11-01). The model now sees the client's own
|
||||
// name. A client offering both "mcp__magpie__x" and a bare "x" would
|
||||
// have the two offered alike, which this doesn't tell apart.
|
||||
func bridgeToolName(name string) string {
|
||||
if rest, ok := strings.CutPrefix(name, "mcp__magpie__"); ok && bridgeToolNameOK.MatchString(rest) && !bridgeToolNameHashed.MatchString(rest) {
|
||||
return rest
|
||||
}
|
||||
if bridgeToolNameOK.MatchString(name) && !bridgeToolNameHashed.MatchString(name) {
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestClaudeToolNamesComeBackAsDeclared(t *testing.T) {
|
||||
t.Skip("a shell script stands in for Claude Code")
|
||||
}
|
||||
long := "tools.example.com/" + strings.Repeat("very_long_segment.", 5) + "end"
|
||||
declared := []string{"spawn.agent", "fs/read", "has space", long, "a.b", "a_b"}
|
||||
declared := []string{"spawn.agent", "fs/read", "has space", long, "a.b", "a_b", "mcp__magpie__magpie-browser__browser_click"}
|
||||
|
||||
dir := t.TempDir()
|
||||
offered := filepath.Join(dir, "offered")
|
||||
@@ -157,3 +157,52 @@ done
|
||||
t.Errorf("history tells the long name as %q", text.String())
|
||||
}
|
||||
}
|
||||
|
||||
// packinggoods (Discord, 11-01): Claude Code with magpie's Library MCP
|
||||
// names its tools mcp__magpie__<server>__<tool>, and through the Claude
|
||||
// bridge the run's model was shown
|
||||
// mcp__magpie__mcp__magpie__magpie-browser__browser_click for each tool
|
||||
// sent up front, while the deferred ones its text named kept one prefix.
|
||||
// The run's Claude Code is offered each such tool under the client's own
|
||||
// name, in the tool list, a tool choice and the history alike, and a call
|
||||
// of it comes back under the declared name.
|
||||
func TestClaudeBridgeKeepsMagpieMCPNames(t *testing.T) {
|
||||
declared := []string{
|
||||
"mcp__magpie__magpie-browser__browser_click",
|
||||
"mcp__magpie__magpie-vision__analyze_image",
|
||||
"mcp__magpie__magpie-web-search__web_search",
|
||||
"mcp__linear__get_issue",
|
||||
"Read",
|
||||
}
|
||||
var tools []Tool
|
||||
for _, n := range declared {
|
||||
tools = append(tools, Tool{Name: n})
|
||||
}
|
||||
req := &Request{Tools: tools}
|
||||
names := bridgeNames(tools)
|
||||
for i, offer := range bridgeTools(req) {
|
||||
n := declared[i]
|
||||
seen := "mcp__magpie__" + offer.Name
|
||||
if strings.HasPrefix(n, "mcp__magpie__") && seen != n {
|
||||
t.Errorf("%s is shown to the run's model as %s", n, seen)
|
||||
}
|
||||
if strings.Contains(seen, "mcp__magpie__mcp__magpie__") {
|
||||
t.Errorf("%s is offered with mcp__magpie__ twice: %s", n, seen)
|
||||
}
|
||||
if got := declaredName(names, offer.Name); got != n {
|
||||
t.Errorf("a call of %s (offered %s) comes back as %s", n, offer.Name, got)
|
||||
}
|
||||
if bridgeName(n) != seen {
|
||||
t.Errorf("history and tool choice name %s as %s, the tool list as %s", n, bridgeName(n), seen)
|
||||
}
|
||||
}
|
||||
var text strings.Builder
|
||||
renderParts(nil, &text, []Part{{Kind: ToolCall, ID: "c1", Name: declared[0], Args: json.RawMessage(`{}`)}}, offeredTools(tools))
|
||||
if !strings.Contains(text.String(), "[tool call "+declared[0]+" id=c1 ") {
|
||||
t.Errorf("history tells %s as %q", declared[0], text.String())
|
||||
}
|
||||
req.ToolChoice = "name:" + declared[0]
|
||||
if got := toolChoiceAsk(req); !strings.Contains(got, "You must call the "+declared[0]+" tool.") {
|
||||
t.Errorf("tool choice %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user