library: the MCP router turns on with no agent, and in gateway mode
treeman_26897 on Discord runs magpie as an MCP entry point for remote clients on a server with no agents. The router could only be turned on from the Library, and the Library said "No agents to write to" with no agent. In gateway mode (magpie web on a headless server, on by itself with no agents) GATEWAY_HIDES left the Library out altogether. The router's switch also showed only once a server was in the library. The gateway and `magpie library mcp router on` had no agent gate: the gate was the page's alone. Now, with no agent to write to, or in gateway mode (where no agent is shown), the Library is its MCP tab alone (`agentless` in client.js): - servers without agent chips, found servers or projects; - the router's switch, there before the first server too; - its lines and status say any app connects at its address, the router is on or off; - the servers it serves are checked once it is on; - Connect… has Other apps alone, with the gateway key line. Gateway mode hides only Agents now. The two keys of the empty state are gone; the gateway-mode subtitle no longer says "no Library". Remote use goes through the guard /v1 has, unchanged: lanGuard and serveMCP. TestHubMCPRemoteEntryNeedsKey holds /mcp/magpie/hub to it from another computer: not shared 403; shared with no key 401 (no Origin, tools/list, a wrong key); Origin null, chrome-extension://, file://, moz-extension://, a foreign site and another computer's page refused from there and from here; a rebound Host with a browser's marks (Origin = Host, Sec-Fetch only, a Mozilla UA) refused from here and there; a proxy or tunnel here (X-Forwarded-For, Cf-Connecting-IP) with no key refused; nothing ran for any of them; with the key it runs, through the proxy too. Run on mote at ef20ff690 (on origin/mainb4799a6bb); rebased again on6a78060c6(gateway.go changed there), the gateway's Hub and LAN tests and the Budget test ran again ok: - go test -tags nogui ./internal/gateway -run Hub: ok - go test ./internal/gui -run Budget: ok (no budget raised; the core scripts were 137 bytes over with a longer comment, cut back) - gofmt -l clean; GOOS=linux and GOOS=windows go vet of gateway, gui: ok - GUI, both engines, every language: library-mcp-agentless (new, 22 of 22), gateway-mode, last-page, library-mcp-hub, mcp-hub-direct, library-servers-bulk, i18n-keys: 87 of 88; the red is i18n-keys "a plugin's words are its own", below. - Before the rebase, the GUI files a change here can reach (every library-*, gateway-mode*, last-page, i18n-*, mcp-hub-direct, agent-prefs, bare-ids, images-library-way, search-/vision-mcp-library, gateway-conversations; 70 files): 1535 of 1536. The one red is i18n-keys "a plugin's words are its own", on main already: #5327, #5332, #5426 (files this change doesn't touch). Broken by hand: - library-mcp-agentless against origin/main's client.js and app.js: 22 of 22 red (no router row with no agent; no Library tab in gateway mode). - rebound() returning false and serveMCP's Origin check off: TestHubMCPRemoteEntryNeedsKey red on the rebound Host cases and on chrome-extension://, file:// and moz-extension:// from here. The test passes on the old Go code: the guard was there already. Not tried: a real remote MCP client against a headless magpie serve or magpie web on another machine; the TUI (it has no Library page of its own for the router; the CLI's router on needs no agent). Reported-by: treeman_26897
This commit is contained in:
+4
-2
@@ -3204,8 +3204,10 @@ key. See [Connecting anything else](#connecting-anything-else) for the
|
||||
protocol-specific base URLs. Keep `3425` behind a firewall or VPN and do not
|
||||
expose it publicly without gateway-key authentication.
|
||||
|
||||
Such a page is in **gateway mode**: it shows Providers, Gateway, Routing,
|
||||
Usage, Sessions, Plugins and Settings, with no Agents or Library tab.
|
||||
Such a page is in **gateway mode**: it shows Sessions, Library, Providers,
|
||||
Routing, Gateway, Usage, Masking, Plugins and Settings, with no Agents tab.
|
||||
The Library has its MCP servers alone, with the MCP router: other
|
||||
computers' apps connect at the router's address with a gateway key.
|
||||
Sessions lists only the sessions of other computers' agents that came
|
||||
through this gateway, never this machine's agents' session files
|
||||
([gateway sessions](subsystems/gateway-sessions.md)). Settings leaves out what is written into this machine's agents (provider in
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -18,7 +18,7 @@ With the Library's switch "MCP router" on (#2679, @minggang123 on X), each agent
|
||||
| Each caller's Magpie Browser session | One `magpie mcp browser` backend serves every agent behind the router, so it alone would be one browser session: every agent in one tab (packinggoodsllc_07668 on Discord). serveMCP gives a client that initializes an `Mcp-Session-Id` (`newMCPSession`; magpie keeps nothing by it and refuses nothing for it), and each `tools/call` is given the caller's session (`hubSession`): the `_meta` `magpie/session` a router in front of this one named, else `hub-<agent>-<Mcp-Session-Id>`, else none. The router passes it on in `_meta` `magpie/session` (`HubSessionMeta`) only to `magpie mcp browser` and to another magpie's router (`keepsSession`), and the bridge sends it as the `X-Magpie-Browser-Session` of that call (`callerSession`), so two agents, or two windows of one, work in tabs of their own; a call that names none goes as the bridge's own session, as before. | `hubSession`, `newMCPSession` in `hub_mcp.go` and `search_mcp.go`; `keepsSession` in `mcp_hub.go`; `callerSession` in [`browsermcp.go`](../../internal/browsermcp/browsermcp.go) |
|
||||
| Backends | One `backend` per Library server, shared by every agent (`hubPool`, keyed by the server's name; an edit or a sign-in since makes it a new one and ends the old). A command is started as `CheckServers` starts one (`startServer`: `proc` tree, home as its folder, `${NAME}` env expanded), on its first list or call, and initialized once. A URL (`http`, `sse`) is reached with its headers and the Library's MCP sign-in (`mcpauth`), and a session the server forgot is opened again once. A `notifications/tools/list_changed` from a server makes the next list ask it again. | `backendOf`, `connect`, `dialHub`, `dialStdio`, `dialSSE`, `dialHTTP` in `mcp_hub.go`; `startServer`, `httpSession` in [`mcp_check.go`](../../internal/library/mcp_check.go) |
|
||||
| Lifetime | A server with no call for `hubIdle` (10 minutes) is ended; the tools it listed are kept, so a list doesn't start it again, and the next call does. A command that died is started again on the next call. Turning the switch off, an edit, and the gateway stopping (`StopHub` on drain) end them: stdin closed, then the process tree. The switch can be turned off, or a server edited or unticked, by another magpie (the window while `magpie serve` runs, the CLI), and an agent given each server's own entry again never asks the router, so the serving gateway also prunes every `hubPruneEvery` (5s) while it holds a server: each one the library no longer has as it was started, or every one once the switch is off, is ended (`hubPrune`). A server ticked for no agent is still served at `/mcp/magpie/hub`, so it is kept. | `use`, `done`, `stop`, `hubStopAll`, `hubPrune` in `mcp_hub.go`; `StopHub`, `keepHubPruned` in `hub_mcp.go` |
|
||||
| GUI | Below the server list in the Library's MCP tab: a row with the switch (`.lib-switch`, role=switch) saying what it does; on, a line counting what it serves (`.lib-hubstats`: servers, tools, the agents given it), then a row "Other apps" with the address (`.lib-hubURL`, copied with a click) and Connect…, then a Router name row (`.lib-hubnoterow`) with a field (`.lib-hubname`, no native control) holding `hubNote` and `hubName` as its placeholder, saved on Enter or leaving it through `servers/hub-note` `{note}` (Escape puts the saved words back; an input method's Enter is its own), then a Tools on demand row (`.lib-hubtoolsrow`) whose switch is on while `hubAllTools` is false and posts `servers/hub-tools` `{on}` (on: every tool whole), and under them the agents that keep their own entries, grouped by why (`.lib-hub-why[data-why]`). The address is `mcpAddress`: the public one in a browser, the gateway in the app. Connect… opens a sheet (`connectHub`, `.lib-hubsheet`) of two tabs. Agents: agents → magpie → servers, drawn as icons with magpie's bird in the middle, a line of where things stand, then every agent `mcpAgents` lists (each detected, shown agent that takes MCP servers) in groups (`.lib-hubgrp[data-group]`): `off` (not connected), `on` (connected), `kept` (keeps each server's own entry). Each row (`.lib-hubagent[data-state]`: `on`, `none`, `own`, `taken`, `no-remote`) has a switch that posts `servers/agents-all` `{agents:[id], on}`, as By agent's Turn all on/off does: on gives it every Library server, so `hubFor` gives it the entry; off takes every Library server from it. A kept agent has a word for why and the reason in full behind (i) (`.lib-hubinfo`, `.lib-hubwhy`); an agent that reaches no server over HTTP says so even with none ticked. magpie-image is drawn and counted with the others. Connect all (`.lib-huball`) posts every `none` agent at once. With more than 8 agents a search (`.lib-hubsearch`) narrows every group, and the connected and the kept fold to one row each (`.lib-hubfolded`) until unfolded. The sheet stays open while it changes, and an agent is never handed to the user as a command to run. Other apps: the address (`.lib-hubaddr`), and a row per app (`.lib-hubapp[data-app]`): Cursor (only when it isn't one of the agents), VS Code, Windsurf and any JSON app, each with where its entry goes and a Copy entry (`.lib-hubcopy`) that copies its JSON. In the app, Cursor and VS Code also get Add (`.lib-hubadd`): the page posts `servers/hub-open` `{app}` and the window opens that app's install link (`HubLink`), which the app asks the user to confirm. The page never sends a link; an app with none is an error, and nothing is opened. In a browser there is no Add. With the router on, the server editor has a switch "Through the MCP router" (on for shared; not shown with the router off) saved as `hub`, a direct server's row has a tag (`.lib-tag.lib-direct`), and the line under the switch and the sheet name the direct servers as given directly (`inHub`, `directNames` in client.js; `mcp-hub-direct.test.cjs`). The TUI keeps the policy on edit. | `hubPart`, `hubStats`, `connectHub` in [`client.js`](../../internal/gui/assets/plugins/library/client.js), [`library.css`](../../internal/gui/assets/plugins/library/library.css), [`i18n.js`](../../internal/gui/assets/plugins/library/i18n.js); `HubLink` in `mcp_hub.go`; `servers/hub-open` in `gui/library.go` |
|
||||
| GUI | Below the server list in the Library's MCP tab: a row with the switch (`.lib-switch`, role=switch) saying what it does; on, a line counting what it serves (`.lib-hubstats`: servers, tools, the agents given it), then a row "Other apps" with the address (`.lib-hubURL`, copied with a click) and Connect…, then a Router name row (`.lib-hubnoterow`) with a field (`.lib-hubname`, no native control) holding `hubNote` and `hubName` as its placeholder, saved on Enter or leaving it through `servers/hub-note` `{note}` (Escape puts the saved words back; an input method's Enter is its own), then a Tools on demand row (`.lib-hubtoolsrow`) whose switch is on while `hubAllTools` is false and posts `servers/hub-tools` `{on}` (on: every tool whole), and under them the agents that keep their own entries, grouped by why (`.lib-hub-why[data-why]`). The address is `mcpAddress`: the public one in a browser, the gateway in the app. Connect… opens a sheet (`connectHub`, `.lib-hubsheet`) of two tabs. Agents: agents → magpie → servers, drawn as icons with magpie's bird in the middle, a line of where things stand, then every agent `mcpAgents` lists (each detected, shown agent that takes MCP servers) in groups (`.lib-hubgrp[data-group]`): `off` (not connected), `on` (connected), `kept` (keeps each server's own entry). Each row (`.lib-hubagent[data-state]`: `on`, `none`, `own`, `taken`, `no-remote`) has a switch that posts `servers/agents-all` `{agents:[id], on}`, as By agent's Turn all on/off does: on gives it every Library server, so `hubFor` gives it the entry; off takes every Library server from it. A kept agent has a word for why and the reason in full behind (i) (`.lib-hubinfo`, `.lib-hubwhy`); an agent that reaches no server over HTTP says so even with none ticked. magpie-image is drawn and counted with the others. Connect all (`.lib-huball`) posts every `none` agent at once. With more than 8 agents a search (`.lib-hubsearch`) narrows every group, and the connected and the kept fold to one row each (`.lib-hubfolded`) until unfolded. The sheet stays open while it changes, and an agent is never handed to the user as a command to run. Other apps: the address (`.lib-hubaddr`), and a row per app (`.lib-hubapp[data-app]`): Cursor (only when it isn't one of the agents), VS Code, Windsurf and any JSON app, each with where its entry goes and a Copy entry (`.lib-hubcopy`) that copies its JSON. In the app, Cursor and VS Code also get Add (`.lib-hubadd`): the page posts `servers/hub-open` `{app}` and the window opens that app's install link (`HubLink`), which the app asks the user to confirm. The page never sends a link; an app with none is an error, and nothing is opened. In a browser there is no Add. With the router on, the server editor has a switch "Through the MCP router" (on for shared; not shown with the router off) saved as `hub`, a direct server's row has a tag (`.lib-tag.lib-direct`), and the line under the switch and the sheet name the direct servers as given directly (`inHub`, `directNames` in client.js; `mcp-hub-direct.test.cjs`). The TUI keeps the policy on edit. With no agent to write to, or in gateway mode (where no agent is shown), the Library is its MCP tab alone (`agentless` in client.js): the servers without agent chips, found servers or projects, the router's switch even before the first server, its lines saying any app connects at the address, the status saying the router is on or off, the servers it serves checked once it is on, and Connect… on Other apps alone. A server for remote clients is set up this way on a headless magpie (treeman_26897 on Discord); the remote client still needs a gateway key, through the same `serveMCP` guard (`TestHubMCPRemoteEntryNeedsKey`, `library-mcp-agentless.test.cjs`). | `hubPart`, `hubStats`, `connectHub` in [`client.js`](../../internal/gui/assets/plugins/library/client.js), [`library.css`](../../internal/gui/assets/plugins/library/library.css), [`i18n.js`](../../internal/gui/assets/plugins/library/i18n.js); `HubLink` in `mcp_hub.go`; `servers/hub-open` in `gui/library.go` |
|
||||
|
||||
The CLI's `magpie library mcp router on|off` (`hub`, its name before, still works) calls `SetMCPHub`, and `magpie library mcp router <name> shared|direct` calls `ServerHub`. `magpie library` lists the agents given magpie's entry and those that keep their own, with why (`libraryStatus` in [`library_cli.go`](../../internal/cli/library_cli.go)).
|
||||
|
||||
|
||||
@@ -597,3 +597,79 @@ func TestHubMCPTellsCallersApart(t *testing.T) {
|
||||
t.Fatalf("callers %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// The router's one address is what a headless magpie gives remote MCP
|
||||
// clients (treeman_26897 on Discord: a server with no agents, the router
|
||||
// turned on for other computers' apps). From another computer it takes a
|
||||
// gateway key, as /v1 does, and nothing without one gets a tool run:
|
||||
// not while magpie isn't shared, not with no Origin, a null one, another
|
||||
// scheme's or a foreign site's, not under a rebound Host, and not through
|
||||
// a proxy on this computer.
|
||||
func TestHubMCPRemoteEntryNeedsKey(t *testing.T) {
|
||||
fresh(t)
|
||||
t.Setenv("MAGPIE_ADDR", "")
|
||||
t.Setenv("MAGPIE_PUBLIC_URL", "")
|
||||
t.Setenv("MAGPIE_TRUST_PROXY", "")
|
||||
f := &fakeHub{on: true, tools: map[string][]HubTool{"": {{Server: "notes", Tool: "find", Spec: hubSpec("find")}}}}
|
||||
withHub(t, f)
|
||||
h := lanGuard(New().Handler())
|
||||
call := toolsCall("notes__find", `{"q":"x"}`)
|
||||
const there = "192.0.2.7:4000"
|
||||
refused := func(what string, w *httptest.ResponseRecorder, want ...int) {
|
||||
t.Helper()
|
||||
for _, c := range want {
|
||||
if w.Code == c {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Errorf("%s: %d %s, want %v", what, w.Code, w.Body, want)
|
||||
}
|
||||
refused("not shared", hubPostAt(h, HubMCPAll, there, call), http.StatusForbidden)
|
||||
refused("not shared, a tools/list", hubPostAt(h, HubMCPAll, there, toolsList), http.StatusForbidden)
|
||||
_, secrets := newCaller(t, "Remote client") // shares magpie
|
||||
refused("no key, no Origin", hubPostAt(h, HubMCPAll, there, call), http.StatusUnauthorized)
|
||||
refused("no key, a tools/list", hubPostAt(h, HubMCPAll, there, toolsList), http.StatusUnauthorized)
|
||||
refused("a wrong key", hubPostAt(h, HubMCPAll, there, call, "Authorization", "Bearer sk-magpie-wrong"), http.StatusUnauthorized)
|
||||
for _, origin := range []string{"null", "chrome-extension://abcdefghijklmnop", "file://", "moz-extension://1234", "https://evil.example", "http://192.0.2.7:3425"} {
|
||||
hdr := []string{"Origin", origin, "Sec-Fetch-Site", "cross-site", "Sec-Fetch-Mode", "cors"}
|
||||
refused("no key, Origin "+origin+" from there", hubPostAt(h, HubMCPAll, there, call, hdr...), http.StatusUnauthorized, http.StatusForbidden)
|
||||
refused("Origin "+origin+" from here", hubPostAt(h, HubMCPAll, here, call, hdr...), http.StatusForbidden)
|
||||
}
|
||||
// a page whose own name was rebound to this computer: same-origin, so
|
||||
// its Origin is the Host or (as a browser's own marks show) none at all.
|
||||
// With none of a browser's marks it is an agent here calling by a name
|
||||
// of its own, which lanGuard lets by, as /v1
|
||||
for _, addr := range []string{here, there} {
|
||||
for _, marks := range [][]string{
|
||||
{"Origin", "http://rebind.attacker.example:3425", "Sec-Fetch-Site", "same-origin", "Sec-Fetch-Mode", "cors"},
|
||||
{"Sec-Fetch-Site", "same-origin", "Sec-Fetch-Mode", "cors"},
|
||||
{"User-Agent", "Mozilla/5.0 (Macintosh) AppleWebKit/605.1.15 Safari/605.1.15"},
|
||||
} {
|
||||
r := httptest.NewRequest(http.MethodPost, HubMCPAll, strings.NewReader(call))
|
||||
r.RemoteAddr, r.Host = addr, "rebind.attacker.example:3425"
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
r.Header.Set("Accept", "application/json, text/event-stream")
|
||||
for i := 0; i+1 < len(marks); i += 2 {
|
||||
r.Header.Set(marks[i], marks[i+1])
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, r)
|
||||
refused(fmt.Sprintf("a rebound Host from %s %v", addr, marks), rec, http.StatusUnauthorized, http.StatusForbidden)
|
||||
}
|
||||
}
|
||||
// a proxy or tunnel on this computer passing another's request on
|
||||
refused("through a proxy here, no key", hubPostAt(h, HubMCPAll, here, call, "X-Forwarded-For", "203.0.113.9"), http.StatusUnauthorized, http.StatusForbidden)
|
||||
refused("through a tunnel here, no key", hubPostAt(h, HubMCPAll, here, call, "Cf-Connecting-IP", "203.0.113.9"), http.StatusUnauthorized, http.StatusForbidden)
|
||||
if got := f.ran(); len(got) != 0 {
|
||||
t.Fatalf("ran for a request turned away: %q", got)
|
||||
}
|
||||
// with its key: the tool runs, from there and through the proxy
|
||||
m := readMCP(t, hubPostAt(h, HubMCPAll, there, call, "Authorization", "Bearer "+secrets[0]))
|
||||
if m.Result.IsError || m.Result.Content[0].Text != "ran notes find" {
|
||||
t.Fatalf("with its key: %+v", m)
|
||||
}
|
||||
m = readMCP(t, hubPostAt(h, HubMCPAll, here, call, "X-Forwarded-For", "203.0.113.9", "Authorization", "Bearer "+secrets[0]))
|
||||
if m.Result.IsError || len(f.ran()) != 2 {
|
||||
t.Fatalf("through a proxy, with its key: %+v, ran %q", m, f.ran())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ const remotePage = web && !/^(localhost|127(\.\d+){3}|\[::1\]|::1)$/i.test(locat
|
||||
// layout.js applies the mode and platform before the header can paint.
|
||||
// Gateway mode (gatewaymode.go): magpie web on a server that is only the
|
||||
// gateway for other computers' agents leaves out this computer's agents'
|
||||
// pages — Agents, Sessions, Library — and their settings; Settings ›
|
||||
// General turns it off, and they are back.
|
||||
// pages — Agents, the Library but its MCP tab — and their settings;
|
||||
// Settings › General turns it off, and they are back.
|
||||
let gatewayMode = web && !!window.bootPrefs?.gateway;
|
||||
const GATEWAY_HIDES = ["agents", "library"];
|
||||
const GATEWAY_HIDES = ["agents"];
|
||||
// Plugins › Built-in (builtins.go, Lxxyx): the window's parts switched off,
|
||||
// by id. data-feature="<id>" leaves by a style while off; its tab leaves the
|
||||
// nav (navHides), a link opens Agents (show), Settings skips its rows.
|
||||
@@ -20133,7 +20133,7 @@ function renderGatewayMode(s) {
|
||||
flag: t("Now on: magpie web was started with --gateway"),
|
||||
"no-agents": t("Now on: no agents on this computer"),
|
||||
}[s.gatewayWhy] || t("Now off: agents found on this computer");
|
||||
$("#gatewayModeSub").textContent = [t("Only what a gateway for other computers needs: no Agents or Library, nor this computer's agents' settings or sessions"), now].filter(Boolean).join(" · ");
|
||||
$("#gatewayModeSub").textContent = [t("Only what a gateway for other computers needs: no Agents page, nor this computer's agents' settings or sessions"), now].filter(Boolean).join(" · ");
|
||||
}
|
||||
|
||||
// renderLangPick: Settings' language, one menu button showing the language
|
||||
|
||||
@@ -1011,7 +1011,7 @@ const I18N = {
|
||||
"{name} doesn't ask to read {what}": "{name} 没有声明读取 {what}",
|
||||
"No such call: {what}": "没有这个调用:{what}",
|
||||
"The page hit an error": "页面出错了",
|
||||
"Only what a gateway for other computers needs: no Agents or Library, nor this computer's agents' settings or sessions": "只显示给其他电脑当网关所需的内容:不显示 Agent 和资源库,也不显示本机 Agent 的设置和会话",
|
||||
"Only what a gateway for other computers needs: no Agents page, nor this computer's agents' settings or sessions": "只显示给其他电脑当网关所需的内容:不显示 Agent 页面,也不显示本机 Agent 的设置和会话",
|
||||
"Now on: magpie web was started with --gateway": "当前开启:magpie web 以 --gateway 启动",
|
||||
"Now on: no agents on this computer": "当前开启:本机没有 Agent",
|
||||
"Now off: agents found on this computer": "当前关闭:本机找到了 Agent",
|
||||
@@ -4013,8 +4013,6 @@ const I18N = {
|
||||
"still sent": "仍发给模型",
|
||||
"Put RTK on PATH": "加到 PATH",
|
||||
"Update RTK": "需更新 RTK",
|
||||
"No agents to write to": "没有可写入的 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and the library can give them the same instructions, MCP servers and skills.": "安装 Claude Code、Codex、Gemini CLI、OpenCode 等之后,资源库就能给它们同一份指令、MCP 服务器和技能。",
|
||||
"magpie keeps a copy of every file before it writes it.": "magpie 写入任何文件前都会先备份一份。",
|
||||
"Backups": "备份",
|
||||
"Not saved yet": "尚未保存",
|
||||
@@ -5651,7 +5649,7 @@ const I18N = {
|
||||
"{name} doesn't ask to read {what}": "{name} 沒有宣告讀取 {what}",
|
||||
"No such call: {what}": "沒有這個呼叫:{what}",
|
||||
"The page hit an error": "頁面出錯了",
|
||||
"Only what a gateway for other computers needs: no Agents or Library, nor this computer's agents' settings or sessions": "只顯示給其他電腦當閘道所需的內容:不顯示 Agent 和資源庫,也不顯示本機 Agent 的設定和會話",
|
||||
"Only what a gateway for other computers needs: no Agents page, nor this computer's agents' settings or sessions": "只顯示給其他電腦當閘道所需的內容:不顯示 Agent 頁面,也不顯示本機 Agent 的設定和會話",
|
||||
"Now on: magpie web was started with --gateway": "目前開啟:magpie web 以 --gateway 啟動",
|
||||
"Now on: no agents on this computer": "目前開啟:本機沒有 Agent",
|
||||
"Now off: agents found on this computer": "目前關閉:本機找到了 Agent",
|
||||
@@ -8621,8 +8619,6 @@ const I18N = {
|
||||
"still sent": "仍發給模型",
|
||||
"Put RTK on PATH": "加到 PATH",
|
||||
"Update RTK": "需更新 RTK",
|
||||
"No agents to write to": "沒有可寫入的 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and the library can give them the same instructions, MCP servers and skills.": "安裝 Claude Code、Codex、Gemini CLI、OpenCode 等之後,資源庫就能給它們同一份指令、MCP 伺服器和技能。",
|
||||
"magpie keeps a copy of every file before it writes it.": "magpie 寫入任何檔案前都會先備份一份。",
|
||||
"Backups": "備份",
|
||||
"Not saved yet": "尚未儲存",
|
||||
@@ -10262,7 +10258,7 @@ const I18N = {
|
||||
"{name} doesn't ask to read {what}": "{name} は {what} の読み取りを宣言していません",
|
||||
"No such call: {what}": "そのような呼び出しはありません:{what}",
|
||||
"The page hit an error": "ページでエラーが起きました",
|
||||
"Only what a gateway for other computers needs: no Agents or Library, nor this computer's agents' settings or sessions": "他のコンピューターのゲートウェイに必要なものだけ:エージェント、ライブラリ、このコンピューターのエージェントの設定とセッションは表示しません",
|
||||
"Only what a gateway for other computers needs: no Agents page, nor this computer's agents' settings or sessions": "他のコンピューターのゲートウェイに必要なものだけ:エージェントのページ、このコンピューターのエージェントの設定とセッションは表示しません",
|
||||
"Now on: magpie web was started with --gateway": "現在オン:magpie web が --gateway で起動されています",
|
||||
"Now on: no agents on this computer": "現在オン:このコンピューターにエージェントがありません",
|
||||
"Now off: agents found on this computer": "現在オフ:このコンピューターにエージェントがあります",
|
||||
@@ -13245,8 +13241,6 @@ const I18N = {
|
||||
"still sent": "送信済み",
|
||||
"Put RTK on PATH": "PATH に追加",
|
||||
"Update RTK": "RTK の更新が必要",
|
||||
"No agents to write to": "書き込み先のエージェントがありません",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and the library can give them the same instructions, MCP servers and skills.": "Claude Code、Codex、Gemini CLI、OpenCode… をインストールすると、ライブラリが同じ指示、MCP サーバー、スキルを渡せます。",
|
||||
"magpie keeps a copy of every file before it writes it.": "magpie はファイルに書き込む前に必ずコピーを保存します。",
|
||||
"Backups": "バックアップ",
|
||||
"Not saved yet": "未保存",
|
||||
@@ -14888,7 +14882,7 @@ const I18N = {
|
||||
"{name} doesn't ask to read {what}": "{name} fragt nicht danach, {what} zu lesen",
|
||||
"No such call: {what}": "Kein solcher Aufruf: {what}",
|
||||
"The page hit an error": "Die Seite hat einen Fehler",
|
||||
"Only what a gateway for other computers needs: no Agents or Library, nor this computer's agents' settings or sessions": "Nur, was ein Gateway für andere Computer braucht: keine Agenten oder Bibliothek, keine Einstellungen oder Sitzungen der Agenten auf diesem Computer",
|
||||
"Only what a gateway for other computers needs: no Agents page, nor this computer's agents' settings or sessions": "Nur, was ein Gateway für andere Computer braucht: keine Agenten-Seite, keine Einstellungen oder Sitzungen der Agenten auf diesem Computer",
|
||||
"Now on: magpie web was started with --gateway": "Jetzt an: magpie web wurde mit --gateway gestartet",
|
||||
"Now on: no agents on this computer": "Jetzt an: keine Agenten auf diesem Computer",
|
||||
"Now off: agents found on this computer": "Jetzt aus: Agenten auf diesem Computer gefunden",
|
||||
@@ -17884,8 +17878,6 @@ const I18N = {
|
||||
"still sent": "noch gesendet",
|
||||
"Put RTK on PATH": "RTK in den PATH aufnehmen",
|
||||
"Update RTK": "RTK aktualisieren",
|
||||
"No agents to write to": "Keine Agenten zum Schreiben",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and the library can give them the same instructions, MCP servers and skills.": "Installieren Sie Claude Code, Codex, Gemini CLI, OpenCode…, und die Bibliothek kann ihnen dieselben Anweisungen, MCP-Server und Skills geben.",
|
||||
"magpie keeps a copy of every file before it writes it.": "magpie sichert jede Datei, bevor es sie schreibt.",
|
||||
"Backups": "Backups",
|
||||
"Not saved yet": "Noch nicht gespeichert",
|
||||
|
||||
@@ -69,7 +69,15 @@ magpie.plugin("library", (ctx) => {
|
||||
// places magpie never saw (unseen) only on the rows that name it, like
|
||||
// a gone one, its chip greyed out: opening its files would start WSL
|
||||
// (#3896, cybercaius on Discord).
|
||||
const shownAgents = () => lib.agents.filter((a) => !a.gone && !a.unseen && !isHidden(a));
|
||||
// In gateway mode (gatewaymode.go) none is shown: the page is the
|
||||
// MCP servers the router gives other computers' apps.
|
||||
const shownAgents = () => gatewayPage() ? [] : lib.agents.filter((a) => !a.gone && !a.unseen && !isHidden(a));
|
||||
// With no agent to write to, none on this computer or gateway mode, the
|
||||
// library is its MCP servers alone, served to any app through the router
|
||||
// (treeman_26897 on Discord: magpie on a server, an MCP entry point for
|
||||
// remote clients, had no way to turn the router on).
|
||||
const gatewayPage = () => typeof gatewayMode !== "undefined" && !!gatewayMode;
|
||||
const agentless = () => !!lib && (gatewayPage() || !lib.agents.length);
|
||||
const withGone = (all, on) => [...all, ...lib.agents.filter((a) => (a.gone || a.unseen && !isHidden(a)) && (on || []).includes(a.id) && !all.some((x) => x.id === a.id))];
|
||||
const mcpAgents = () => shownAgents().filter((a) => a.mcp)
|
||||
.map((a) => a.mcpVia ? { ...a, aside: t("{agent} reads MCP servers through the {ext} extension", { agent: a.name, ext: a.mcpVia }) } : a);
|
||||
@@ -816,7 +824,7 @@ magpie.plugin("library", (ctx) => {
|
||||
function libHead(counts) {
|
||||
const head = el("div", "lib-head");
|
||||
const n = (k) => (counts?.[k] ? " · " + counts[k] : "");
|
||||
const tabs = segs([
|
||||
const tabs = segs(agentless() ? [["mcp", t("MCP servers") + n("mcp")]] : [
|
||||
["instructions", t("Instructions")],
|
||||
["mcp", t("MCP servers") + n("mcp")],
|
||||
["skills", t("Skills") + n("skills")],
|
||||
@@ -873,13 +881,12 @@ magpie.plugin("library", (ctx) => {
|
||||
const caret = focus ? [document.activeElement.selectionStart, document.activeElement.selectionEnd] : null;
|
||||
page.replaceChildren();
|
||||
fits = [];
|
||||
// the MCP servers alone with no agent to write to; the tab the reader
|
||||
// last picked is kept for when there is one
|
||||
if (agentless()) tab = "mcp";
|
||||
const head = libHead({ mcp: lib.servers.length, skills: lib.skills.length, hooks: (lib.hooks || []).length, subagents: (lib.subagents || []).length });
|
||||
page.append(head);
|
||||
head.classList.toggle("stuck", top > 0);
|
||||
if (!lib.agents.length) {
|
||||
page.append(empty(t("No agents to write to"), t("Install Claude Code, Codex, Gemini CLI, OpenCode… and the library can give them the same instructions, MCP servers and skills.")));
|
||||
return;
|
||||
}
|
||||
// what changed in a tab is drawn in place: only another tab (or the
|
||||
// first one after the skeleton) fades in
|
||||
const problems = problemsCard();
|
||||
@@ -1640,12 +1647,17 @@ magpie.plugin("library", (ctx) => {
|
||||
const reaches = (s) => (a) => !a || (!(remote(s) && a.noRemote) && !(s.transport === "sse" && a.noSSE) && !(envRefs(s) && a.noEnvRefs));
|
||||
|
||||
function renderServers(body) {
|
||||
body.append(intro(t("Add a server once and switch it on for the agents that should have it — magpie writes it into each one's config in the shape that agent reads.")));
|
||||
body.append(intro(agentless()
|
||||
? t("Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.")
|
||||
: t("Add a server once and switch it on for the agents that should have it — magpie writes it into each one's config in the shape that agent reads.")));
|
||||
const all = mcpAgents();
|
||||
pickingFor("servers", lib.servers);
|
||||
if (!lib.servers.length) {
|
||||
const add = button(t("+ Add a server"), "action", () => editServer(null));
|
||||
body.append(empty(t("No servers in the library yet"), lib.foundServers.length ? t("Add one, or bring in those your agents already have, below.") : t("Paste a server's JSON from its README, or fill it in."), add));
|
||||
body.append(empty(t("No servers in the library yet"), lib.foundServers.length && !agentless() ? t("Add one, or bring in those your agents already have, below.") : t("Paste a server's JSON from its README, or fill it in."), add));
|
||||
// with no agent, the router is what the page is for: there to turn
|
||||
// on before the first server
|
||||
if (agentless()) body.append(...hubPart());
|
||||
} else {
|
||||
const list = el("div", "list lib-list");
|
||||
// in the order the reader picked (#481), A→Z till then
|
||||
@@ -1678,12 +1690,13 @@ magpie.plugin("library", (ctx) => {
|
||||
// checked only when the reader clicks its status (#1597, xiaozhu1337),
|
||||
// and again once it changed after that: a sign-in since isn't left
|
||||
// beside "needs sign-in" (新v学员 on Discord)
|
||||
const unchecked = lib.servers.filter((s) => (inUse(s) || health.has(s.name)) && health.get(s.name)?.key !== healthKey(s));
|
||||
// With no agent, the router is what starts them, so on it checks them too
|
||||
const unchecked = lib.servers.filter((s) => (inUse(s) || (agentless() && lib.mcpHub && inHub(s)) || health.has(s.name)) && health.get(s.name)?.key !== healthKey(s));
|
||||
queueMicrotask(() => checkHealth(unchecked));
|
||||
}
|
||||
// an agent's own servers (Codex's node_repl, added each time it starts)
|
||||
// aren't listed: magpie leaves them as they are
|
||||
const found = lib.foundServers.filter((f) => !f.own);
|
||||
const found = agentless() ? [] : lib.foundServers.filter((f) => !f.own);
|
||||
if (found.length) {
|
||||
const rh = el("div", "row-head");
|
||||
rh.append(el("span", "label", t("In your agents")), el("span", "grow"), el("span", "note", t("not in the library — bring one in to manage it here")));
|
||||
@@ -1692,10 +1705,10 @@ magpie.plugin("library", (ctx) => {
|
||||
for (const f of found) list.append(foundServerRow(f));
|
||||
body.append(list);
|
||||
}
|
||||
if (lib.servers.length || lib.projects.length) renderProjects(body, "mcp");
|
||||
if (!agentless() && (lib.servers.length || lib.projects.length)) renderProjects(body, "mcp");
|
||||
const skip = shownAgents().filter((a) => !a.mcp);
|
||||
if (skip.length) body.append(el("p", "lib-aside", t("{agents} has no MCP servers magpie can write.", { agents: skip.map((a) => a.name).join(", ") })));
|
||||
body.append(...asleepAsides());
|
||||
if (!gatewayPage()) body.append(...asleepAsides());
|
||||
// WorkBuddy connects a server only once it is trusted there, again
|
||||
// after its command or address changes (#1266)
|
||||
for (const wb of shownAgents().filter((a) => (a.id === "workbuddy" || a.id === "workbuddy-ai") && a.mcp)) {
|
||||
@@ -1716,12 +1729,16 @@ magpie.plugin("library", (ctx) => {
|
||||
const row = el("div", "row lib-row lib-hub");
|
||||
const who = el("div", "who");
|
||||
who.append(el("div", "name", t("MCP router")));
|
||||
who.append(el("div", "sub wraps", lib.mcpHub
|
||||
who.append(el("div", "sub wraps", agentless()
|
||||
? (lib.mcpHub ? t("Any app connects at the address below for every server in the library, as server__tool.") : t("Serve every server in the library at one address, for any app to connect to."))
|
||||
: lib.mcpHub
|
||||
? t("Each agent is given one server, magpie, in place of these. magpie runs each server once for all of them and hands each call to it, as server__tool. Restart an agent for it to read the change.")
|
||||
: t("Serve every server through magpie: each agent is given one server, magpie, in place of these, and any other app connects at one address.")));
|
||||
if (lib.mcpHub) who.append(el("div", "sub lib-hubstats", hubStats()));
|
||||
row.append(hubMark(), who, toggle(!!lib.mcpHub, t("MCP router"), (on) =>
|
||||
change("servers/hub", { on }, on
|
||||
change("servers/hub", { on }, agentless()
|
||||
? (on ? t("The MCP router is on: apps can connect at its address") : t("The MCP router is off"))
|
||||
: on
|
||||
? t("The agents are given magpie's one MCP server — restart them to use it")
|
||||
: t("The agents are given each server's own entry again — restart them to use it"))));
|
||||
list.append(row);
|
||||
@@ -1841,7 +1858,7 @@ magpie.plugin("library", (ctx) => {
|
||||
const given = hubAgents().filter((a) => a.hub === "on").map((a) => a.name);
|
||||
if (given.length) parts.push(t("in {agents}", { agents: given.length > 3 ? t("{first} and {n} more", { first: given.slice(0, 2).join(", "), n: given.length - 2 }) : given.join(", ") }));
|
||||
// the owner, counting two servers and seeing one: where the other went
|
||||
const direct = directNames();
|
||||
const direct = agentless() ? "" : directNames();
|
||||
if (direct) parts.push(t("{name} is given to each agent directly", { name: direct }));
|
||||
return parts.join(" · ");
|
||||
}
|
||||
@@ -2123,7 +2140,8 @@ magpie.plugin("library", (ctx) => {
|
||||
sub.title = serverLine(s);
|
||||
who.append(noteSub(s.note, sub, serverLine(s)), toolsEl(s.name));
|
||||
row.append(mark(s.icon, s.transport === "stdio" ? GLYPH.cmd : GLYPH.web), who, ...removeAct(() => confirmRemoveServer(s)),
|
||||
agentChips(withGone(all, s.agents), s.agents, chipsChange("servers/agents", s.name, "servers", (x) => serverRow(x, all)), { problems: s.problems, blocked: sseBlocked(s), all: true }));
|
||||
// no agent to give it to: other apps reach it through the router
|
||||
...(agentless() ? [] : [agentChips(withGone(all, s.agents), s.agents, chipsChange("servers/agents", s.name, "servers", (x) => serverRow(x, all)), { problems: s.problems, blocked: sseBlocked(s), all: true })]));
|
||||
if (picking) return pickRow(row, s.name);
|
||||
// a line of its own under the row, not in the name's column (tao0194)
|
||||
if (s.name === "magpie-browser" && !s.agents?.length) row.append(browserAsk(row));
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
// kernel adds them to i18n.js's (magpie.strings).
|
||||
magpie.strings({
|
||||
zh: {
|
||||
"The MCP router is on: apps can connect at its address": "MCP 路由已打开:应用可以连接它的地址",
|
||||
"The MCP router is off": "MCP 路由已关闭",
|
||||
"Any app connects at the address below for every server in the library, as server__tool.": "任何应用连接下面的地址,即可使用资源库里的全部服务器,工具名为 server__tool。",
|
||||
"Serve every server in the library at one address, for any app to connect to.": "在一个地址上提供资源库里的全部服务器,供任何应用连接。",
|
||||
"Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.": "添加其他应用要用的服务器,再打开 MCP 路由:它们连接路由地址,从其他电脑连接时需要网关密钥。",
|
||||
"Tools on demand": "按需加载工具",
|
||||
"An agent given more than 10 tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request. Claude Code, Claude Desktop, Codex and Pi find tools themselves and are given every one.": "给一个 Agent 的工具超过 10 个时,改为给它两个工具:一个查找工具,一个运行工具,这样工具定义不会出现在每次请求里。Claude Code、Claude Desktop、Codex 和 Pi 会自己查找工具,仍会拿到全部工具。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "Agent 现在按需拿到路由的工具 — 重启它们后生效",
|
||||
@@ -784,6 +789,11 @@ magpie.strings({
|
||||
"{agents} can be changed once it runs.": "{agents} 要等它运行后才能修改。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"The MCP router is on: apps can connect at its address": "MCP 路由已開啟:應用程式可以連線到它的位址",
|
||||
"The MCP router is off": "MCP 路由已關閉",
|
||||
"Any app connects at the address below for every server in the library, as server__tool.": "任何應用程式連線下面的位址,即可使用資源庫裡的全部伺服器,工具名稱為 server__tool。",
|
||||
"Serve every server in the library at one address, for any app to connect to.": "在一個位址上提供資源庫裡的全部伺服器,供任何應用程式連線。",
|
||||
"Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.": "新增其他應用程式要用的伺服器,再開啟 MCP 路由:它們連線路由位址,從其他電腦連線時需要閘道金鑰。",
|
||||
"Tools on demand": "按需載入工具",
|
||||
"An agent given more than 10 tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request. Claude Code, Claude Desktop, Codex and Pi find tools themselves and are given every one.": "給一個 Agent 的工具超過 10 個時,改為給它兩個工具:一個尋找工具,一個執行工具,這樣工具定義不會出現在每次請求裡。Claude Code、Claude Desktop、Codex 和 Pi 會自己尋找工具,仍會拿到全部工具。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "Agent 現在按需取得路由的工具 — 重新啟動它們後生效",
|
||||
@@ -1566,6 +1576,11 @@ magpie.strings({
|
||||
"{agents} can be changed once it runs.": "{agents} 要等它執行後才能修改。",
|
||||
},
|
||||
ja: {
|
||||
"The MCP router is on: apps can connect at its address": "MCP ルーターをオンにしました:アプリはそのアドレスに接続できます",
|
||||
"The MCP router is off": "MCP ルーターをオフにしました",
|
||||
"Any app connects at the address below for every server in the library, as server__tool.": "どのアプリも下のアドレスに接続すると、ライブラリのすべてのサーバーを server__tool として使えます。",
|
||||
"Serve every server in the library at one address, for any app to connect to.": "ライブラリのすべてのサーバーを一つのアドレスで提供し、どのアプリからも接続できるようにします。",
|
||||
"Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.": "他のアプリが使うサーバーを追加し、MCP ルーターをオンにします:アプリはルーターのアドレスに接続し、他のコンピューターからはゲートウェイキーが必要です。",
|
||||
"Tools on demand": "ツールをオンデマンドで渡す",
|
||||
"An agent given more than 10 tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request. Claude Code, Claude Desktop, Codex and Pi find tools themselves and are given every one.": "エージェントに渡すツールが 10 個を超えると、代わりにツールを探すものと実行するものの 2 つを渡し、ツールの定義が毎回のリクエストに入らないようにします。Claude Code、Claude Desktop、Codex、Pi は自分でツールを探すので、すべてのツールが渡されます。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "エージェントにルーターのツールをオンデマンドで渡します — 反映するにはエージェントを再起動してください",
|
||||
@@ -2348,6 +2363,11 @@ magpie.strings({
|
||||
"{agents} can be changed once it runs.": "{agents} は起動後に変更できます。",
|
||||
},
|
||||
de: {
|
||||
"The MCP router is on: apps can connect at its address": "Der MCP-Router ist an: Apps verbinden sich mit seiner Adresse",
|
||||
"The MCP router is off": "Der MCP-Router ist aus",
|
||||
"Any app connects at the address below for every server in the library, as server__tool.": "Jede App verbindet sich mit der Adresse unten und erreicht jeden Server der Bibliothek, als server__tool.",
|
||||
"Serve every server in the library at one address, for any app to connect to.": "Stellt jeden Server der Bibliothek unter einer Adresse bereit, mit der sich jede App verbinden kann.",
|
||||
"Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.": "Fügen Sie die Server hinzu, die andere Apps erreichen sollen, und schalten Sie den MCP-Router ein: Sie verbinden sich mit seiner Adresse, von einem anderen Computer mit einem Gateway-Schlüssel.",
|
||||
"Tools on demand": "Tools bei Bedarf",
|
||||
"An agent given more than 10 tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request. Claude Code, Claude Desktop, Codex and Pi find tools themselves and are given every one.": "Ein Agent, der mehr als 10 Tools bekäme, bekommt stattdessen zwei: eines findet ein Tool, das andere führt es aus, damit ihre Definitionen nicht in jeder Anfrage stehen. Claude Code, Claude Desktop, Codex und Pi suchen Tools selbst und bekommen alle.",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "Agents bekommen die Tools des Routers bei Bedarf — starte sie neu, damit sie es nutzen",
|
||||
|
||||
@@ -16,8 +16,9 @@ import (
|
||||
|
||||
// Gateway mode (Player on Discord): `magpie web` on a server that is only
|
||||
// the gateway for other machines' agents shows what such a gateway needs —
|
||||
// Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings — and leaves out
|
||||
// what is this machine's agents' (Agents, Library, the settings
|
||||
// Providers, Gateway, Routing, Usage, Sessions, Plugins, Settings and the
|
||||
// Library's MCP servers with the router (treeman_26897) — and leaves out
|
||||
// what is this machine's agents' (Agents, the Library's other tabs, the settings
|
||||
// written into agents' files) and its desktop's (the tray, the Dock, open
|
||||
// at login, notifications). It is the browser page's alone: the app's
|
||||
// windows show everything whatever it says.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Gateway mode (Player on Discord): magpie web on a server that is only
|
||||
// the gateway for other computers' agents. boot.js says so and the page
|
||||
// opens on Providers with no Agents or Library tab, an address
|
||||
// opens on Providers with no Agents tab, an address
|
||||
// kept for one of them opening Providers; Settings leaves out what is
|
||||
// written into this computer's agents' files (provider in model names;
|
||||
// the Codex and Claude Code settings live on the Agents page, which is
|
||||
@@ -82,9 +82,10 @@ const L = {
|
||||
en: { mode: "Gateway mode", noAgents: "Now on: no agents on this computer", off: "Now off: agents found on this computer" },
|
||||
zh: { mode: "网关模式", noAgents: "当前开启:本机没有 Agent", off: "当前关闭:本机找到了 Agent" },
|
||||
};
|
||||
const HIDDEN = ["agents", "library"];
|
||||
// the Library stays, its MCP servers alone, for the router (treeman_26897)
|
||||
const HIDDEN = ["agents"];
|
||||
// in the order the pages are grouped in (work, models, insights, extend)
|
||||
const KEPT = ["sessions", "providers", "routing", "gateway", "usage", "masking", "plugins"];
|
||||
const KEPT = ["sessions", "library", "providers", "routing", "gateway", "usage", "masking", "plugins"];
|
||||
|
||||
// the tabs shown, the page shown
|
||||
const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent).map((b) => b.dataset.view));
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// again (no ?view=) and reloaded is on Routing, its tab picked, nothing
|
||||
// scrolled. A page asked for (?view=, the tray's links) wins over the one
|
||||
// kept, Agents too. A page kept that isn't one, or one gateway mode leaves
|
||||
// out (Agents, Library), gives way to the first page (Providers there).
|
||||
// out (Agents), gives way to the first page (Providers there).
|
||||
// Chromium and WebKit, 1100 (sidebar) and 420 (header's tabs) wide. No
|
||||
// backend: the API is faked.
|
||||
const assert = require("node:assert/strict");
|
||||
@@ -100,7 +100,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(errors, [], where);
|
||||
await context.close();
|
||||
|
||||
// magpie web in gateway mode: Agents and Library aren't there
|
||||
// magpie web in gateway mode: Agents isn't there (the Library is, for
|
||||
// its MCP router)
|
||||
const gw = await browser.newContext({ viewport: { width, height: 640 }, reducedMotion: "reduce" });
|
||||
const gp = await gw.newPage();
|
||||
gp.setDefaultTimeout(5000);
|
||||
@@ -109,7 +110,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
gp.on("pageerror", (e) => gerr.push(e.message));
|
||||
await gp.route("**/*", server({ web: true, gateway: true }));
|
||||
await open(gp, BASE, "providers", `${where} gateway: first open`);
|
||||
for (const v of ["agents", "library"]) {
|
||||
for (const v of ["agents"]) {
|
||||
await keep(gp, v);
|
||||
await open(gp, BASE, "providers", `${where} gateway: ${v} kept`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// treeman_26897 on Discord: magpie run as an MCP entry point for remote
|
||||
// clients has no agents, and the MCP router could only be turned on with
|
||||
// one to write to: the Library said "No agents to write to", and in
|
||||
// gateway mode (magpie web on such a server) it wasn't there at all.
|
||||
// With no agent, or in gateway mode, the Library is its MCP tab alone: the
|
||||
// servers with no agent chips, nothing from agents' own configs, and the
|
||||
// router's switch, there before the first server too. Its lines say any
|
||||
// app connects at the address; a click posts servers/hub on, says the
|
||||
// router is on, counts what it serves and shows the address, and Connect…
|
||||
// has Other apps alone, with the gateway key a remote app needs. In every
|
||||
// language, both engines, the app with no agents at 1100px and a browser
|
||||
// in gateway mode at 420px: no sideways scroll, no native select.
|
||||
// No backend: the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { strings } = require("./strings.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const HOME = "/srv/mg";
|
||||
const fixture = (st) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
mcpHub: st.on, hubPath: "/mcp/magpie/hub/",
|
||||
// in gateway mode this computer's agents are there, and not shown
|
||||
agents: st.gateway ? [{ id: "claude", name: "Claude Code", icon: "claudecode-color", skills: `${HOME}/.claude/skills`, mcp: `${HOME}/.claude.json`, ...(st.on ? { hub: "on" } : {}) }] : [],
|
||||
instructions: { agents: [], sets: [] }, foundSkills: [], skills: [], problems: [],
|
||||
foundServers: st.gateway ? [{ name: "agent-own", transport: "stdio", command: "npx", args: ["agent-own"], agents: ["claude"] }] : [],
|
||||
projects: st.gateway ? [{ path: `${HOME}/code/app`, servers: { notes: ["claude"] } }] : [],
|
||||
servers: st.none ? [] : [{ name: "notes", transport: "stdio", command: "uvx", args: ["notes-mcp"], agents: st.gateway ? ["claude"] : [] }],
|
||||
});
|
||||
|
||||
let I18N;
|
||||
function tr(lang, key, vars = {}) {
|
||||
let s = key;
|
||||
if (lang !== "en") {
|
||||
assert.equal(typeof I18N[lang][key], "string", `${lang} has no ${JSON.stringify(key)}`);
|
||||
s = I18N[lang][key];
|
||||
}
|
||||
return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
|
||||
}
|
||||
|
||||
function server(lang, st) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${st.web}${st.gateway ? ",gateway:true" : ""}};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", gateway: "http://127.0.0.1:3425", publicURL: "https://mcp.example.net" } });
|
||||
if (url.pathname === "/api/library") return json(fixture(st));
|
||||
if (url.pathname === "/api/library/servers/hub") {
|
||||
const body = req.postDataJSON();
|
||||
st.sent.push(body);
|
||||
st.on = body.on;
|
||||
return json({ ...fixture(st), result: { changed: [] } });
|
||||
}
|
||||
if (url.pathname === "/api/library/mcp/check") {
|
||||
const names = req.postDataJSON().names;
|
||||
st.checked.push(...names);
|
||||
return json({ servers: Object.fromEntries(names.map((n) => [n, { state: "ok", tools: 2 }])) });
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
const sideways = (page) => page.evaluate(() => {
|
||||
const over = [];
|
||||
const w = document.documentElement.clientWidth;
|
||||
if (document.documentElement.scrollWidth > w) over.push("page " + document.documentElement.scrollWidth);
|
||||
for (const e of document.querySelectorAll("#view-library .lib-hub, #view-library .lib-hub .lib-switch, #view-library .lib-server, #view-library .lib-hubat, #view-library .lib-hubat .lib-hubconnect, .lib-hubsheet, .lib-hubsheet .lib-hubapp, .lib-hubsheet .lib-hubaddr, .lib-hubsheet .bar button")) {
|
||||
const r = e.getBoundingClientRect();
|
||||
if (r.width && (r.right > w + 0.5 || r.left < -0.5)) over.push((e.className || e.tagName) + " " + Math.round(r.left) + "–" + Math.round(r.right));
|
||||
}
|
||||
return over;
|
||||
});
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": the MCP router with no agent", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
I18N = strings().I18N;
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
|
||||
for (const width of [1100, 420]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
await t.test(`${lang} ${width}px`, async () => {
|
||||
const w = (key, vars) => tr(lang, key, vars);
|
||||
// the app with no agents; a browser in gateway mode, its agent not shown
|
||||
const web = width < 800;
|
||||
const st = { on: false, sent: [], checked: [], web, gateway: web, none: false };
|
||||
const where = web ? "gateway mode" : "no agents";
|
||||
const url = (web ? "https://mcp.example.net" : "http://127.0.0.1:3425") + "/mcp/magpie/hub";
|
||||
const errors = [];
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
// the Skills tab last left: there is only MCP now
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, st));
|
||||
await page.goto("http://magpie.test/");
|
||||
// the Library is a page in gateway mode too
|
||||
const nav = page.locator('button[data-view="library"]');
|
||||
assert.ok(await nav.isVisible(), `${where}: no Library tab`);
|
||||
await nav.click();
|
||||
const v = page.locator("#view-library");
|
||||
const hub = v.locator(".lib-hub");
|
||||
await hub.waitFor();
|
||||
|
||||
// the MCP tab alone, and nothing of agents
|
||||
assert.deepEqual((await v.locator(".lib-tabs .opt").allTextContents()).map((x) => x.trim().replace(/ · \d+$/, "")), [w("MCP servers")], `${where}: the tabs`);
|
||||
assert.equal((await v.locator(".lib-intro").first().textContent()).trim(), w("Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key."), where);
|
||||
assert.equal(await v.locator(".lib-server").count(), 1, where);
|
||||
assert.equal(await v.locator(".lib-ag, .lib-agents").count(), 0, `${where}: agent chips`);
|
||||
const text = await v.textContent();
|
||||
for (const gone of [w("In your agents"), w("In projects"), "Claude Code", "agent-own"]) assert.ok(!text.includes(gone), `${where}: ${gone} is shown`);
|
||||
assert.equal(await page.locator("select").count(), 0);
|
||||
|
||||
// off: what it would do
|
||||
assert.equal((await hub.locator(".name").textContent()).trim(), w("MCP router"));
|
||||
assert.equal((await hub.locator(".sub.wraps").textContent()).trim(), w("Serve every server in the library at one address, for any app to connect to."));
|
||||
const sw = hub.locator(".lib-switch");
|
||||
assert.equal(await sw.getAttribute("aria-checked"), "false");
|
||||
assert.equal(await v.locator(".lib-hubat").count(), 0);
|
||||
assert.deepEqual(await sideways(page), [], `${where}: sideways scroll, off`);
|
||||
|
||||
// on: the router is on, what it serves, and its address
|
||||
await sw.click();
|
||||
await page.waitForFunction((x) => document.querySelector("#status")?.textContent === x, w("The MCP router is on: apps can connect at its address"));
|
||||
assert.deepEqual(st.sent, [{ on: true }]);
|
||||
await page.waitForFunction(() => document.querySelector("#view-library .lib-hub .lib-switch")?.getAttribute("aria-checked") === "true");
|
||||
assert.equal((await v.locator(".lib-hub .sub.wraps").textContent()).trim(), w("Any app connects at the address below for every server in the library, as server__tool."));
|
||||
await page.waitForFunction((x) => document.querySelector("#view-library .lib-hubstats")?.textContent === x, [w("1 server"), w("{n} tools", { n: 2 })].join(" · "));
|
||||
assert.ok(st.checked.includes("notes"), `${where}: the router's server isn't checked`);
|
||||
assert.equal((await v.locator(".lib-hubURL").textContent()).trim(), url);
|
||||
assert.deepEqual(await sideways(page), [], `${where}: sideways scroll, on`);
|
||||
|
||||
// Connect…: other apps alone, with the gateway key
|
||||
await v.locator(".lib-hubconnect").click();
|
||||
const sheet = page.locator(".lib-hubsheet");
|
||||
await sheet.waitFor();
|
||||
assert.equal(await sheet.locator(".ebody > .segs").count(), 0, `${where}: the sheet has tabs`);
|
||||
assert.equal(await sheet.locator(".lib-hubagent").count(), 0);
|
||||
assert.equal((await sheet.locator(".lib-hubaddr code").textContent()).trim(), url);
|
||||
assert.ok(await sheet.locator(".lib-hubapp").count() >= 3);
|
||||
assert.equal((await sheet.locator(".lib-hubcap").textContent()).trim(), w("From another computer, use the address magpie is reached at there, with a gateway key: Authorization: Bearer <key>."));
|
||||
assert.deepEqual(await sideways(page), [], `${where}: sideways scroll, sheet`);
|
||||
await sheet.locator(".bar button.primary").click();
|
||||
await sheet.waitFor({ state: "hidden" });
|
||||
|
||||
// off again
|
||||
await v.locator(".lib-hub .lib-switch").click();
|
||||
await page.waitForFunction((x) => document.querySelector("#status")?.textContent === x, w("The MCP router is off"));
|
||||
assert.deepEqual(st.sent, [{ on: true }, { on: false }]);
|
||||
|
||||
// no server yet: the switch is there to turn on first
|
||||
st.none = true;
|
||||
await page.reload();
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
await v.locator(".lib-hub").waitFor();
|
||||
assert.equal(await v.locator(".lib-server").count(), 0);
|
||||
assert.ok((await v.textContent()).includes(w("Paste a server's JSON from its README, or fill it in.")), where);
|
||||
assert.equal(await v.locator(".lib-hub .lib-switch").getAttribute("aria-checked"), "false");
|
||||
assert.deepEqual(await sideways(page), [], `${where}: sideways scroll, no server`);
|
||||
|
||||
assert.deepEqual(errors, []);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -129,7 +129,7 @@ docker logs magpie</pre>
|
||||
|
||||
<h2 id="web"><a class="anchor" href="#web">The browser UI</a></h2>
|
||||
<p>Open the link from the log. The key in it is traded for a cookie and taken out of the address; a page opened without it is turned away (401). With <code>MAGPIE_WEB_KEY</code> set (16 or more letters, digits or <code>- . _ ~</code>; <code>openssl rand -hex 16</code> makes one) the key stays the same across restarts and the browser stays signed in for 400 days. Without it, every start makes a new key and the cookie lasts the browser session.</p>
|
||||
<p>The page is in <b>gateway mode</b>: <span class="ui">Providers</span>, <span class="ui">Gateway</span>, <span class="ui">Routing</span>, <span class="ui">Usage</span>, <span class="ui">Sessions</span>, <span class="ui">Plugins</span> and <span class="ui">Settings</span>, with no Agents or Library, since there are no agents in the container. <span class="ui">Sessions</span> lists only the sessions of agents on other computers that came through this gateway, never this machine’s agents’ files. <span class="ui">Settings</span> → <span class="ui">General</span> → <span class="ui">Gateway mode</span> turns it off.</p>
|
||||
<p>The page is in <b>gateway mode</b>: <span class="ui">Providers</span>, <span class="ui">Gateway</span>, <span class="ui">Routing</span>, <span class="ui">Usage</span>, <span class="ui">Sessions</span>, <span class="ui">Plugins</span> and <span class="ui">Settings</span>, with no Agents, since there are no agents in the container. <span class="ui">Library</span> has its MCP servers alone, with the MCP router: other computers’ apps connect at the router’s address with a gateway key. <span class="ui">Sessions</span> lists only the sessions of agents on other computers that came through this gateway, never this machine’s agents’ files. <span class="ui">Settings</span> → <span class="ui">General</span> → <span class="ui">Gateway mode</span> turns it off.</p>
|
||||
<p>On a NAS or a server you reach over SSH, open the page through a tunnel rather than publishing 3430: <code>ssh -L 3430:127.0.0.1:3430 you@nas</code>, then the log’s link on your own computer.</p>
|
||||
<div class="callout"><b>Anyone with the link can change magpie and see its keys.</b> Keep 3430 on loopback or a VPN. Across the network, serve it over HTTPS: give magpie a certificate with <code>MAGPIE_TLS_CERT</code> and <code>MAGPIE_TLS_KEY</code>, or put it behind a reverse proxy with TLS, such as Caddy.</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user