cuipengcx90's #4382, Option A's first step (nifengfanpan asked on Discord): with the MCP hub on, every Library server went behind magpie's one entry, so a server that reads its project from the folder it starts in, or keeps a session's state, resolved the wrong repository or shared state across agents. A server now has a hub policy, Server.Hub ("hub" in library.json): "" (shared, the default, so nothing changes for existing users; "shared" is saved as "") or "direct". A direct server is left out of the hub through inHub, the test that already keeps magpie's own image server out, so each agent given it keeps its own entry written as with the hub off, beside the hub's entry for the rest. An agent whose every server is direct gets no hub entry. The hub neither lists nor runs a direct server, at /mcp/magpie/hub either, and hubPrune ends one it held. Switching goes through change(), so the agents are written again at once and the entry from the other policy is removed. An unknown policy is an error. - GUI: with the hub on, the server editor has a "Through the MCP hub" switch (role=switch, not a <select>; not shown with the hub off or for the image server), a direct server's row has a "Not through the hub" tag, and the hub's line and the Connect sheet name the direct servers with the image server as given directly. Strings are in zh, zh-TW, ja and de ("MCP 聚合" as the core uses it). - CLI: magpie library mcp hub <name> shared|direct (ServerHub), and magpie library marks a direct server. - TUI: an edit keeps the policy. - Not done: Option B (per-roots/project backends behind the hub, keying hubPool by roots). It is left for later; #4382 stays open for it. Run: - TestHubDirectServer (internal/library) and the extended TestLibraryMCPHub (internal/cli) on mote. Broken by hand: inHub back to !isSelf(s) makes TestHubDirectServer red ("codex with the hub on: [magpie], want [index magpie]"). - Real configs in a sandbox HOME on mote (fake claude on PATH, the real binary built from this tree): mcp add index + web for claude and codex, hub on, hub index direct, shared, then both direct. The direct index entry was in .claude.json and .codex/config.toml beside magpie's; with every server direct both files were byte-for-byte as with the hub off (json.tool diff and diff); shared again removed the index entry. - Full Go suite (-tags nogui -timeout 45m ./...) on mote at this tree rebased on origin/main72ed121fd: 81 packages ok. Before the rebase the only red was TestQuotaSpanCarriesEveryWindowField (#4457, fixed byccbefe2a2). GOOS=linux and GOOS=windows go vet clean, gofmt clean. - GUI on WSL (magpie-desktop; mote's GUI is broken, #4125), both engines, every language: the new mcp-hub-direct.test.cjs (1100 and 390 wide, hub on and off), library-mcp-hub, mcp-local-server, i18n-keys: 88 pass. Broken by hand: not sending hub in the save makes mcp-hub-direct red (11 of 11 in chromium). - The 54 library/mcp/i18n GUI files at --test-concurrency=4 on WSL at load ~160: 978 of 988 pass. Red: library-chip-fan (webkit, fan positions), library-mcp-tools (chromium ja 420, "the click scrolled the page") and mcp-oauth-app (chromium de 390). None of them touch the hub switch or the editor's new field. They are being rerun alone, here and on origin/main, after this push; a red that only this change has is fixed next, and a red on main too is filed. Not tried: the whole GUI suite (1028 files); a real cwd-sensitive server in a real agent session; the live app window.
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// magpie library mcp hub on|off (#2679): on, the agent is given magpie's
|
|
// one MCP server in place of the library's; off, each server's own again.
|
|
// Any other word is refused, and writes nothing.
|
|
func TestLibraryMCPHub(t *testing.T) {
|
|
h := t.TempDir()
|
|
for k, v := range map[string]string{"HOME": h, "USERPROFILE": h, "XDG_CONFIG_HOME": filepath.Join(h, ".config"), "CLAUDE_CONFIG_DIR": "", "CODEX_HOME": "", "APPDATA": "", "LOCALAPPDATA": ""} {
|
|
t.Setenv(k, v)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(h, ".claude"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(h, ".claude/settings.json"), []byte("{}"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
names := func() []string {
|
|
t.Helper()
|
|
b, err := os.ReadFile(filepath.Join(h, ".claude.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var c struct {
|
|
MCPServers map[string]map[string]any `json:"mcpServers"`
|
|
}
|
|
if err := json.Unmarshal(b, &c); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var out []string
|
|
for k := range c.MCPServers {
|
|
out = append(out, k)
|
|
}
|
|
slices.Sort(out)
|
|
return out
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "add", "fs", "npx", "-y", "fs", "agents=claude"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"fs"}) {
|
|
t.Fatalf("before: %v", got)
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "on"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"magpie"}) {
|
|
t.Fatalf("hub on: %v", got)
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "yes"}); err == nil || !strings.Contains(err.Error(), "usage") {
|
|
t.Fatalf("hub yes: %v", err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"magpie"}) {
|
|
t.Fatalf("after a word it doesn't know: %v", got)
|
|
}
|
|
// a server kept direct (#4382) is its own entry again, beside no hub
|
|
// entry once no server is behind it; shared, behind the hub again
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "fs", "direct"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"fs"}) {
|
|
t.Fatalf("fs direct: %v", got)
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "fs", "solo"}); err == nil || !strings.Contains(err.Error(), "usage") {
|
|
t.Fatalf("hub fs solo: %v", err)
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "fs", "shared"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"magpie"}) {
|
|
t.Fatalf("fs shared: %v", got)
|
|
}
|
|
if err := libraryCmd([]string{"library", "mcp", "hub", "off"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := names(); !slices.Equal(got, []string{"fs"}) {
|
|
t.Fatalf("hub off: %v", got)
|
|
}
|
|
}
|