With another magpie as a provider (preset remote-magpie), its router's
MCP servers took adding that same magpie again under Library -> MCP.
Now the gateway's info (GET /v1) says "mcp_hub": true to a caller it
serves MCP to while its router is on with a server that isn't itself
another magpie's router. A fetch of a Remote magpie's models asks that
info with the provider's key, only while the library would still give
it a server, and the library then adds one: named for the provider,
http at <root>/mcp/magpie/hub with Authorization: Bearer <key>, kept to
this computer (local), on for the agents given the hub's entry.
- Offered once (bridgesOffered in library.json): removed or switched
off by the user, it stays so until the provider is removed and added
again.
- A server the user already has at that magpie's router (same origin,
the router's path) is the one; none is added beside it.
- The provider removed takes its server out (adoptBridges, at Sync and
the View read); providers.json unreadable takes nothing out; the
provider's address or key changed changes the server's; edited to
another address or key it becomes the user's own (keptBridge).
- No loop: every dial to a URL under /mcp/magpie/hub carries
X-Magpie-Router, and a request with it is given no such server,
neither listed (library Tools, gateway hubServersOf) nor run (Call,
hubToolNamed). A server carried in by sync is never a bridge.
- No GUI change: it is a server row as any other.
Run (mote, at base 1c45645b5):
- gofmt -l clean; go vet ./internal/{gateway,library,provider} on
darwin, GOOS=windows, and GOOS=linux -tags nogui: ok.
- go test ./internal/gateway -run 'TestHubLeavesRemoteRouterToARouter|
TestInfoSaysMCPHub|TestHubMCP'; ./internal/provider -run
'TestRemoteHubNoted|TestRemoteSelf'; ./internal/library -run
'TestRemoteMagpieRouter|TestCarriedServerIsNoBridge|TestPluginTools|
TestHub': ok.
- Real two-magpie run on mote: a built binary, two sandbox HOMEs /
XDG_CONFIG_HOMEs, B on 3512 with a python stub provider and a stub
HTTP MCP server behind its router, A on 3513 with B as a Remote
magpie. After `magpie sync` on A, A's library.json had home-magpie
(http://127.0.0.1:3512/mcp/magpie/hub, Bearer key, bridge home) and
bridgesOffered [home]; A's /mcp/magpie/hub listed
home-magpie__stubmcp__echo and tools/call returned the stub's echo;
A asked with X-Magpie-Router listed nothing (loop guard); B asked
with it still listed its own stubmcp__echo.
Broken by hand, each red: the Tools filter, the Call filter, the router
header in remoteHeaders, the same-origin dedup, offered-once, the
unreadable-providers keep, the key refresh, keptBridge, putServers'
carried reset, hubServerOf's Bridge, the gateway's hubServersOf, the
gateway's header -> ctx, info's non-bridge check, fetch's hook, the
older-magpie check and the this-magpie check.
Not tried / not handled:
- The real run was over loopback; a LAN remote's key check is covered
only by the existing TestHubMCPRemoteEntryNeedsKey path.
- The provider's own extra headers (a proxy's) aren't carried to the
server; a remote with several keys is asked with p.Key.
- A remote whose router is turned off later keeps its server (it lists
no tools).
- A server the user added by hand at another magpie's router now sends
X-Magpie-Router too, so that router leaves out its own Remote
magpies' servers for it.
- Windows and Linux test runs (vet only).
Reported-by: treeman_26897
huhuy72219405 on X: "能不能把不同设备的mcp区分一下,有些mcp属于本地的,
同步之后其他设备不应该读取到". A server in Library > MCP now has a
"This computer only" switch in its editor (Server.Local; CLI
`magpie library mcp add ... --local` and `magpie library mcp local
<name> on|off`; the TUI keeps it on edit and marks the row).
- Collect leaves local servers out (carriedServers), so neither a sync
nor a backup file takes one to another computer. Turning a shared
server local takes it out of what is carried, so the other computers
drop it at their next sync; the flag itself is never carried.
- Put (sync, join, Restore, Undo, backup file) keeps every local
server, with its agents, and clears Local on what comes in.
- Another computer's server by a local server's name goes to
Library.Away: given to no agent, not in the hub, carried on as it
came, so a push from here never removes it from the computers that
have it. settleAway (every change) promotes it once the name is gone
here, and drops it once the name is shared here again.
- The hub serves local servers like any other (it runs here);
subagents aren't carried, so one naming a local server keeps it.
Docs: docs/subsystems/library.md, docs/subsystems/sync-backup.md.
Run at f5dd4e142 + this change; after rebasing on d3898ca8d (gui/provider only, then 2a1ef15ba, routing), vet, the five new Go tests, mcp-local-server and i18n-keys again, ok:
- mote: gofmt -l clean; go vet of library/backup/davsync/cli/tui;
GOOS=linux and GOOS=windows go vet -tags nogui of the same; go test
of TestLocalServerNotCarried, TestPutKeepsLocalServer,
TestPutSameNameAsLocal (library), TestRestoreKeepsLocalServer
(backup), TestLocalServerThroughSync (davsync, two computers through
the fake S3) ok.
- mote GUI, Chromium and WebKit: mcp-local-server.test.cjs (new; every
language, 1100 and 390 wide, switch saves local true/false, row tag,
no sideways scroll), i18n-keys, mcp-editor-cancel,
mcp-startup-timeout, every library-mcp-*, mcp-oauth-app, mcp-signin*,
library-items, library-servers-bulk, library-subagents,
library-pick-remove, library-env-refs, library-zed-mcp,
library-loading: all pass (126 of 126 in the last batch).
- Full Go suite, -tags nogui -timeout 45m, on the Linux box (wsl-run;
mote had another session's full suite running): every package ok
but internal/agent, whose TestInstalledVersion, TestGrokInstalled,
TestOmpDetectedWithPiDir and TestZedAppPath fail the same at
origin/main 9b4d0bda8 on that box; all four are #4033.
- Real CLI in a sandbox HOME on mote: mcp add --local, local on/off,
`magpie library` shows "this computer only", library.json has
"local": true; an unknown name and a bad value are refused.
Broken by hand: putServers not keeping local servers turned
TestPutKeepsLocalServer, TestPutSameNameAsLocal,
TestRestoreKeepsLocalServer and TestLocalServerThroughSync red;
carriedServers carrying local servers turned TestLocalServerNotCarried,
TestPutSameNameAsLocal, TestRestoreKeepsLocalServer and
TestLocalServerThroughSync red.
Not tried: a sync between two real computers; the real GUI app (the
Playwright run fakes the API); the full Go suite on macOS or Windows.