diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index d0c867687..60fe00d65 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -142,6 +142,7 @@ const I18N = { "Local servers need no key": "本地服务无需密钥", "Open the row and paste an API key": "展开这一行并粘贴 API 密钥", "{agent} is signed in, but stays out of this list. ": "{agent} 已登录,但不在此列表中。", + "{agents} adds these itself, each time it starts, and magpie leaves them as they are: {names}": "{agents} 每次启动都会自己加上这些,magpie 不去动它们:{names}", "{agent}'s saved accounts aren't offered. ": "{agent} 保存的账号没有提供出来。", "signed in": "已登录", "{p} exposes no models yet — pick some below": "{p} 尚未暴露模型 — 在下方选几个", diff --git a/internal/gui/assets/library.js b/internal/gui/assets/library.js index b815073b3..cd62c304d 100644 --- a/internal/gui/assets/library.js +++ b/internal/gui/assets/library.js @@ -442,14 +442,21 @@ after.append(button(t("+ Add server"), "", () => editServer(null))); body.append(after); } - if (lib.foundServers.length) { + const found = lib.foundServers.filter((f) => !f.own), own = lib.foundServers.filter((f) => f.own); + if (found.length) { const rh = el("div", "row-head"); rh.append(el("span", "label", t("In your agents")), el("span", "grow"), el("span", "note", t("not in the library — bring one in to manage it here"))); body.append(rh); const list = el("div", "list lib-list"); - for (const f of lib.foundServers) list.append(foundServerRow(f)); + for (const f of found) list.append(foundServerRow(f)); body.append(list); } + if (own.length) { + const by = [...new Set(own.flatMap((f) => f.server.agents))].map(nameOf).join(", "); + const p = el("p", "lib-aside", t("{agents} adds these itself, each time it starts, and magpie leaves them as they are: {names}", { agents: by, names: own.map((f) => f.server.name).join(", ") })); + p.title = own.map((f) => f.server.name + ": " + serverLine(f.server)).join("\n"); + body.append(p); + } const skip = shownAgents().filter((a) => !a.mcp); if (skip.length) body.append(el("p", "lib-aside", t("{agents} has no MCP servers magpie can write.", { agents: skip.map((a) => a.name).join(", ") }))); body.append(discover("mcp")); diff --git a/internal/library/library_test.go b/internal/library/library_test.go index 97424827d..6ccbeb840 100644 --- a/internal/library/library_test.go +++ b/internal/library/library_test.go @@ -5,6 +5,7 @@ import ( "bytes" "compress/gzip" "encoding/json" + "maps" "net/http" "net/http/httptest" "os" @@ -706,3 +707,34 @@ func TestClaudeDesktopMCP(t *testing.T) { } } } + +// The servers Codex's app writes into its config itself are told apart: +// its own, not ones to bring in. +func TestFoundServersAppOwned(t *testing.T) { + h := sandbox(t) + write(t, filepath.Join(h, ".codex/config.toml"), `[mcp_servers.node_repl] +command = 'C:\Users\u\AppData\Local\OpenAI\Codex\runtimes\cua_node\1.0\node_repl.exe' + +[mcp_servers.cua_repl] +command = 'C:\Program Files\WindowsApps\OpenAI.Codex_1.0_x64\ChatGPT.exe' +enabled = false + +[mcp_servers.computer-use] +command = "./Codex Computer Use.app/Contents/SharedSupport/SkyComputerUseClient.app/Contents/MacOS/SkyComputerUseClient" + +[mcp_servers.gh] +command = "gh-mcp" +`) + v, err := Read(nil) + if err != nil { + t.Fatal(err) + } + own := map[string]bool{} + for _, f := range v.FoundServers { + own[f.Server.Name] = f.Own + } + want := map[string]bool{"node_repl": true, "cua_repl": true, "computer-use": true, "gh": false} + if !maps.Equal(own, want) { + t.Errorf("own: %v, want %v", own, want) + } +} diff --git a/internal/library/mcp.go b/internal/library/mcp.go index 71c018291..17782ebf7 100644 --- a/internal/library/mcp.go +++ b/internal/library/mcp.go @@ -599,6 +599,26 @@ type Found struct { Server *Server `json:"server"` Others []string `json:"others,omitempty"` Icon string `json:"icon,omitempty"` + // Own: the agent's app puts it there itself, each time it starts + // (Codex's node_repl and cua_repl): it isn't one to bring in, and + // taking it out doesn't last. + Own bool `json:"own,omitempty"` +} + +// appOwned is whether a server runs from inside an app's own install — a +// Mac app bundle, a Microsoft Store app, the Codex app's runtimes — as the +// servers an agent's app writes into its config itself do. +func appOwned(s *Server) bool { + if s.Remote() { + return false + } + cmd := strings.ToLower(strings.ReplaceAll(s.Command, `\`, "/")) + for _, in := range []string{".app/contents/", "/windowsapps/", "/cua_node/", "/openai/codex/runtimes/"} { + if strings.Contains(cmd, in) { + return true + } + } + return false } func foundServers(l *Library) []Found { @@ -621,7 +641,7 @@ func foundServers(l *Library) []Found { switch { case f == nil: s.Agents = []string{t.Agent.ID} - byName[name] = &Found{Server: s} + byName[name] = &Found{Server: s, Own: appOwned(s)} names = append(names, name) case f.Server.same(s): f.Server.Agents = append(f.Server.Agents, t.Agent.ID) diff --git a/library_cli.go b/library_cli.go index e58fed248..9c3cfdd0e 100644 --- a/library_cli.go +++ b/library_cli.go @@ -187,6 +187,20 @@ func libraryStatus() error { fmt.Println(" ", amber.Render("!"), a, muted.Render(e)) } } + var found, own []string + for _, f := range v.FoundServers { + if f.Own { + own = append(own, f.Server.Name+muted.Render(" ("+strings.Join(f.Server.Agents, ", ")+"'s own)")) + } else { + found = append(found, f.Server.Name+muted.Render(" ("+strings.Join(f.Server.Agents, ", ")+")")) + } + } + if len(found) > 0 { + fmt.Println(" ", muted.Render("in your agents, not in the library:"), strings.Join(found, ", ")) + } + if len(own) > 0 { + fmt.Println(" ", muted.Render("added by the agent itself, left as they are:"), strings.Join(own, ", ")) + } fmt.Println(bold.Render("Skills")) if len(v.Skills) == 0 { fmt.Println(" ", muted.Render("none yet"))