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.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package settings
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// What the MCP router says of itself is this computer's own: a sync or a
|
|
// restored backup from the computer in China keeps the one in Los
|
|
// Angeles saying Los Angeles. It is kept one line and short, and set
|
|
// alone, beside the rest of the file.
|
|
func TestRouterNote(t *testing.T) {
|
|
from := Settings{RouterNote: "China"}
|
|
from.KeepOwn(Settings{RouterNote: "Los Angeles"})
|
|
if from.RouterNote != "Los Angeles" {
|
|
t.Fatalf("a sync brought %q", from.RouterNote)
|
|
}
|
|
if got := CleanRouterNote(" Los\tAngeles\n(US) "); got != "Los Angeles (US)" {
|
|
t.Fatalf("cleaned %q", got)
|
|
}
|
|
if got := CleanRouterNote(strings.Repeat("洛", RouterNoteMost+5)); got != strings.Repeat("洛", RouterNoteMost) {
|
|
t.Fatalf("not cut at %d characters: %d", RouterNoteMost, len([]rune(got)))
|
|
}
|
|
if err := Save(Settings{Theme: "dark"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := SetRouterNote(" Los Angeles "); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s := Load(); s.RouterNote != "Los Angeles" || s.Theme != "dark" {
|
|
t.Fatalf("saved %+v", s)
|
|
}
|
|
if err := SetRouterNote(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s := Load(); s.RouterNote != "" {
|
|
t.Fatalf("not cleared: %q", s.RouterNote)
|
|
}
|
|
}
|