library: the Tools on demand row names the agents the gateway gives every tool
The row under the MCP router said "Claude Code, Claude Desktop, Codex and
Pi find tools themselves and are given every one", but hubOnDemand gives
every tool to Droid and omp too (hubSearchesItself). The words now come
from the code: gateway.HubFindsItself (the ordered list hubSearchesItself
is built from) and gateway.HubOnDemandOver reach the library's view as
hubFindsItself (each agent by its name, its id when none is found) and
hubOnDemandOver, and the row joins them with the language's list
separator. Two keys replace the old sentence in zh, zh-TW, ja and de; the
CJK sentences follow each other with no space.
Tests:
- TestHubFindsItselfIsWhoGetsEveryTool: every named agent (and its WSL
id) is given every tool, every agent given every tool is named, and
other agents get theirs on demand.
- TestHubFindsItselfInTheView: /api/library carries the gateway's list
and threshold, each agent by its name.
- library-mcp-router-tools.test.cjs: the row's text is built from the
view's list and count (fixture: 12, six agents), names each one, never
says 10, and has no "。 ".
Run (wsl-run, magpie-desktop; mote was at load 46-49 of 18, mica's disk
full), at this tree on 35a03fee0:
- gofmt -l internal/gateway internal/library internal/gui: clean
- go vet -tags nogui, and GOOS=windows go vet -tags nogui, of
./internal/gateway ./internal/library ./internal/gui: ok
- go test -count=1 ./internal/gateway -run 'Hub|MCP': ok
- go test -count=1 ./internal/gui ./internal/testenv: ok (134s)
- go test -count=1 ./internal/library: ok (183s)
- node --test i18n-keys, library-mcp-router-tools,
library-mcp-router-note, library-mcp-hub (chromium and webkit; 1100
and 420 wide; en, zh, zh-TW, ja, de): 70 of 70 ok
Broken by hand (a copy of this tree): dropping omp from the list while
omp still gets every tool, TestHubFindsItselfIsWhoGetsEveryTool fails
"omp is given every tool but not named"; putting the old hardcoded "10"
and four names back into the row, library-mcp-router-tools fails in
every language. That run also showed "。 " in zh, fixed here.
Not run: the full go test ./... and the whole GUI suite; the real app.
This commit is contained in:
@@ -19,7 +19,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. With no agent to write to, or in gateway mode (where no agent is shown), the Library is its MCP tab, beside Skills and Instructions for a Remote magpie's clients (`agentless`, `AGENTLESS_TABS` in client.js; it opens on MCP unless the reader picked one of the three): 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` |
|
||||
| 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), its words saying the threshold and the agents that search their tools themselves from the view's `hubOnDemandOver` and `hubFindsItself` (`gateway.HubOnDemandOver`, `gateway.HubFindsItself`, the list `hubSearchesItself` is built from, each agent by its name), never written into the text (they named four of the six; `TestHubFindsItselfIsWhoGetsEveryTool`, `TestHubFindsItselfInTheView`, `library-mcp-router-tools.test.cjs`), 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, beside Skills and Instructions for a Remote magpie's clients (`agentless`, `AGENTLESS_TABS` in client.js; it opens on MCP unless the reader picked one of the three): 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` |
|
||||
| A Remote magpie's router | With another magpie as a provider (preset `remote-magpie`), its router's servers took adding that magpie again under Library → MCP (treeman_26897 on Discord). The gateway's info (`GET /v1`) says `"mcp_hub": true` to a caller it serves MCP to (`local` or `sharedWith`) while the switch is on with a server that isn't another magpie's router (`hubServes`). A fetch of a Remote magpie's models (`fetch` → `noteRemoteHub`, not one found to be this magpie) asks that info with the provider's key, only while the library would give it a server (`RemoteHubAsk`: its id is in `bridgesOn` and isn't in `bridgesOffered`), and `RemoteHubFound` then adds one server: named for the provider (`bridgeName`), `http` at `<root>/mcp/magpie/hub` with `Authorization: Bearer <key>`, `bridge` = the provider's id, `local`, on for the agents given the hub's entry. It is the user's call (treeman_26897 again): the Remote magpie's editor has a switch, "Add its MCP servers to the Library" (`libraryMCP` in `/api/providers` and the save; `library.RemoteMCPOn`, `library.SetRemoteMCP`), off when one is added. On puts its id in `bridgesOn` and asks at once (`provider.AskRemoteHub`); off takes its server out. A server added before the switch (no `bridgesOn`) is kept and shows the switch on. Offered once each time it is switched on: a server removed in the Library turns the switch off (`removeServer`), one switched off for an agent stays off. Renamed, the provider's `Was` carries its server's `bridge`, `bridgesOn` and `bridgesOffered` to its id now (`adoptBridges`); the server keeps its name. A server the user has at that magpie's router already (same origin, the router's path) is the one, and none is added. The provider gone takes the server out (`adoptBridges`, at Sync and the View read); providers.json unreadable takes nothing out; the provider's address and key changed change the server's; edited to another address or key it is the user's own (`keptBridge`). No loop: every dial to a URL under `/mcp/magpie/hub` carries `X-Magpie-Router` (`remoteHeaders`), and a request with it (`gateway.FromRouter`) is given no `bridge` server, neither listed (`Tools`, `hubServersOf`) nor run (`Call`, `hubToolNamed`). | [`bridge_mcp.go`](../../internal/library/bridge_mcp.go); [`remote_hub.go`](../../internal/provider/remote_hub.go); `RouterHeader`, `hubServes` in [`hub_mcp.go`](../../internal/gateway/hub_mcp.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)).
|
||||
|
||||
@@ -48,7 +48,25 @@ const hubOnDemandOver = 10
|
||||
// omp (18.9) mounts every MCP tool as an xd:// device, its schema read only
|
||||
// when asked for: given find_tools in their place, neither showed its
|
||||
// model which tools were behind it (tao5010 on Discord, 11-04).
|
||||
var hubSearchesItself = map[string]bool{"claude": true, "claude-desktop": true, "codex": true, "pi": true, "droid": true, "omp": true}
|
||||
// The Library's Tools on demand row names them from HubFindsItself, so its
|
||||
// words can't leave one out again (they named four of the six, 11-18).
|
||||
var hubSearchers = []string{"claude", "claude-desktop", "codex", "pi", "droid", "omp"}
|
||||
|
||||
var hubSearchesItself = func() map[string]bool {
|
||||
m := map[string]bool{}
|
||||
for _, id := range hubSearchers {
|
||||
m[id] = true
|
||||
}
|
||||
return m
|
||||
}()
|
||||
|
||||
// HubFindsItself is the agents given every tool whole because they search
|
||||
// their MCP tools themselves (hubSearchesItself), by id, in the order the
|
||||
// Library names them.
|
||||
func HubFindsItself() []string { return slices.Clone(hubSearchers) }
|
||||
|
||||
// HubOnDemandOver is hubOnDemandOver, for the Library to say.
|
||||
const HubOnDemandOver = hubOnDemandOver
|
||||
|
||||
// hubFindFull is how many of find_tools' matches come with their
|
||||
// parameters, and hubFindMore how many more it names after them.
|
||||
|
||||
@@ -248,3 +248,26 @@ func TestHubFindToolsSaysWhatIsBehind(t *testing.T) {
|
||||
t.Fatalf("with 40 servers find_tools' description is %d characters (at most %d): %s", runeLen(find), max, find)
|
||||
}
|
||||
}
|
||||
|
||||
// HubFindsItself, which the Library's Tools on demand row names, is every
|
||||
// agent hubOnDemand gives every tool whole and no other: its words named
|
||||
// four of the six (11-18).
|
||||
func TestHubFindsItselfIsWhoGetsEveryTool(t *testing.T) {
|
||||
fresh(t)
|
||||
n := hubOnDemandOver + 1
|
||||
for _, id := range HubFindsItself() {
|
||||
if hubOnDemand(id, n) || hubOnDemand(id+"@wsl:Ubuntu", n) {
|
||||
t.Fatalf("%s is named as searching itself but is given its tools on demand", id)
|
||||
}
|
||||
}
|
||||
for id := range hubSearchesItself {
|
||||
if !slices.Contains(HubFindsItself(), id) {
|
||||
t.Fatalf("%s is given every tool but not named", id)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"opencode", "gemini", "kimi", "qwen", "goose", "crush", "copilot", "cursor"} {
|
||||
if !hubOnDemand(id, n) {
|
||||
t.Fatalf("%s is given every tool but not named", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3051,11 +3051,22 @@ magpie.plugin("library", (ctx) => {
|
||||
// itself and is given more than a few is given two in their place, one
|
||||
// finding a tool and one running it (gateway.hubOnDemand). Off gives
|
||||
// every agent every tool whole (settings' routerAllTools).
|
||||
// what the row says: the threshold and the agents that search their
|
||||
// tools themselves come from the gateway's own (hubOnDemandOver,
|
||||
// hubFindsItself in the library's view), so the words can't leave one
|
||||
// out again: they named four of the six (11-18)
|
||||
function hubToolsSay() {
|
||||
const say = t("An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.", { n: lib.hubOnDemandOver });
|
||||
const finds = lib.hubFindsItself || [];
|
||||
if (finds.length < 2) return say;
|
||||
// a sentence ending in a full-width stop (zh, ja) is followed by none
|
||||
return say + (say.endsWith("。") ? "" : " ") + t("{list} and {last} find tools themselves and are given every one.", { list: finds.slice(0, -1).join(t(", ")), last: finds.at(-1) });
|
||||
}
|
||||
function hubToolsRow() {
|
||||
const row = el("div", "row lib-row lib-hubtoolsrow");
|
||||
const who = el("div", "who");
|
||||
who.append(el("div", "name", t("Tools on demand")));
|
||||
who.append(el("div", "sub wraps", t("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.")));
|
||||
who.append(el("div", "sub wraps", hubToolsSay()));
|
||||
const on = !lib.hubAllTools;
|
||||
row.append(glyph(GLYPH.search), who, toggle(on, t("Tools on demand"), (v) =>
|
||||
change("servers/hub-tools", { on: !v }).then((ok) => {
|
||||
|
||||
@@ -117,7 +117,8 @@ magpie.strings({
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these skills and gives them to its agents.": "其他电脑上的 magpie 把这个 magpie 添加为供应商并打开“使用它的技能和提示词”后,会拿到这些技能,交给它的 Agent。",
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these sets, and its agents read them.": "其他电脑上的 magpie 把这个 magpie 添加为供应商并打开“使用它的技能和提示词”后,会拿到这些指令集,由它的 Agent 读取。",
|
||||
"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 会自己查找工具,仍会拿到全部工具。",
|
||||
"An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.": "给一个 Agent 的工具超过 {n} 个时,改为给它两个工具:一个查找工具,一个运行工具,这样工具定义不会出现在每次请求里。",
|
||||
"{list} and {last} find tools themselves and are given every one.": "{list} 和 {last} 会自己查找工具,仍会拿到全部工具。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "Agent 现在按需拿到路由的工具 — 重启它们后生效",
|
||||
"Agents are given every tool of the router — restart them to use it": "Agent 现在拿到路由的全部工具 — 重启它们后生效",
|
||||
"Show more ({n} left)": "显示更多(还有 {n} 个)",
|
||||
@@ -1224,7 +1225,8 @@ magpie.strings({
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these skills and gives them to its agents.": "其他電腦上的 magpie 把這個 magpie 新增為供應商並開啟「使用它的技能和提示詞」後,會拿到這些技能,交給它的 Agent。",
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these sets, and its agents read them.": "其他電腦上的 magpie 把這個 magpie 新增為供應商並開啟「使用它的技能和提示詞」後,會拿到這些指令集,由它的 Agent 讀取。",
|
||||
"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 會自己尋找工具,仍會拿到全部工具。",
|
||||
"An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.": "給一個 Agent 的工具超過 {n} 個時,改為給它兩個工具:一個尋找工具,一個執行工具,這樣工具定義不會出現在每次請求裡。",
|
||||
"{list} and {last} find tools themselves and are given every one.": "{list} 和 {last} 會自己尋找工具,仍會拿到全部工具。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "Agent 現在按需取得路由的工具 — 重新啟動它們後生效",
|
||||
"Agents are given every tool of the router — restart them to use it": "Agent 現在取得路由的全部工具 — 重新啟動它們後生效",
|
||||
"Show more ({n} left)": "顯示更多(還有 {n} 個)",
|
||||
@@ -2331,7 +2333,8 @@ magpie.strings({
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these skills and gives them to its agents.": "別のコンピューターの magpie がこの magpie をプロバイダとして追加し「そのスキルとプロンプトを使う」をオンにすると、これらのスキルを受け取り、そのエージェントに渡します。",
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these sets, and its agents read them.": "別のコンピューターの magpie がこの magpie をプロバイダとして追加し「そのスキルとプロンプトを使う」をオンにすると、これらのセットを受け取り、そのエージェントが読み込みます。",
|
||||
"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 は自分でツールを探すので、すべてのツールが渡されます。",
|
||||
"An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.": "エージェントに渡すツールが {n} 個を超えると、代わりにツールを探すものと実行するものの 2 つを渡し、ツールの定義が毎回のリクエストに入らないようにします。",
|
||||
"{list} and {last} find tools themselves and are given every one.": "{list}、{last} は自分でツールを探すので、すべてのツールが渡されます。",
|
||||
"Agents are given the router's tools on demand — restart them to use it": "エージェントにルーターのツールをオンデマンドで渡します — 反映するにはエージェントを再起動してください",
|
||||
"Agents are given every tool of the router — restart them to use it": "エージェントにルーターのすべてのツールを渡します — 反映するにはエージェントを再起動してください",
|
||||
"Show more ({n} left)": "さらに表示(残り {n} 件)",
|
||||
@@ -3438,7 +3441,8 @@ magpie.strings({
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these skills and gives them to its agents.": "Ein magpie auf einem anderen Computer, der diesen als Anbieter hinzufügt und „Seine Skills und Prompts verwenden“ einschaltet, übernimmt diese Skills und gibt sie seinen Agenten.",
|
||||
"A magpie on another computer that adds this one as a provider, with Use its skills and prompts on, takes these sets, and its agents read them.": "Ein magpie auf einem anderen Computer, der diesen als Anbieter hinzufügt und „Seine Skills und Prompts verwenden“ einschaltet, übernimmt diese Sets, und seine Agenten lesen sie.",
|
||||
"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.",
|
||||
"An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.": "Ein Agent, der mehr als {n} Tools bekäme, bekommt stattdessen zwei: eines findet ein Tool, das andere führt es aus, damit ihre Definitionen nicht in jeder Anfrage stehen.",
|
||||
"{list} and {last} find tools themselves and are given every one.": "{list} und {last} 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",
|
||||
"Agents are given every tool of the router — restart them to use it": "Agents bekommen alle Tools des Routers — starte sie neu, damit sie es nutzen",
|
||||
"Show more ({n} left)": "Mehr zeigen (noch {n})",
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -76,3 +78,36 @@ func TestHubAllToolsSaved(t *testing.T) {
|
||||
t.Fatalf("off: %d %v", rec.Code, settings.Load().RouterAllTools)
|
||||
}
|
||||
}
|
||||
|
||||
// The Tools on demand row says how many tools an agent is given whole and
|
||||
// which agents search their tools themselves from the page's view, which
|
||||
// carries the gateway's own (gateway.HubOnDemandOver,
|
||||
// gateway.HubFindsItself), each agent by its name: its words named four of
|
||||
// the six (11-18).
|
||||
func TestHubFindsItselfInTheView(t *testing.T) {
|
||||
sandboxHome(t)
|
||||
rec := httptest.NewRecorder()
|
||||
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/api/library", nil))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body)
|
||||
}
|
||||
var v struct {
|
||||
HubFindsItself []string
|
||||
HubOnDemandOver int
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ids := gateway.HubFindsItself()
|
||||
if v.HubOnDemandOver != gateway.HubOnDemandOver || len(v.HubFindsItself) != len(ids) {
|
||||
t.Fatalf("view says %d, %q; the gateway %d, %q", v.HubOnDemandOver, v.HubFindsItself, gateway.HubOnDemandOver, ids)
|
||||
}
|
||||
for i, id := range ids {
|
||||
if a, err := agent.Find(id); err == nil && a.ID == id && v.HubFindsItself[i] != a.Name {
|
||||
t.Fatalf("%s is said as %q, not %q", id, v.HubFindsItself[i], a.Name)
|
||||
}
|
||||
if v.HubFindsItself[i] == id && id != "omp" {
|
||||
t.Fatalf("%s is said by its id", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
// ArvinCharl on X: the MCP router's tools fill an agent's context. With
|
||||
// the router on, the Library's MCP tab has a Tools on demand row under the
|
||||
// router's name: a switch, on by default (settings' routerAllTools off),
|
||||
// saying that an agent given more than 10 tools gets two in their place,
|
||||
// and which agents find tools themselves. A click posts servers/hub-tools
|
||||
// saying that an agent given more than the gateway's count of tools gets
|
||||
// two in their place, and which agents find tools themselves, both from the
|
||||
// library's view. A click posts servers/hub-tools
|
||||
// {on: true} (every tool whole), says so, and the switch reads off; a click
|
||||
// again posts {on: false}. Off, there is no row. In every language, both
|
||||
// engines, wide and narrow: no sideways scroll, the switch inside its row.
|
||||
@@ -20,11 +21,18 @@ const HOME = "/Users/mg";
|
||||
const fixture = (st) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
mcpHub: st.on, hubPath: "/mcp/magpie/hub/", hubNote: "", hubName: "la-box", hubAllTools: st.all,
|
||||
hubOnDemandOver: OVER, hubFindsItself: FINDS,
|
||||
agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", skills: `${HOME}/.claude/skills`, mcp: `${HOME}/.claude.json`, ...(st.on ? { hub: "on" } : {}) }],
|
||||
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], problems: [],
|
||||
servers: [{ name: "fetch", transport: "stdio", command: "uvx", args: ["mcp-server-fetch"], agents: ["claude"] }],
|
||||
});
|
||||
|
||||
// the gateway's own threshold and agents (hubOnDemandOver, hubFindsItself
|
||||
// in the library's view), not 10 and the four the row's words once named:
|
||||
// the row says what it is given (11-18)
|
||||
const OVER = 12;
|
||||
const FINDS = ["Claude Code", "Claude Desktop", "Codex", "Pi", "Droid", "omp"];
|
||||
|
||||
let I18N;
|
||||
function tr(lang, key, vars = {}) {
|
||||
let s = key;
|
||||
@@ -128,7 +136,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
});
|
||||
assert.ok(after, "the row isn't under the router's name");
|
||||
assert.equal((await row.locator(".name").textContent()).trim(), w("Tools on demand"));
|
||||
assert.equal((await row.locator(".sub").textContent()).trim(), w("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."));
|
||||
const says = (await row.locator(".sub").textContent()).trim();
|
||||
assert.equal(says, w("An agent given more than {n} tools gets two in their place, one that finds a tool and one that runs it, so their definitions stay out of every request.", { n: OVER }) + (lang.startsWith("zh") || lang === "ja" ? "" : " ") +
|
||||
w("{list} and {last} find tools themselves and are given every one.", { list: FINDS.slice(0, -1).join(w(", ")), last: FINDS.at(-1) }));
|
||||
for (const name of FINDS) assert.ok(says.includes(name), `${name} isn't named: ${says}`);
|
||||
assert.ok(says.includes(String(OVER)) && !says.includes("10"), says);
|
||||
assert.ok(!says.includes("。 "), says);
|
||||
const sw = () => p.locator("#view-library .lib-hubtoolsrow .lib-switch");
|
||||
assert.equal(await sw().getAttribute("aria-label"), w("Tools on demand"));
|
||||
assert.equal(await sw().getAttribute("aria-checked"), "true");
|
||||
|
||||
@@ -32,6 +32,7 @@ package library
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"cmp"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
@@ -1123,3 +1124,22 @@ var (
|
||||
_ hubConn = (*streamConn)(nil)
|
||||
_ hubConn = (*httpConn)(nil)
|
||||
)
|
||||
|
||||
// hubFindsItself is the names of the agents the router gives every tool
|
||||
// whole, as they search their MCP tools themselves (gateway.HubFindsItself),
|
||||
// for the Tools on demand row to say: its words named four of the six
|
||||
// (11-18). An agent's name doesn't change while magpie runs, so they are
|
||||
// looked up once; one not found is said by its id.
|
||||
var hubFindsItself = sync.OnceValue(func() []string {
|
||||
names := map[string]string{}
|
||||
for _, a := range append(apps(), agent.All()...) {
|
||||
if _, ok := names[a.ID]; !ok && a.WSL == "" {
|
||||
names[a.ID] = a.Name
|
||||
}
|
||||
}
|
||||
var out []string
|
||||
for _, id := range gateway.HubFindsItself() {
|
||||
out = append(out, cmp.Or(names[id], id))
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
@@ -583,6 +583,12 @@ type View struct {
|
||||
// HubAllTools: every agent is given the router's tools whole, none on
|
||||
// demand (settings' RouterAllTools, gateway.hubOnDemand)
|
||||
HubAllTools bool `json:"hubAllTools"`
|
||||
// HubFindsItself names the agents given every tool whole, as they
|
||||
// search their tools themselves, and HubOnDemandOver how many tools an
|
||||
// agent is given whole at most (gateway.HubFindsItself,
|
||||
// gateway.HubOnDemandOver): the Tools on demand row says them
|
||||
HubFindsItself []string `json:"hubFindsItself"`
|
||||
HubOnDemandOver int `json:"hubOnDemandOver"`
|
||||
// CheckDue is set when the skills from GitHub weren't checked for
|
||||
// updates since magpie started, or not for a while: the page checks
|
||||
// them as it shows them (#1449)
|
||||
@@ -666,7 +672,7 @@ func readView(problems []Problem, glance bool) (*View, error) {
|
||||
// the agents are found once for the whole read: finding them looks
|
||||
// through every agent's folders, in WSL too (#1624)
|
||||
targets, asleep := targetsAsleep(false)
|
||||
v := &View{Agents: []AgentView{}, Servers: []ServerView{}, Skills: []SkillView{}, FoundSkills: []FoundSkill{}, Instructions: l.instructionsView(targets, asleep), Dir: Dir(), Backups: BackupDir(), CopySkills: l.CopySkills, SharedSkills: l.SharedSkills, SharedDir: sharedSkillsDir(), AutoUpdateSkills: l.AutoUpdateSkills, MCPHub: l.MCPHub, SkillRouter: l.SkillRouter, HubPath: gateway.HubMCPPath, HubNote: settings.Shared().RouterNote, HubName: gateway.HostName(), HubAllTools: settings.Shared().RouterAllTools, Partial: glance}
|
||||
v := &View{Agents: []AgentView{}, Servers: []ServerView{}, Skills: []SkillView{}, FoundSkills: []FoundSkill{}, Instructions: l.instructionsView(targets, asleep), Dir: Dir(), Backups: BackupDir(), CopySkills: l.CopySkills, SharedSkills: l.SharedSkills, SharedDir: sharedSkillsDir(), AutoUpdateSkills: l.AutoUpdateSkills, MCPHub: l.MCPHub, SkillRouter: l.SkillRouter, HubPath: gateway.HubMCPPath, HubNote: settings.Shared().RouterNote, HubName: gateway.HostName(), HubAllTools: settings.Shared().RouterAllTools, HubFindsItself: hubFindsItself(), HubOnDemandOver: gateway.HubOnDemandOver, Partial: glance}
|
||||
for _, t := range targets {
|
||||
av := AgentView{ID: t.Agent.ID, Name: t.Agent.Name, Icon: t.Agent.Icon, Instructions: t.Instructions, Skills: t.Skills,
|
||||
SkillsAlso: t.SkillsAlso, Note: t.Note, MCPVia: t.MCPVia, ProjectSkills: ProjectSkillsDir(t.Agent.ID), ProjectMCP: ProjectMCPFile(t.Agent.ID), ProjectSubagents: ProjectSubagentsDir(t.Agent.ID),
|
||||
|
||||
Reference in New Issue
Block a user