library: a plugin's tools hidden from every agent from its Plugins row
chengming0v0 (Discord) keeps a plugin for its providers but doesn't want
the MCP server it brings (minimax_query_video_generation and the rest)
shown to agents, and doesn't want to remove the plugin.
Before: a plugin that gives tools is a Library server of its own
(plugin_tools.go), switched per agent with the row's chips in Library ›
MCP, which held through updates and off/on. Nothing on the Plugins page
said so: its line read "Tools for every agent" whatever the Library had,
and an app at the router's address (/mcp/magpie/hub, agent "") was given
every server, ticked for any agent or none, so taking every chip off
still left the tools there.
Now:
- The plugin's tools line says "Tools for agents" or "Tools, hidden from
agents", with Hide from agents / Give to agents beside the copy button
(plugins.js, toolsServer in /api/plugins from library.PluginServers).
- PluginServerOn (servers/plugin-on {name, on}) sets Server.Hidden and
keeps the agents it had in Paused. Hidden, no agent is given it and
hubServers leaves it out for the router's address too. Give to agents
gives the kept agents back; with none kept, the router's agents
(hubAgents), or else every shown agent that can take it.
- It holds through a plugin update, the plugin off and on, an edit in the
Library editor (SaveServer keeps it) and an agent's "every server"
(serversAgents with no names skips a hidden one). Ticking an agent for
it in Library › MCP shows it again (save clears Hidden).
- Library › MCP tags the server "Plugin", its tooltip pointing at Plugins.
- /mcp/magpie/tools (every plugin's tools, wired by hand) is unchanged.
- Docs: plugin-tools.md, mcp-router.md, site docs plugins (en, zh, ja).
- The core script budget is not raised: two plugins.js comments cut, the
button's tooltips and status lines left out.
Run on mote at this tree (before the site docs, html only):
- go build ./..., go vet ./internal/library ./internal/gui, GOOS=windows
go vet of both, GOOS=linux go vet ./internal/library: ok.
- go test -count=1 ./internal/library/: ok (187s).
- go test -count=1 ./internal/gui/ -run 'Plugin|Library|Budget|Script':
ok (TestCoreScriptBudget 1,533,514 of 1,533,802).
- node --test plugin-tools.test.cjs (new: the line's words, Hide and Give
posting {name, on}, the button inside its row at 980 and 420, all five
languages, Chromium and WebKit): ok; builtins, every library-mcp-* and
mcp-* file: ok.
- i18n-keys "a plugin's words are its own": red, the same three words on
origin/main 61394481c (#5327/#5332, #5426, #5482); nothing of mine.
- library-mcp-first-click: one 1500ms wait red per run (chromium en 1100
once, webkit zh-TW 1100 once) with several files at once; green alone on
origin/main 61394481c. Not filed yet; the whole GUI suite comes next.
- site/worker.test.mjs: ok.
Broken by hand: without `!s.Hidden` in hubServers, TestPluginToolsHidden
is red ("hidden: still listed"); without the every-server skip, red at
"every server given to claude".
Not tried: a real MiniMax plugin or the real app; the whole GUI suite and
go test ./... (queued under the suite lock on mote after the push); a Go
test of toolsServer in pluginsState (the GUI test fakes /api/plugins);
Windows and Linux runs.
Reported-by: chengming0v0 (Discord)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# MCP router
|
||||
|
||||
With the Library's switch "MCP router" on (#2679, @minggang123 on X), each agent is given one MCP server, `magpie`, in place of the Library's MCP servers ticked for it. magpie serves it at `/mcp/magpie/hub/<agent>` (Streamable HTTP) and hands each call on to the Library server behind it. Any other app (Cursor, VS Code, Windsurf, an app on another computer) connects at `/mcp/magpie/hub`, which serves every server in the Library. A server written once is then set up once, for every agent and app, and a command server runs once, not once in each. The servers themselves are the [Library](library.md)'s; the endpoint is the gateway's, guarded as [Plugin tools](plugin-tools.md)' `/mcp/magpie/tools` is. The switch is off by default.
|
||||
With the Library's switch "MCP router" on (#2679, @minggang123 on X), each agent is given one MCP server, `magpie`, in place of the Library's MCP servers ticked for it. magpie serves it at `/mcp/magpie/hub/<agent>` (Streamable HTTP) and hands each call on to the Library server behind it. Any other app (Cursor, VS Code, Windsurf, an app on another computer) connects at `/mcp/magpie/hub`, which serves every server in the Library (but a plugin's server hidden from agents). A server written once is then set up once, for every agent and app, and a command server runs once, not once in each. The servers themselves are the [Library](library.md)'s; the endpoint is the gateway's, guarded as [Plugin tools](plugin-tools.md)' `/mcp/magpie/tools` is. The switch is off by default.
|
||||
|
||||
## Responsibilities and sources of truth
|
||||
|
||||
@@ -9,7 +9,7 @@ With the Library's switch "MCP router" on (#2679, @minggang123 on X), each agent
|
||||
| Switch | `Library.MCPHub` (`mcpHub` in library.json) is the source of truth. `SetMCPHub` sets it through `change`, so every agent is synced at once; turning it off also ends every server the router started (`hubStopAll`). The page posts `servers/hub` `{on}`. | `SetMCPHub` in [`mcp_hub.go`](../../internal/library/mcp_hub.go); `servers/hub` in [`gui/library.go`](../../internal/gui/library.go) |
|
||||
| Entry | `syncMCP` gives an agent `hubServerFor(t)`, named `magpie` (`HubEntry`), in place of each server it would have written, and records it in `Applied.MCP` like any server, so turning the switch off takes out only that entry and writes each server's own again. The URL is the gateway as that agent reaches it (`gatewayOf`), so a WSL distro or a LAN computer gets its address, with `Authorization: Bearer <key>` when that address needs a key (`agent.KeyAt`). A LAN key or relay change re-syncs (`LANChanged`). magpie's own image server (`isSelf`) is behind the router too, except for an agent in a WSL distro (its id has `@wsl:`), which keeps its own entry to the magpie in that distro. A server the user keeps direct is not (`Server.Hub` = `direct`, `hub` in library.json; #4382, cuipengcx90): each agent given it keeps its own entry, written as with the router off, beside the router's entry for the rest, and started by that agent: Codex on magpie, which is otherwise given a command server as the gateway's `/mcp/run/<name>` that magpie starts from home ([`mcp_run.go`](../../internal/library/mcp_run.go), #3885), is given a direct one's `command`, `args` and `env` with no `cwd`, so Codex starts it in the thread's folder (codex-mcp's `LocalStdioServerLauncher` falls back to the session's `cwd`; `TestRunDirectServerIsCodexsCommand`); an agent whose every server is direct is given no hub entry. `inHub` is the one test, so the router neither lists nor runs a direct server, at `/mcp/magpie/hub` either, and `hubPrune` ends one it held. The default (`""`; `shared` is saved as `""`) is the router's as before. Switching it (`ServerHub`, or a save) goes through `change`, so each agent is written again at once and the entry it had the other way is taken out (`TestHubDirectServer`). The policy is the server's, so a sync carries it. A per-project or per-session backend behind the router (Option B in #4382, keying `hubPool` by roots) is not built. | `hubFor`, `hubServerFor`, `inHub` in `mcp_hub.go`; `syncMCP` in [`sync.go`](../../internal/library/sync.go); [`mcp_signin.go`](../../internal/library/mcp_signin.go) |
|
||||
| Who keeps their entries | An agent keeps each server's own entry, and `AgentView.Hub` says why: `no-remote` (it reaches no server over HTTP: `mcpFile.supports` refuses the entry, as for Claude Desktop), `taken` (a Library server is itself called magpie), `own` (the agent has an entry called magpie that magpie didn't write; it is left as it is). `on` is an agent given the router's entry. An agent given none of the router's servers has no value. | `hubFor` in `mcp_hub.go`; `AgentView.Hub`, `View.MCPHub`, `View.HubPath` in `sync.go` |
|
||||
| Serve | `tools/list` lists the tools of the servers ticked for that agent (at `/mcp/magpie/hub`, agent `""`: every server in the Library, ticked for any agent or none), but those in `DisabledTools`, as `<server>__<tool>`: each part in `[A-Za-z0-9_-]` (other characters `_`), at most 64 characters (`cutName`), `_2`, `_3` on a name two would share. Each tool's description and `inputSchema` go on as the server listed them (an object schema with no properties when it has none). An agent that searches its MCP tools itself is given every tool in full, and its tool search keeps them out of each request: Claude Code (`ENABLE_TOOL_SEARCH`, which magpie turns on, see [agent wiring](agent-wiring.md)), Claude Desktop, Codex (`tool_search` on magpie's catalog), Pi, Droid (which defers every MCP tool to its ToolSearch) and omp (which names each in its catalog by its description's first line) (`hubSearchesItself`, by the agent's id without its `@wsl:<distro>`). So is the address for any other app (agent `""`) and an agent given 10 tools or fewer. Any other agent is given its tools on demand (below). `tools/call` runs one; an unknown name, or another agent's, is error -32602. `initialize` and `ping` are answered; other methods are -32601. Tools only: no resources or prompts. | `hubMCPCall`, `hubNamed` in [`hub_mcp.go`](../../internal/gateway/hub_mcp.go) |
|
||||
| Serve | `tools/list` lists the tools of the servers ticked for that agent (at `/mcp/magpie/hub`, agent `""`: every server in the Library, ticked for any agent or none, but a plugin's server hidden from agents, `Server.Hidden`, [Plugin tools](plugin-tools.md)), but those in `DisabledTools`, as `<server>__<tool>`: each part in `[A-Za-z0-9_-]` (other characters `_`), at most 64 characters (`cutName`), `_2`, `_3` on a name two would share. Each tool's description and `inputSchema` go on as the server listed them (an object schema with no properties when it has none). An agent that searches its MCP tools itself is given every tool in full, and its tool search keeps them out of each request: Claude Code (`ENABLE_TOOL_SEARCH`, which magpie turns on, see [agent wiring](agent-wiring.md)), Claude Desktop, Codex (`tool_search` on magpie's catalog), Pi, Droid (which defers every MCP tool to its ToolSearch) and omp (which names each in its catalog by its description's first line) (`hubSearchesItself`, by the agent's id without its `@wsl:<distro>`). So is the address for any other app (agent `""`) and an agent given 10 tools or fewer. Any other agent is given its tools on demand (below). `tools/call` runs one; an unknown name, or another agent's, is error -32602. `initialize` and `ping` are answered; other methods are -32601. Tools only: no resources or prompts. | `hubMCPCall`, `hubNamed` in [`hub_mcp.go`](../../internal/gateway/hub_mcp.go) |
|
||||
| What it serves | An agent that shows the router as one line, and its tools only once they are searched for, learns from that line alone which servers are behind it (a Pi asked about a GitHub repository cloned it rather than ask the DeepWiki behind the router, told only "The tools of the MCP servers in magpie's Library", 11-01). `initialize`'s `instructions` start with `HubLine`: `Tools of <name> (<what it is for>), …`, every server by name, each one's first clause (`hubClause`) cut at a word to an equal share of 250 characters (`hubLineMax`, Pi's `MAX_SERVER_DESCRIPTION_CHARS`), the short ones whole; names that don't fit are counted (`and N more`). Then, for an agent given several routers to tell them apart (packinggoodsllc_07668: magpies that only share MCP servers), the router's name sentence when it has one (Router name, below), then a line for each server (`hubDetails`): `- <name> (<its title>): <what it is for>. Tools: <tool> (<first clause of its description>), …`, the tools the Library turned off left out and a router's `[<name>] ` dropped; a line too long for its share of the room says its tools by name only, then as many names as fit and `and N more`. The whole is at most 2000 characters (`hubSayMax`, half the 4096 Claude Code keeps), the closing text kept whole. What a server is for is the market's (`serverAbout`): the featured or registry server it is by `serverKey`, whatever it is named, or the featured one it is named after; otherwise the server's own words, its `serverInfo.description` or else its `instructions`' first line (`saysOf`); another magpie's `Tools of a (…), b.` is said with `Tools of` once. Its title is its `serverInfo.title`. These and its tools are what the server last answered to `initialize` and `tools/list` (`noteCard`), kept in `mcp-hub-servers.json` beside settings.json (not in the synced library folder) by server name and `cardKey` (a hash of `hubKey`: an edit or a sign-in since is another server), written through a temporary file only when they change; a router started again describes its servers before running any. A server with no card for it as it is now (`Known` false) is listed by `initialize`, which waits up to 5 s (`hubDescribeWait`) for it. No model writes any of it. Which agents show the instructions, from their installed source (11-02): Claude Code (a `# MCP Server Instructions` message, 4096 characters), Codex (the namespace's description), OpenCode (`<mcp_instructions>`), Gemini CLI (in a trusted folder only), Qwen Code (the opening history), Pi (the first line in its prompt, the whole through codemode); Kimi CLI reads none, and none of them shows `serverInfo.title` to the model. Pi doesn't wait for a codemode server before writing the first prompt (`waitForDirectServers` waits for direct ones), so its instructions miss that prompt; Pi's own mcp.json (`fmtPiNative`) gets the same line as the hub entry's `description`, which Pi shows before connecting (`serverSummary`). It is magpie's on the hub entry only (`mine`), read back to tell a changed list of servers (`Server.about`, `same`), and any other entry's description is the user's. | `HubLine`, `hubAbout`, `hubDetails`, `hubServerLine`, `hubServersFor` in `hub_mcp.go`; `theHub.Servers`, `hubAbouts`, `hubServerFor` in `mcp_hub.go`; `hubServerOf`, `noteCard`, `saysOf` in [`mcp_hub_cards.go`](../../internal/library/mcp_hub_cards.go); `serverAbout` in [`market.go`](../../internal/library/market.go) |
|
||||
| Tools on demand | An agent with no tool search of its own sends every tool, with its `inputSchema`, on every request (ArvinCharl on X, 11-04: the tools filled the context). Past `hubOnDemandOver` (10) tools, `hubOnDemand` gives it two in their place: `find_tools {query, server?}` scores each tool on the query's words (a word in its router name 3, in its description 1, the whole query in its name 5 more; `hubMatches`) and answers the best 5 with their name, description and `inputSchema`, then up to 15 more by name with their first clause; an empty query, or one nothing matches, names every tool. `find_tools`' description starts with `HubLine` (each server and what it is for: an agent such as omp shows a tool by its description's first line, and some, such as Droid, show no instructions), then how to search, then each server's tools (`hubDetails` within `hubFindSayMax`, 1200 characters; `hubFindSay`): told only how to search, a model asked for a picture searched and stopped (tao5010 on Discord, 11-04). `call_tool {name, arguments}` runs the tool by its router name as `tools/call` finds it (`hubToolNamed`), else the one tool with that name on its server in any case (`hubCallNamed`); `arguments` given as a string holding an object is that object. It runs through the same caller, roots and key limit as `tools/call` (`hubCall`), and its request-log row names the tool that ran (`mcpUse.named`). A name nothing gives is an error naming the close ones. `tools/call` takes both names whatever was listed, and still runs a tool by its own name. `initialize`'s instructions add `Its tools are given on demand: …` (counted from `HubServer.Tools`), and still name each server's tools (`hubDetails`), so the model knows what there is to find. The Library's switch Tools on demand (on by default) turns it off for every agent: `settings.RouterAllTools`, this computer's own (`KeepOwn`), set alone (`SetRouterAllTools`) and kept by the Settings page's save. | `hubOnDemand`, `hubFind`, `hubCallByName` in [`hub_ondemand.go`](../../internal/gateway/hub_ondemand.go); `hubCall` in `hub_mcp.go`; `RouterAllTools`, `SetRouterAllTools` in `settings.go`; `servers/hub-tools` in `gui/library.go`; `View.HubAllTools` in `sync.go` |
|
||||
| Router name | What a router says of itself, for an agent given the same tools by two routers (packinggoodsllc_07668 on Discord: one magpie in China, one in Los Angeles) to pick one. `hubWhere`: the user's words (`settings.RouterNote`, one line, 80 characters at most, `CleanRouterNote`), to every caller; with none, this computer's name (`hostName`) to a caller that isn't `local`, and nothing to one that is (one router at hand; the computer's name stays off its prompts). With a value, `initialize`'s `instructions` say `This router: <name>. …` on their second line (at the end when no server is behind it), `serverInfo.title` is `Magpie MCP hub · <name>`, and each tool's description starts `[<name>] ` (once: a description that starts so already, another magpie's router behind this one, isn't given it again). It is this computer's own (`KeepOwn`): a sync never brings another's. Set in the Library's MCP tab (below) or settings.json; the Settings page's save keeps it (`POST /api/settings`). | `hubWhere` in `hub_mcp.go`; `RouterNote`, `SetRouterNote` in [`settings.go`](../../internal/settings/settings.go); `servers/hub-note` in `gui/library.go`; `View.HubNote`, `View.HubName` in `sync.go` |
|
||||
|
||||
@@ -38,13 +38,14 @@ A tool's answer goes back to the agent that called it, on this computer or on a
|
||||
- The router runs its tools in this process (`gateway.PluginToolsOf`, `RunPluginToolOf`), under the same Plugin tools gate. With the router off an agent is given the gateway's address of the plugin's tools as it reaches the gateway (`through`), with a key from another machine.
|
||||
- It is `local`: a carry or backup never takes it to a computer that may lack the plugin. It is offered once (`pluginsOffered`): a server the user removed comes back only when the plugin is removed and added again. The plugin removed takes its server out; turned off, the server stays and lists nothing. A plugins.json that can't be read changes nothing.
|
||||
- `/mcp/magpie/tools`, every plugin's tools under one server, stays for agents wired to it by hand.
|
||||
- Its plugin's row on the Plugins page says which way it is ("Tools for agents" or "Tools, hidden from agents") and switches it: Hide from agents takes it from every agent, and from apps at the router's address, while the plugin and its providers keep working (chengming0v0 on Discord: a plugin's MCP tools unwanted, the plugin kept). `PluginServerOn` (`servers/plugin-on` `{name, on}`) sets `Hidden` and keeps the agents it had in `Paused`; Give to agents gives them back, or, with none kept, the router's agents (`hubAgents`) or else every agent shown that can take it. The switch is the server's own state, so it holds through a plugin update, the plugin off and on, a restart and an edit in the Library; ticking any agent for it in Library › MCP clears `Hidden` (`save`). `PluginServers` gives the row its state (`toolsServer` in `/api/plugins`); a plugin with no Library server (removed by the user) shows no switch. Library › MCP tags the server "Plugin". `/mcp/magpie/tools` is not affected: it serves only an agent wired to it by hand. (`TestPluginToolsHidden`, `plugin-tools.test.cjs`)
|
||||
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
go test ./internal/plugin/ -run Tool
|
||||
go test ./internal/gateway/ -run 'ToolsMCP|ServingGates|OwnMCPRejects' -timeout 45m
|
||||
go test ./internal/library/ -run PluginTools
|
||||
go test ./internal/library/ -run 'PluginTools|Hub'
|
||||
go test ./plugins/tools/ ./internal/pluginrt/
|
||||
go test ./internal/gui/ -run 'Builtin|Plugins'
|
||||
node --test internal/gui/tests/plugin-tools.test.cjs internal/gui/tests/builtins.test.cjs
|
||||
|
||||
@@ -985,6 +985,10 @@ const I18N = {
|
||||
"1 plugin gives tools": "1 个插件提供工具",
|
||||
"{n} plugins give tools": "{n} 个插件提供工具",
|
||||
"Tools for every agent: {names}": "给每个智能体的工具:{names}",
|
||||
"Tools for agents: {names}": "给智能体的工具:{names}",
|
||||
"Tools, hidden from agents: {names}": "工具,已对智能体隐藏:{names}",
|
||||
"Hide from agents": "对智能体隐藏",
|
||||
"Give to agents": "交给智能体",
|
||||
"MCP server address": "MCP 服务器地址",
|
||||
"Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)": "复制 MCP 服务器地址({url}):在智能体里把它添加为 MCP 服务器(Streamable HTTP)",
|
||||
"Key limits": "密钥限额",
|
||||
@@ -5659,6 +5663,10 @@ const I18N = {
|
||||
"1 plugin gives tools": "1 個外掛提供工具",
|
||||
"{n} plugins give tools": "{n} 個外掛提供工具",
|
||||
"Tools for every agent: {names}": "給每個代理的工具:{names}",
|
||||
"Tools for agents: {names}": "給代理的工具:{names}",
|
||||
"Tools, hidden from agents: {names}": "工具,已對代理隱藏:{names}",
|
||||
"Hide from agents": "對代理隱藏",
|
||||
"Give to agents": "交給代理",
|
||||
"MCP server address": "MCP 伺服器位址",
|
||||
"Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)": "複製 MCP 伺服器位址({url}):在代理中把它新增為 MCP 伺服器(Streamable HTTP)",
|
||||
"Key limits": "密鑰限額",
|
||||
@@ -10304,6 +10312,10 @@ const I18N = {
|
||||
"1 plugin gives tools": "1 個のプラグインがツールを提供",
|
||||
"{n} plugins give tools": "{n} 個のプラグインがツールを提供",
|
||||
"Tools for every agent: {names}": "すべてのエージェントのツール:{names}",
|
||||
"Tools for agents: {names}": "エージェントのツール:{names}",
|
||||
"Tools, hidden from agents: {names}": "ツール(エージェントには非表示):{names}",
|
||||
"Hide from agents": "エージェントに隠す",
|
||||
"Give to agents": "エージェントに渡す",
|
||||
"MCP server address": "MCP サーバーのアドレス",
|
||||
"Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)": "MCP サーバーのアドレス({url})をコピー:エージェントに MCP サーバー(Streamable HTTP)として追加します",
|
||||
"Key limits": "キーの上限",
|
||||
@@ -14964,6 +14976,10 @@ const I18N = {
|
||||
"1 plugin gives tools": "1 Plugin bietet Werkzeuge",
|
||||
"{n} plugins give tools": "{n} Plugins bieten Werkzeuge",
|
||||
"Tools for every agent: {names}": "Werkzeuge für jeden Agenten: {names}",
|
||||
"Tools for agents: {names}": "Werkzeuge für Agenten: {names}",
|
||||
"Tools, hidden from agents: {names}": "Werkzeuge, vor Agenten verborgen: {names}",
|
||||
"Hide from agents": "Vor Agenten verbergen",
|
||||
"Give to agents": "Agenten geben",
|
||||
"MCP server address": "Adresse des MCP-Servers",
|
||||
"Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)": "Adresse des MCP-Servers kopieren ({url}): in einem Agenten als MCP-Server (Streamable HTTP) hinzufügen",
|
||||
"Key limits": "Schlüssel-Limits",
|
||||
|
||||
@@ -316,3 +316,4 @@ body.window .pm-manual { --bleed-l: 16px; }
|
||||
.pm-card.ghost .sk, .pm-ghlook, .pm-ghlook .dots i, .pm-arrive .pm-card { animation: none; }
|
||||
.pm-ghlook .dots i { opacity: .5; }
|
||||
}
|
||||
.pm-tools > .pm-tools-flip { flex: none; margin-left: auto; padding: 0 2px; }
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
// Plugins: the market of OpenCode provider plugins — subscriptions magpie
|
||||
// signs in to through someone else's code. Discover lists the plugins
|
||||
// magpie suggests (the community repo's list, with what npm says of each
|
||||
// now) and finds the rest on npm; Installed is what was added, to sign in
|
||||
// with, update, switch off or remove. Each part is drawn as it comes
|
||||
// (#488): what's installed from /api/plugins, the plugins suggested from
|
||||
// /api/plugins/listings, and what npm says of them (versions, downloads)
|
||||
// from /api/plugins/npm after; a sign-in happens in the Providers add
|
||||
// sheet, as every other subscription's does.
|
||||
// Plugins: the market of OpenCode plugins. Discover lists the suggested
|
||||
// ones and finds the rest on npm; Installed is what was added. Each part is
|
||||
// drawn as it comes (#488): /api/plugins, /api/plugins/listings, then
|
||||
// /api/plugins/npm; a sign-in happens in the Providers add sheet.
|
||||
(() => {
|
||||
const page = $("#view-plugins");
|
||||
if (!page) return;
|
||||
@@ -169,11 +164,8 @@
|
||||
own: !!(r.name || r.summary),
|
||||
npm: { version: r.version || "", publisher: r.owner, repository: r.url, license: r.license, weekly: 0 },
|
||||
});
|
||||
// A failed ask is said, with why, whether or not a list was had before:
|
||||
// an empty list was read as there being no unofficial plugins (till on
|
||||
// Discord: GitHub unreachable from their desktop, the section gone).
|
||||
// A list had before stands through a failed ask that brings none.
|
||||
// again: Try again, which has magpie ask GitHub at once.
|
||||
// A failed ask is said, with why, list or not (till on Discord); a list
|
||||
// had before stands. again: Try again, which asks GitHub at once.
|
||||
async function loadTagged(again) {
|
||||
try {
|
||||
const r = await api("plugins/github" + (again ? "?again=1" : ""));
|
||||
@@ -1272,7 +1264,7 @@
|
||||
if (mw && !e.off && !ask) who.append(mwLine(mw));
|
||||
if (gw && !e.off && !ask) who.append(gatewayLine(gw));
|
||||
if (ag && !e.off && !ask) who.append(agentLine(ag));
|
||||
if (e.tools?.length && !e.off && !ask) who.append(toolsLine(e.tools));
|
||||
if (e.tools?.length && !e.off && !ask) who.append(toolsLine(e.tools, e));
|
||||
// off too: what its page may read is said before it is turned on
|
||||
if (e.page && !ask) who.append(pageLine(e.page));
|
||||
if (e.panels?.length && !ask) who.append(panelsLine(e.panels, e.panelReads));
|
||||
@@ -1477,14 +1469,25 @@
|
||||
// toolsLine is the tools a plugin gives, which magpie's plugin tools MCP
|
||||
// server offers every agent: each by the name an agent sees, its
|
||||
// description on hover, and the server's address to copy into an agent
|
||||
function toolsLine(tools) {
|
||||
const d = el("div", "sub pm-mw pm-tools");
|
||||
d.append(el("span", "", t("Tools for every agent: {names}", { names: tools.map((x) => x.mcp || x.name).join(t(", ")) })));
|
||||
// and, with its Library server (toolsServer), a switch for every agent
|
||||
function toolsLine(tools, e) {
|
||||
const d = el("div", "sub pm-mw pm-tools"), sv = e.toolsServer;
|
||||
const names = tools.map((x) => x.mcp || x.name).join(t(", "));
|
||||
d.append(el("span", "", t(!sv ? "Tools for every agent: {names}" : sv.on ? "Tools for agents: {names}" : "Tools, hidden from agents: {names}", { names })));
|
||||
d.title = tools.map((x) => (x.mcp || x.name) + (x.description ? " — " + x.description : "")).join("\n");
|
||||
const url = mcpAddress(state.settings || {}, "/mcp/magpie/tools");
|
||||
const b = copyBtn(url, t("MCP server address"));
|
||||
b.title = t("Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)", { url });
|
||||
d.append(b);
|
||||
if (sv && !gatewayMode && !featuresOff.has("library")) {
|
||||
const f = el("button", "link pm-tools-flip", t(sv.on ? "Hide from agents" : "Give to agents"));
|
||||
f.onclick = (ev) => {
|
||||
ev.stopPropagation();
|
||||
f.disabled = true;
|
||||
api("library/servers/plugin-on", { name: sv.plugin, on: !sv.on }).then(refresh, (err) => { f.disabled = false; statusErr(err); });
|
||||
};
|
||||
d.append(f);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
@@ -2138,7 +2138,9 @@ magpie.plugin("library", (ctx) => {
|
||||
if (s.signIn?.dead) nm.append(tag(t("Sign-in ran out"), "warn", t("Open it to sign in again")));
|
||||
else if (s.signIn?.signedIn) nm.append(tag(t("Signed in"), "lib-signed", t("The agents given it use magpie's sign-in")));
|
||||
// kept to this computer: sync carries it nowhere (huhuy72219405 on X)
|
||||
if (s.local) nm.append(tag(t("Not synced"), "lib-local", s.bridge ? bridgedWhy() : t("Sync never carries it to your other computers")));
|
||||
// a plugin's tools say whose they are, where they are turned off too
|
||||
if (s.plugin) nm.append(tag(t("Plugin"), "lib-local lib-plugin", t("{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers", { plugin: s.plugin })));
|
||||
else if (s.local) nm.append(tag(t("Not synced"), "lib-local", s.bridge ? bridgedWhy() : t("Sync never carries it to your other computers")));
|
||||
// out of the hub, each agent's own entry (#4382): said only while the hub is on
|
||||
if (lib.mcpHub && s.hub === "direct") nm.append(tag(t("Not through the router"), "lib-direct", t("Each agent is given its own entry for it, as with the MCP router off")));
|
||||
// its status beside the name, not in it: the name is still the name
|
||||
|
||||
@@ -17,6 +17,7 @@ magpie.strings({
|
||||
"Through the MCP router": "经过 MCP 路由",
|
||||
"Off gives each agent its own entry for it, as with the router off: for a server that reads its project from the folder it starts in, or keeps a session's state": "关掉后,每个 Agent 各自有它的条目,和关掉路由时一样:适合从启动目录读取项目、或保存会话状态的服务器",
|
||||
"Sync never carries it to your other computers": "同步不会把它带到你的其他电脑",
|
||||
"{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers": "{plugin} 的工具。可在「插件」里对所有智能体隐藏,插件保留;同步不会把它们带到你的其他电脑",
|
||||
"Added from a Remote magpie with this computer's key for it, so it stays on this computer": "它从 Remote magpie 添加,带着这台电脑给它的密钥,所以只留在这台电脑",
|
||||
"Sync to your other computers": "同步到其他电脑",
|
||||
"Off keeps it on this computer: sync never carries it to your other computers, and a sync from them neither removes it nor puts theirs in its place": "关闭后只留在这台电脑:同步不会把它带到你的其他电脑;其他电脑同步过来时,既不会删掉它,也不会用它们的同名服务器替换它",
|
||||
@@ -822,6 +823,7 @@ magpie.strings({
|
||||
"Through the MCP router": "經過 MCP 路由",
|
||||
"Off gives each agent its own entry for it, as with the router off: for a server that reads its project from the folder it starts in, or keeps a session's state": "關掉後,每個 Agent 各自有它的條目,和關掉路由時一樣:適合從啟動目錄讀取專案、或保存工作階段狀態的伺服器",
|
||||
"Sync never carries it to your other computers": "同步不會把它帶到你的其他電腦",
|
||||
"{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers": "{plugin} 的工具。可在「外掛」裡對所有代理隱藏,外掛保留;同步不會把它們帶到你的其他電腦",
|
||||
"Added from a Remote magpie with this computer's key for it, so it stays on this computer": "它從 Remote magpie 加入,帶著這台電腦給它的金鑰,所以只留在這台電腦",
|
||||
"Sync to your other computers": "同步到其他電腦",
|
||||
"Off keeps it on this computer: sync never carries it to your other computers, and a sync from them neither removes it nor puts theirs in its place": "關閉後只留在這台電腦:同步不會把它帶到你的其他電腦;其他電腦同步過來時,既不會刪掉它,也不會用它們的同名伺服器取代它",
|
||||
@@ -1627,6 +1629,7 @@ magpie.strings({
|
||||
"Through the MCP router": "MCP ルーターを通す",
|
||||
"Off gives each agent its own entry for it, as with the router off: for a server that reads its project from the folder it starts in, or keeps a session's state": "オフにすると、各エージェントに個別のエントリを渡します(ルーターがオフのときと同じ)。起動したフォルダからプロジェクトを読むサーバーや、セッションの状態を持つサーバー向けです",
|
||||
"Sync never carries it to your other computers": "同期でほかのコンピュータには送られません",
|
||||
"{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers": "{plugin} のツール。「プラグイン」で、プラグインを残したまますべてのエージェントから隠せます。同期で他のコンピュータには送られません",
|
||||
"Added from a Remote magpie with this computer's key for it, so it stays on this computer": "Remote magpie から、このコンピュータのキーで追加されたため、このコンピュータにだけ残ります",
|
||||
"Sync to your other computers": "ほかのコンピュータと同期",
|
||||
"Off keeps it on this computer: sync never carries it to your other computers, and a sync from them neither removes it nor puts theirs in its place": "オフにするとこのコンピュータだけに残ります。同期でほかのコンピュータには送られず、ほかのコンピュータからの同期で削除されたり、同じ名前のサーバーに置き換えられたりすることもありません",
|
||||
@@ -2432,6 +2435,7 @@ magpie.strings({
|
||||
"Through the MCP router": "Über den MCP-Router",
|
||||
"Off gives each agent its own entry for it, as with the router off: for a server that reads its project from the folder it starts in, or keeps a session's state": "Aus bekommt jeder Agent einen eigenen Eintrag dafür, wie bei ausgeschaltetem Router: für einen Server, der sein Projekt aus dem Ordner liest, in dem er startet, oder den Zustand einer Sitzung hält",
|
||||
"Sync never carries it to your other computers": "Die Synchronisierung bringt ihn nicht auf deine anderen Computer",
|
||||
"{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers": "Werkzeuge von {plugin}. Unter Erweiterungen vor allen Agenten verbergbar, die Erweiterung bleibt; die Synchronisierung bringt sie nie auf deine anderen Computer",
|
||||
"Added from a Remote magpie with this computer's key for it, so it stays on this computer": "Von einem Remote magpie mit dem Schlüssel dieses Computers hinzugefügt, darum bleibt er auf diesem Computer",
|
||||
"Sync to your other computers": "Mit deinen anderen Computern synchronisieren",
|
||||
"Off keeps it on this computer: sync never carries it to your other computers, and a sync from them neither removes it nor puts theirs in its place": "Aus bleibt er nur auf diesem Computer: Die Synchronisierung bringt ihn nicht auf deine anderen Computer, und eine Synchronisierung von dort entfernt ihn weder noch ersetzt sie ihn durch ihren gleichnamigen Server",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -543,6 +543,10 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
|
||||
case "servers/tools":
|
||||
// the tools its agents leave out (nf1qaz2w on Discord)
|
||||
res, err = library.ServerTools(in.Name, in.Names)
|
||||
case "servers/plugin-on":
|
||||
// a plugin's tools off for every agent, or on again, from its
|
||||
// row on the Plugins page (Name is the plugin's)
|
||||
res, err = library.PluginServerOn(in.Name, in.On)
|
||||
case "servers/agents-all":
|
||||
res, err = library.EveryServerAgents(in.Agents, in.On)
|
||||
case "servers/agents-some":
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
"github.com/yetone/magpie/internal/middleware"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -171,6 +172,9 @@ type pluginEntryJSON struct {
|
||||
// offers every agent under MCP's name: with their descriptions while
|
||||
// the host runs, by name alone from what it noted last when it doesn't
|
||||
Tools []pluginToolJSON `json:"tools,omitempty"`
|
||||
// ToolsServer is the Library's server of those tools, whose agents
|
||||
// the row turns them off and on for (chengming0v0 on Discord)
|
||||
ToolsServer *library.PluginServer `json:"toolsServer,omitempty"`
|
||||
}
|
||||
|
||||
// pluginToolJSON is one tool a plugin gives, as its row lists it.
|
||||
@@ -272,6 +276,10 @@ func pluginsState(ctx context.Context, w Windows) pluginsJSON {
|
||||
}
|
||||
}
|
||||
toolNames := gateway.ToolNames(tools)
|
||||
var servers map[string]library.PluginServer
|
||||
if len(tools) > 0 {
|
||||
servers = library.PluginServers()
|
||||
}
|
||||
// each plugin's subscriptions, by the names it gave last (plugin.Cached,
|
||||
// which holds them without starting the host or asking anyone, and asks
|
||||
// the plugins again in the background when a sign-in or the plugins
|
||||
@@ -377,6 +385,9 @@ func pluginsState(ctx context.Context, w Windows) pluginsJSON {
|
||||
for _, x := range pt.Tools {
|
||||
j.Tools = append(j.Tools, pluginToolJSON{Name: x.Name, Description: x.Description, MCP: toolNames[e.Spec][x.Name]})
|
||||
}
|
||||
if sv, ok := servers[plugin.Name(e.Spec)]; ok && len(j.Tools) > 0 {
|
||||
j.ToolsServer = &sv
|
||||
}
|
||||
}
|
||||
j.Moved = provider.MovedOnto(e.Spec)
|
||||
if j.Moved == nil {
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
// the name magpie's plugin tools MCP server gives it, its description on
|
||||
// hover, and a button that copies the server's address. A plugin of tools
|
||||
// alone wears no Provider chip and isn't said to sign in to nothing; one
|
||||
// that signs in too keeps its line; one switched off lists none. Every
|
||||
// language, both engines, at a narrow width too; the API is faked here.
|
||||
// that signs in too keeps its line; one switched off lists none. One with
|
||||
// a server in the Library hides its tools from every agent and gives them
|
||||
// back from its line (chengming0v0 on Discord). Every language, both
|
||||
// engines, at a narrow width too; the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -13,8 +15,10 @@ const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
const WEATHER = "/Users/x/pl/weather-tools", BOTH = "/Users/x/pl/both", OFF = "/Users/x/pl/off";
|
||||
const WEATHER = "/Users/x/pl/weather-tools", BOTH = "/Users/x/pl/both", OFF = "/Users/x/pl/off", VIDEO = "/Users/x/pl/video";
|
||||
const video = { spec: VIDEO, providers: ["Vid"], moved: [], named: true, tools: [{ name: "make", mcp: "video_make" }], toolsServer: { name: "video", plugin: VIDEO, on: true } };
|
||||
const state = { bun: true, bunVersion: "1.3.0", named: true, plugins: [
|
||||
video,
|
||||
{ spec: WEATHER, providers: [], moved: [], named: true, tools: [
|
||||
{ name: "now", description: "The weather now in a city.", mcp: "weather-tools_now" },
|
||||
{ name: "week", description: "Seven days ahead.", mcp: "weather-tools_week" },
|
||||
@@ -23,6 +27,7 @@ const state = { bun: true, bunVersion: "1.3.0", named: true, plugins: [
|
||||
{ spec: OFF, off: true, providers: [], moved: [], tools: [{ name: "x", mcp: "off_x" }] },
|
||||
] };
|
||||
|
||||
const shown = []; // what each Hide or Give asked the Library
|
||||
function server(lang) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
@@ -34,6 +39,12 @@ function server(lang) {
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
||||
if (url.pathname === "/api/plugins") return json(state);
|
||||
if (url.pathname === "/api/library/servers/plugin-on") {
|
||||
const b = route.request().postDataJSON();
|
||||
shown.push(b);
|
||||
video.toolsServer = { ...video.toolsServer, on: b.on };
|
||||
return json({});
|
||||
}
|
||||
if (url.pathname === "/api/plugins/listings") return json({ listings: [] });
|
||||
if (url.pathname === "/api/plugins/market") return json({ listings: [], state });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
@@ -44,11 +55,11 @@ function server(lang) {
|
||||
}
|
||||
|
||||
const L = {
|
||||
en: { installed: "Installed", tools: "Tools for every agent: weather-tools_now, weather-tools_week", nothing: "Signs in to nothing", provider: "Provider" },
|
||||
zh: { installed: "已安装", tools: "给每个智能体的工具:weather-tools_now、weather-tools_week", nothing: "不能登录", provider: "供应商" },
|
||||
"zh-TW": { installed: "已安裝", tools: /^給每個代理的工具:weather-tools_now/ },
|
||||
ja: { installed: "インストール済み", tools: /^すべてのエージェントのツール:weather-tools_now/ },
|
||||
de: { installed: "Installiert", tools: /^Werkzeuge für jeden Agenten: weather-tools_now/ },
|
||||
en: { installed: "Installed", tools: "Tools for every agent: weather-tools_now, weather-tools_week", nothing: "Signs in to nothing", provider: "Provider", given: "Tools for agents: video_make", hidden: "Tools, hidden from agents: video_make", hide: "Hide from agents", give: "Give to agents" },
|
||||
zh: { installed: "已安装", tools: "给每个智能体的工具:weather-tools_now、weather-tools_week", nothing: "不能登录", provider: "供应商", given: "给智能体的工具:video_make", hidden: "工具,已对智能体隐藏:video_make", hide: "对智能体隐藏", give: "交给智能体" },
|
||||
"zh-TW": { installed: "已安裝", tools: /^給每個代理的工具:weather-tools_now/, given: "給代理的工具:video_make", hidden: "工具,已對代理隱藏:video_make", hide: "對代理隱藏", give: "交給代理" },
|
||||
ja: { installed: "インストール済み", tools: /^すべてのエージェントのツール:weather-tools_now/, given: "エージェントのツール:video_make", hidden: "ツール(エージェントには非表示):video_make", hide: "エージェントに隠す", give: "エージェントに渡す" },
|
||||
de: { installed: "Installiert", tools: /^Werkzeuge für jeden Agenten: weather-tools_now/, given: "Werkzeuge für Agenten: video_make", hidden: "Werkzeuge, vor Agenten verborgen: video_make", hide: "Vor Agenten verbergen", give: "Agenten geben" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
@@ -92,6 +103,25 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.ok((await both.innerText()).includes("Acme"));
|
||||
assert.ok((await both.locator(".pm-tools").innerText()).includes("both_lookup"));
|
||||
assert.equal(await row("off").locator(".pm-tools").count(), 0, "a plugin off lists no tools");
|
||||
assert.equal(await weather.locator(".pm-tools-flip").count(), 0, "no server in the Library, nothing to hide");
|
||||
|
||||
// hidden from every agent, and given back, from the row
|
||||
video.toolsServer.on = true;
|
||||
shown.length = 0;
|
||||
const vline = row("video").locator(".pm-tools");
|
||||
assert.equal((await vline.locator("span").first().innerText()).trim(), w.given);
|
||||
const flip = vline.locator(".pm-tools-flip");
|
||||
assert.equal((await flip.innerText()).trim(), w.hide);
|
||||
await flip.click();
|
||||
await vline.locator(".pm-tools-flip", { hasText: w.give }).waitFor();
|
||||
assert.equal((await vline.locator("span").first().innerText()).trim(), w.hidden);
|
||||
assert.deepEqual(shown, [{ name: VIDEO, on: false }]);
|
||||
assert.ok(!(await row("video").innerText()).includes("Off\n"), "the plugin itself stays on");
|
||||
await vline.locator(".pm-tools-flip").click();
|
||||
await vline.locator(".pm-tools-flip", { hasText: w.hide }).waitFor();
|
||||
assert.deepEqual(shown, [{ name: VIDEO, on: false }, { name: VIDEO, on: true }]);
|
||||
const [fb, vb] = await Promise.all([vline.locator(".pm-tools-flip").boundingBox(), row("video").boundingBox()]);
|
||||
assert.ok(fb.x + fb.width <= vb.x + vb.width + 1, "the line's button overflows its row");
|
||||
|
||||
const over = await page.evaluate(() => document.scrollingElement.scrollWidth - document.scrollingElement.clientWidth);
|
||||
assert.ok(over <= 0, "page scrolls sideways by " + over);
|
||||
|
||||
@@ -191,6 +191,12 @@ func load() (*Library, error) {
|
||||
|
||||
func (l *Library) save() error {
|
||||
sort.Slice(l.MCP, func(i, j int) bool { return l.MCP[i].Name < l.MCP[j].Name })
|
||||
// a paused server given an agent, however, is on again
|
||||
for _, s := range l.MCP {
|
||||
if len(s.Agents) > 0 {
|
||||
s.Hidden, s.Paused = false, nil
|
||||
}
|
||||
}
|
||||
sort.Slice(l.Skills, func(i, j int) bool { return l.Skills[i].Name < l.Skills[j].Name })
|
||||
sort.Slice(l.Projects, func(i, j int) bool { return l.Projects[i].Dir < l.Projects[j].Dir })
|
||||
sort.Slice(l.Hooks, func(i, j int) bool { return l.Hooks[i].Name < l.Hooks[j].Name })
|
||||
|
||||
@@ -64,6 +64,13 @@ type Server struct {
|
||||
// gateway serves them at its URL, and the hub calls the plugin itself
|
||||
// (plugin_tools.go)
|
||||
Plugin string `json:"plugin,omitempty"`
|
||||
// Hidden is a plugin's server whose tools were hidden from every
|
||||
// agent on the Plugins page (PluginServerOn, chengming0v0 on
|
||||
// Discord): no agent is given it, nor an app at the MCP router's
|
||||
// address. Paused are the agents it had, given back when it is shown
|
||||
// again. Both go once the server has an agent again (save).
|
||||
Hidden bool `json:"hidden,omitempty"`
|
||||
Paused []string `json:"paused,omitempty"`
|
||||
// Bridge is the Remote magpie (its provider id) whose MCP router the
|
||||
// server is, given a server of its own (bridge_mcp.go)
|
||||
Bridge string `json:"bridge,omitempty"`
|
||||
|
||||
@@ -202,7 +202,7 @@ func hubServers(agentID string) []*Server {
|
||||
func (l *Library) hubServers(agentID string) []*Server {
|
||||
var out []*Server
|
||||
for _, s := range l.MCP {
|
||||
if (agentID == "" || slices.Contains(s.Agents, agentID)) && inHub(s, agentID) {
|
||||
if (agentID == "" && !s.Hidden || slices.Contains(s.Agents, agentID)) && inHub(s, agentID) {
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ package library
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"slices"
|
||||
@@ -37,6 +38,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// pluginToolsOf and runPluginToolOf are the gateway's, a test's fakes in
|
||||
@@ -191,3 +193,88 @@ func pluginHubCall(ctx context.Context, agentID string, s *Server, tool string,
|
||||
}
|
||||
return json.Marshal(map[string]any{"content": []map[string]any{{"type": "text", "text": said}}, "isError": false})
|
||||
}
|
||||
|
||||
// PluginServer is the server of a plugin's tools, as the plugin's row on
|
||||
// the Plugins page shows it.
|
||||
type PluginServer struct {
|
||||
Name string `json:"name"`
|
||||
Plugin string `json:"plugin"` // plugin.Name, which PluginServerOn takes
|
||||
// On is whether any agent is given it
|
||||
On bool `json:"on"`
|
||||
}
|
||||
|
||||
// PluginServers are the plugins' servers by plugin (plugin.Name); none
|
||||
// when the library can't be read.
|
||||
func PluginServers() map[string]PluginServer {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
l, err := load()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
out := map[string]PluginServer{}
|
||||
for _, s := range l.MCP {
|
||||
if s.Plugin != "" {
|
||||
out[s.Plugin] = PluginServer{Name: s.Name, Plugin: s.Plugin, On: len(s.Agents) > 0}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PluginServerOn hides a plugin's tools from every agent, or shows them
|
||||
// again (chengming0v0 on Discord: a plugin's tools no agent should see,
|
||||
// the plugin kept for its providers). Hidden, no agent is given the
|
||||
// server, nor an app at the MCP router's address, and the agents it had
|
||||
// are kept (Paused); shown again, they get it back. With none kept (it was given to none when added, or
|
||||
// taken from each agent in the Library), on gives it to the agents the MCP
|
||||
// router's entry goes to, or with the router off or given to none, to every
|
||||
// agent shown that can take it, as the row's All chip in the Library does.
|
||||
func PluginServerOn(pluginName string, on bool) (*Result, error) {
|
||||
return change(func(l *Library) error {
|
||||
var s *Server
|
||||
for _, x := range l.MCP {
|
||||
if x.Plugin == pluginName {
|
||||
s = x
|
||||
}
|
||||
}
|
||||
if s == nil {
|
||||
return fmt.Errorf("%s has no MCP server in the library", pluginName)
|
||||
}
|
||||
if !on {
|
||||
if !s.Hidden {
|
||||
s.Hidden, s.Paused, s.Agents = true, s.Agents, []string{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(s.Agents) > 0 {
|
||||
s.Hidden, s.Paused = false, nil
|
||||
return nil
|
||||
}
|
||||
want := s.Paused
|
||||
if len(want) == 0 {
|
||||
want = l.hubAgents()
|
||||
}
|
||||
r := reachNow()
|
||||
if len(want) == 0 {
|
||||
hidden := settings.Load().AgentsHidden
|
||||
for _, a := range r.order {
|
||||
if !slices.Contains(hidden, a) {
|
||||
want = append(want, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
var to []string
|
||||
for _, a := range want {
|
||||
// one kept from before goes back as it was: its distro may be
|
||||
// stopped, or its file unread just now
|
||||
if len(s.Paused) > 0 || r.takes(a, s) {
|
||||
to = append(to, a)
|
||||
}
|
||||
}
|
||||
if len(to) == 0 {
|
||||
return fmt.Errorf("no agent can take %s", s.Name)
|
||||
}
|
||||
s.Agents, s.Hidden, s.Paused = slices.Compact(slices.Sorted(slices.Values(to))), false, nil
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -215,3 +215,90 @@ func TestPluginToolsServerThroughAnotherAddress(t *testing.T) {
|
||||
t.Errorf("the stored server changed: %s", s.URL)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin's tools hidden from every agent on the Plugins page
|
||||
// (chengming0v0 on Discord: MiniMax's tools, the plugin kept for its
|
||||
// providers): no agent's hub lists or runs them, nor an app's at the
|
||||
// router's address; hidden they stay through the plugin updated, turned
|
||||
// off and on, and the server edited; shown again, the agents that had
|
||||
// them get them back. An agent ticked in the Library shows them too.
|
||||
func TestPluginToolsHidden(t *testing.T) {
|
||||
hubSandbox(t)
|
||||
f := fakePluginTools(t, search1api)
|
||||
fake := fakeStdio(t, "ok", nil)
|
||||
fake.Agents = []string{"claude"}
|
||||
ok(t)(SaveServer("", *fake))
|
||||
ok(t)(SetMCPHub(true))
|
||||
ok(t)(Sync())
|
||||
const name = "@magpie-community/tools-search1api"
|
||||
ctx := context.Background()
|
||||
hub := theHub{}
|
||||
listed := func(agentID string) bool {
|
||||
return slices.Contains(hubNames(hub.Tools(ctx, agentID)), "search1api/search")
|
||||
}
|
||||
if !listed("claude") || !listed("") || !PluginServers()[name].On {
|
||||
t.Fatal("the plugin's tools aren't given to begin with")
|
||||
}
|
||||
|
||||
ok(t)(PluginServerOn(name, false))
|
||||
hidden := func(when string) {
|
||||
t.Helper()
|
||||
l, err := load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := l.server("search1api")
|
||||
if s == nil || !s.Hidden || len(s.Agents) != 0 || !slices.Equal(s.Paused, []string{"claude"}) {
|
||||
t.Fatalf("%s: %+v", when, s)
|
||||
}
|
||||
if listed("claude") || listed("") || PluginServers()[name].On {
|
||||
t.Fatalf("%s: still listed", when)
|
||||
}
|
||||
if _, err := hub.Call(ctx, "", "search1api", "search", json.RawMessage(`{}`)); err == nil {
|
||||
t.Fatalf("%s: an app at the router's address ran it", when)
|
||||
}
|
||||
}
|
||||
hidden("hidden")
|
||||
f.specs = []string{"@magpie-community/tools-search1api@0.1.2"}
|
||||
ok(t)(Sync())
|
||||
hidden("the plugin updated")
|
||||
f.off = true
|
||||
ok(t)(Sync())
|
||||
f.off = false
|
||||
ok(t)(Sync())
|
||||
hidden("the plugin off and on")
|
||||
l, _ := load()
|
||||
ed := *l.server("search1api")
|
||||
ed.Hidden, ed.Paused, ed.Note = false, nil, "videos"
|
||||
ok(t)(SaveServer("search1api", ed))
|
||||
hidden("edited")
|
||||
ok(t)(PluginServerOn(name, false))
|
||||
hidden("hidden twice")
|
||||
ok(t)(EveryServerAgents([]string{"claude"}, true))
|
||||
hidden("every server given to claude")
|
||||
if l, _ := load(); !slices.Contains(l.server("fake").Agents, "claude") {
|
||||
t.Fatal("every server given to claude left out another server")
|
||||
}
|
||||
|
||||
ok(t)(PluginServerOn(name, true))
|
||||
if l, _ := load(); !slices.Equal(l.server("search1api").Agents, []string{"claude"}) || l.server("search1api").Hidden || !listed("claude") || !listed("") {
|
||||
t.Fatalf("shown again: %+v", l.server("search1api"))
|
||||
}
|
||||
|
||||
// ticked for an agent in the Library, it is shown
|
||||
ok(t)(PluginServerOn(name, false))
|
||||
ok(t)(ServerAgents("search1api", []string{"codex"}))
|
||||
if l, _ := load(); l.server("search1api").Hidden || l.server("search1api").Paused != nil || !listed("") {
|
||||
t.Fatalf("ticked in the Library, still hidden: %+v", l.server("search1api"))
|
||||
}
|
||||
|
||||
// none kept: shown, it goes to the agents of the router's entry
|
||||
ok(t)(ServerAgents("search1api", []string{}))
|
||||
ok(t)(PluginServerOn(name, true))
|
||||
if l, _ := load(); !slices.Equal(l.server("search1api").Agents, []string{"claude"}) {
|
||||
t.Fatalf("shown with none kept, the router on: %v", l.server("search1api").Agents)
|
||||
}
|
||||
if _, err := PluginServerOn("@x/none", true); err == nil {
|
||||
t.Error("a plugin with no server shown")
|
||||
}
|
||||
}
|
||||
|
||||
+42
-15
@@ -783,6 +783,10 @@ func SaveServer(old string, s Server) (*Result, error) {
|
||||
if p := l.MCP[i].Plugin; p != "" && s.Plugin == "" {
|
||||
s.Plugin, s.Local = p, true
|
||||
}
|
||||
// still off, it still knows whom to give it back to
|
||||
if len(s.Agents) == 0 && !s.Hidden {
|
||||
s.Hidden, s.Paused = l.MCP[i].Hidden, l.MCP[i].Paused
|
||||
}
|
||||
// a Remote magpie's router stays its own while it is at the
|
||||
// provider's address and key (bridge_mcp.go)
|
||||
keptBridge(l.MCP[i], &s)
|
||||
@@ -843,29 +847,22 @@ func serversAgents(names, agents []string, on bool) (*Result, error) {
|
||||
return fmt.Errorf("no server called %s", name)
|
||||
}
|
||||
}
|
||||
mcp := map[string]*mcpFile{}
|
||||
// a stopped distro's agents, by what magpie last knew of them
|
||||
shapes := map[string]*shape{}
|
||||
var r reach
|
||||
if on {
|
||||
ts, asleep := targetsAsleep(false)
|
||||
for _, t := range ts {
|
||||
if t.MCP != nil {
|
||||
mcp[t.Agent.ID] = t.MCP
|
||||
}
|
||||
}
|
||||
for _, a := range asleep {
|
||||
if sh := shapeOf(a); sh != nil {
|
||||
shapes[a.ID] = sh
|
||||
}
|
||||
}
|
||||
r = reachNow()
|
||||
}
|
||||
for _, s := range l.MCP {
|
||||
if names != nil && !slices.Contains(names, s.Name) {
|
||||
continue
|
||||
}
|
||||
// an agent's every server leaves out a plugin's hidden from
|
||||
// every agent on the Plugins page; named, it is shown
|
||||
if names == nil && on && s.Hidden {
|
||||
continue
|
||||
}
|
||||
kept := slices.DeleteFunc(slices.Clone(s.Agents), func(a string) bool { return slices.Contains(agents, a) })
|
||||
for _, a := range agents {
|
||||
if on && mcp[a] != nil && mcp[a].supports(s) == nil || on && shapes[a] != nil && shapes[a].reaches(s) {
|
||||
if on && r.takes(a, s) {
|
||||
kept = append(kept, a)
|
||||
} else if on && slices.Contains(s.Agents, a) {
|
||||
kept = append(kept, a) // one it has already stays, whatever it says of it
|
||||
@@ -877,6 +874,36 @@ func serversAgents(names, agents []string, on bool) (*Result, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// reach is which agents a server can be given: those whose MCP file
|
||||
// supports it, and a stopped distro's by what magpie last knew of them.
|
||||
type reach struct {
|
||||
mcp map[string]*mcpFile
|
||||
shapes map[string]*shape
|
||||
order []string // every agent it knows, as found
|
||||
}
|
||||
|
||||
func reachNow() reach {
|
||||
r := reach{mcp: map[string]*mcpFile{}, shapes: map[string]*shape{}}
|
||||
ts, asleep := targetsAsleep(false)
|
||||
for _, t := range ts {
|
||||
if t.MCP != nil {
|
||||
r.mcp[t.Agent.ID] = t.MCP
|
||||
r.order = append(r.order, t.Agent.ID)
|
||||
}
|
||||
}
|
||||
for _, a := range asleep {
|
||||
if sh := shapeOf(a); sh != nil {
|
||||
r.shapes[a.ID] = sh
|
||||
r.order = append(r.order, a.ID)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (r reach) takes(a string, s *Server) bool {
|
||||
return r.mcp[a] != nil && r.mcp[a].supports(s) == nil || r.shapes[a] != nil && r.shapes[a].reaches(s)
|
||||
}
|
||||
|
||||
// RemoveServer takes a server out of the library and out of every agent
|
||||
// magpie gave it to.
|
||||
func RemoveServer(name string) (*Result, error) {
|
||||
|
||||
@@ -811,6 +811,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<p>設定 → プラグインには各プラグインのツールがこの名前で表示され、サーバーのアドレスをコピーできます。<code>args</code> は zod のフィールド定義(<code>tool.schema</code> は zod)、zod オブジェクト、または JSON Schema オブジェクトです。エージェントにはこれが示され、magpie は <code>execute</code> の前に呼び出しの引数をこれで検証します。引数が正しくなければ、その引数を示すエラーを返します。<code>ctx</code> は OpenCode と同じで、<code>agent</code> は呼び出したエージェントです。ツールの実行時間は 55 秒までで、時間切れになると <code>ctx.abort</code> が発火します。</p>
|
||||
<p>このサーバーは組み込みプラグイン <span class="ui">プラグインのツール</span> が提供します。オンのプラグインがツールを提供している間はオンのままで、オフのときはツールが一覧に出ず、呼び出しにはオフであることが返ります。ゲートウェイキーでの呼び出しはそのキーの上限に数えられます。ツールはプロバイダープラグインと同じくあなたの権限でプラグインホスト内で動き、結果は呼び出したエージェントにだけ返ります。</p>
|
||||
<p>ツールを提供するプラグインは、ライブラリの MCP タブにもそれぞれ独立したサーバーとして現れ、プラグインの短い名前(<code>search1api</code>)が付きます。アドレスを手で追加する必要はありません。<a href="mcp-router.html">MCP ルーター</a>がオンなら、そのツールはルーターを使うすべてのエージェントに <code>search1api__search</code> として出ます。ほかのライブラリのサーバーと同じく、エージェントごとにオン・オフでき、ツールを一つずつ止めることもできます。削除すると、プラグインを外して追加し直すまで戻りません。</p>
|
||||
<p>プロバイダーのためにプラグインは残し、ツールはどのエージェントにも渡したくないときは、<span class="ui">プラグイン</span> › <span class="ui">インストール済み</span>でそのツールの行の<span class="ui">エージェントに隠す</span>を押します。サーバーはどのエージェントにも、ルーターのアドレスにつなぐアプリにも渡されず、更新、オフとオン、再起動のあとも変わりません。<span class="ui">エージェントに渡す</span>で、元のエージェントに戻ります。</p>
|
||||
|
||||
<h2 id="agents"><a class="anchor" href="#agents">エージェントプラグイン</a></h2>
|
||||
<p>プラグインは<em>エージェント</em>を追加することもできます。magpie に組み込みの設定がないエージェントです。そのエージェントがモデルをどこに書くか、magpie のゲートウェイを使うために他に何を書くかを伝えます。するとエージェントは magpie 自身のものと同じように<span class="ui">エージェント</span>ページに並びます。その行で magpie のモデルを選ぶと、magpie はモデルをゲートウェイのアドレスとエージェント専用のキーと一緒に設定へ書き込み、スイッチを切るとすべてユーザーの元の状態に戻します。下の例は <a href="https://aider.chat">Aider</a> を追加します。</p>
|
||||
|
||||
@@ -811,6 +811,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<p>Settings → Plugins lists each plugin’s tools by these names and copies the server’s address. <code>args</code> is a zod shape (<code>tool.schema</code> is zod), a zod object or a JSON Schema object. The agent is shown it, and magpie checks a call’s arguments against it before <code>execute</code> runs; a wrong argument is answered as an error naming it. <code>ctx</code> is OpenCode’s, with <code>agent</code> the agent that called. A tool has 55 seconds, and <code>ctx.abort</code> fires when they are up.</p>
|
||||
<p>The built-in plugin <span class="ui">Plugin tools</span> serves the server. It stays on while a plugin that is on gives a tool; off, no tool is listed and a call says so. A call made with a gateway key counts against that key’s limits. A tool runs in the plugin host with your rights, as a provider plugin does, and its answer goes only to the agent that called it.</p>
|
||||
<p>Each plugin that gives tools is also a server of its own in the Library’s MCP tab, named by the plugin’s short name (<code>search1api</code>), so you don’t have to add the address by hand. With the <a href="mcp-router.html">MCP router</a> on, its tools are in the router of every agent the router is given, as <code>search1api__search</code>; switch it on or off per agent, or turn single tools off, as with any Library server. Removed, it comes back only when you remove the plugin and add it again.</p>
|
||||
<p>To keep a plugin for its providers but give its tools to no agent, press <span class="ui">Hide from agents</span> on its tools line under <span class="ui">Plugins</span> › <span class="ui">Installed</span>. Its server is then given to no agent, nor to an app at the router’s address, through updates, the plugin off and on, and restarts. <span class="ui">Give to agents</span> gives it back to the agents it had.</p>
|
||||
|
||||
<h2 id="agents"><a class="anchor" href="#agents">Agent plugins</a></h2>
|
||||
<p>A plugin can also add an <em>agent</em>: one magpie has no setup of its own for. It says where the agent keeps its model and what else to write there for the agent to use magpie’s gateway. The agent is then on the <span class="ui">Agents</span> page like magpie’s own: pick one of magpie’s models in its row and magpie writes it into the agent’s config, with the gateway’s address and a key of the agent’s own; switch it off and everything goes back to how the user had it. The example below adds <a href="https://aider.chat">Aider</a>.</p>
|
||||
|
||||
@@ -811,6 +811,7 @@ claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/to
|
||||
<p>设置 → 插件里会按这些名字列出每个插件的工具,并能复制服务器地址。<code>args</code> 可以是 zod 字段表(<code>tool.schema</code> 就是 zod)、zod 对象或 JSON Schema 对象。智能体会看到它,magpie 在 <code>execute</code> 运行前按它检查调用的参数;参数不对时回一个写明是哪个参数的错误。<code>ctx</code> 与 OpenCode 的相同,<code>agent</code> 是发起调用的智能体。每个工具最多运行 55 秒,到时 <code>ctx.abort</code> 触发。</p>
|
||||
<p>这个服务器由内置插件 <span class="ui">插件工具</span> 提供。只要有已开启的插件提供工具,它就保持开启;关闭时不列出任何工具,调用会说明它已关闭。用网关密钥发起的调用计入该密钥的限额。工具和提供方插件一样,以你的权限在插件宿主里运行,结果只回给调用它的智能体。</p>
|
||||
<p>每个提供工具的插件也会在资料库的 MCP 页里成为一个独立的服务器,以插件的短名命名(如 <code>search1api</code>),不用再手动添加地址。开启 <a href="mcp-router.html">MCP 路由</a>时,它的工具会出现在每个接入路由的智能体里,名为 <code>search1api__search</code>;和资料库里其他服务器一样,可以按智能体开关,或单独关掉某个工具。删掉后,只有把插件移除再重新添加才会再出现。</p>
|
||||
<p>想保留插件的供应商、却不把它的工具给任何智能体:在<span class="ui">插件</span> › <span class="ui">已安装</span>里,点它工具那一行的<span class="ui">对智能体隐藏</span>。之后它的服务器不会给任何智能体,也不会给连到路由地址的应用;插件更新、关了再开、重启都保持不变。点<span class="ui">交给智能体</span>,就还给原来那些智能体。</p>
|
||||
|
||||
<h2 id="agents"><a class="anchor" href="#agents">Agent 插件</a></h2>
|
||||
<p>插件还可以添加一个 <em>Agent</em>:magpie 没有内置接入的那种。它说明这个 Agent 把模型写在哪里,以及还要写些什么才能让 Agent 走 magpie 的网关。这样它就和 magpie 内置的 Agent 一样出现在 <span class="ui">Agent</span> 页:在它那一行选一个 magpie 的模型,magpie 就把模型连同网关地址和这个 Agent 自己的 key 写进它的配置;关掉开关,一切恢复成用户原来的样子。下面的例子添加 <a href="https://aider.chat">Aider</a>。</p>
|
||||
|
||||
Reference in New Issue
Block a user