Two magpies, one in China and one in Los Angeles, each serve the same tools through their MCP router (/mcp/magpie/hub). An agent connected to both saw two identical web fetches and couldn't pick the one in Los Angeles to reach Google. Each router now says where it is: - initialize's instructions end "This router: <name>. Each of its tools' descriptions starts with [<name>]; ...", and serverInfo.title is "Magpie MCP hub · <name>"; - each tool's description in tools/list starts "[<name>] " (once: a description that starts so already, another magpie's router behind this one, isn't given it twice). <name> is the user's words (settings.RouterNote, one line, 80 characters at most) to every caller. With none it is this computer's name, to callers on other computers only: an agent on this computer has one router at hand, and its prompts stay as they were. RouterNote is this computer's own (KeepOwn): library.json is synced, settings.json isn't, so a sync never brings the other machine's name. It is set in the Library's MCP tab, in a Router name row under the router's address (shown while the router is on): a plain field with the computer's name as placeholder, saved on Enter or leaving it, Escape puts the saved words back, an input method's Enter is its own. POST /api/settings keeps it. Translated in zh, zh-TW, ja, de. docs/subsystems/mcp-router.md has the rule. Run (mote, ata5a9cdf7b+ this change): go vet ./... for darwin, linux and windows ok; go test -tags nogui ./... -timeout 45m: every package ok except internal/gui's TestSettingsSaveKeepsWhatItDoesNotSend on BusyLoad, red on main since8d8df0639(#4739, fixed in the next commit). After rebasing on9feb1024c: internal/gui, settings, library and gateway again, and node --test library-mcp-router-note (new), library-mcp-hub, mcp-hub-direct and i18n-keys, chromium and webkit, en/zh/zh-TW/ja/de, at 1100 and 420 wide. Broken by hand: hubWhere returning "" turns TestHubMCPSaysWhere red; dropping RouterNote from KeepOwn turns TestRouterNote red; dropping it from POST /api/settings' carry list turns TestHubNoteSaved and TestSettingsSaveKeepsWhatItDoesNotSend red. i18n-keys caught a test comment saying "Router name", reworded. Not tried: two real magpies on two computers with a real Claude Code or Codex connected to both, and whether a model actually picks by the prefix; the Linux and Windows apps' Library tab.
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// The name the Library gives this computer's MCP router (packinggoodsllc_07668 on Discord) is saved
|
|
// to this computer's settings and comes back in the page's view, with
|
|
// this computer's name for the field's placeholder; a save from the
|
|
// Settings page, which doesn't send it, leaves it as it is.
|
|
func TestHubNoteSaved(t *testing.T) {
|
|
sandboxHome(t)
|
|
h := Handler(nil, nil)
|
|
post := func(path, body string) *httptest.ResponseRecorder {
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
return rec
|
|
}
|
|
rec := post("/api/library/servers/hub-note", `{"note":" Los Angeles "}`)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body)
|
|
}
|
|
var v struct{ HubNote, HubName string }
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v.HubNote != "Los Angeles" || settings.Load().RouterNote != "Los Angeles" {
|
|
t.Fatalf("view %+v, saved %q", v, settings.Load().RouterNote)
|
|
}
|
|
if rec := post("/api/settings", `{"theme":"dark","lang":"en"}`); rec.Code != http.StatusOK {
|
|
t.Fatalf("settings: %d %s", rec.Code, rec.Body)
|
|
}
|
|
if got := settings.Load().RouterNote; got != "Los Angeles" {
|
|
t.Fatalf("the Settings page's save left %q", got)
|
|
}
|
|
if rec := post("/api/library/servers/hub-note", `{"note":""}`); rec.Code != http.StatusOK || settings.Load().RouterNote != "" {
|
|
t.Fatalf("cleared: %d %q", rec.Code, settings.Load().RouterNote)
|
|
}
|
|
}
|