library: MCP servers turned off fold away below the ones on (hzlxb on X)

hzlxb on X asked for Library -> MCP servers to keep the servers turned off
apart, folded, as Providers keeps the providers turned off. The list now
holds the servers on. The ones off sit below it, above "+ Add server",
under a "Servers turned off (N)" fold drawn with Providers' Turned off
markup (row-head off-head, .fold with the chevron, the count in .note).
It is folded at first and remembered in localStorage
magpie.offServersOpen, as magpie.offProvidersOpen is. A server switched
off moves under the fold, and one switched on comes back up. While
picking (Select) the fold is held open and disabled, so every server
picked is in sight, as Providers holds its fold open while searching.
The MCP tab has no filter of its own, so there is nothing else for it to
hide from. With every server off only the fold shows. With none off
there is no fold. Strings are in en, zh, zh-TW, ja and de.

Run:
- library-mcp-off-fold.test.cjs (new): Chromium and WebKit, 1100 and
  420 wide, en/zh/zh-TW/ja/de. It checks order, label, count, title,
  aria-expanded, that opening by a wheel-scrolled click leaves the head
  where it is and opens no editor, the reload memory, moving on a
  switch, picking, all off and none off. It is red on the old library
  files (no fold; checked on mica in chromium).
- Library/MCP/i18n/click-scroll/providers-off-fold GUI files (102 files,
  both engines) on mote at the pre-rebase head 29a5f10f9: 2304 of 2310 pass. The 6
  reds are library-open-again's 1100px cases, red the same alone on the
  old tree (filed as #6751).
- go test -count=1 ./internal/gui/ on mica at this head: ok (143s).
  gofmt clean.
- The whole GUI suite on mote at 29a5f10f9, in two parts (mote rebooted
  mid-run; the rest ran after it came back, under suite.lock). Part 1:
  411 not ok in 75 files. Part 2 (640 files): 11355 tests, 10911 pass,
  444 fail. No red is in the files this change touches except
  library-open-again (#6751). Every red file has an open issue saying it
  is red on main: skill-fold-all/skill-manual (#6667, #6668, the
  window's /api/update/using), skill-group-shared (#6687),
  view-open-wheel (#4723), view-trackpad-coast (#4724),
  view-wheel-unheard (#5158), usage-* (#6743, #4263), the rest in #6709
  or by name; icon-tile was unfiled and is now #6759 (dim-color from
  2649d5d72, not in app.css's tile rule).
- After rebasing on origin/main 923cc8747 (1f04ed219 touched
  library.css): Library/i18n/click-scroll/providers-off/gui-* files on
  mote: 1837 of 1847 pass. Reds: library-open-again's 1100px
  cases (#6751), library-env de (#6675, NO_PROXYlocalhost) and
  library-chip-fan de no-preference (#3072), both chromium only; those
  two pass 3 of 3 alone at this head and at origin/main 923cc8747; go test -count=1 ./internal/gui/ on mica: ok (154s).

Not tried: the real app, including WebKitGTK on Linux. The fold has no
motion of its own (it uses Providers' chevron rotation).
This commit is contained in:
yetone
2026-11-15 21:22:45 +08:00
parent 923cc8747f
commit d7cda856ad
6 changed files with 244 additions and 5 deletions
File diff suppressed because one or more lines are too long
+38 -3
View File
@@ -1055,7 +1055,7 @@ magpie.plugin("library", (ctx) => {
else if (tab === "plugins") renderPlugins(body);
else renderSkills(body);
page.append(body);
for (const n of body.querySelectorAll(".row-head .note")) n.title = n.textContent;
for (const n of body.querySelectorAll(".row-head .note")) if (!n.closest(".fold")) n.title = n.textContent;
for (const d of page.querySelectorAll(".lib-detail[data-detail]")) if (had.has(d.dataset.detail)) d.classList.add("kept");
for (const f of fits.splice(0)) f();
page.scrollTop = top;
@@ -2780,6 +2780,8 @@ magpie.plugin("library", (ctx) => {
const remote = (s) => s.transport === "http" || s.transport === "sse";
const reaches = (s) => (a) => !a || (!(remote(s) && a.noRemote) && !(s.transport === "sse" && a.noSSE) && !(envRefs(s) && a.noEnvRefs));
let serversOffFolded = true; // the servers turned off, folded below the ones on
try { serversOffFolded = localStorage.getItem("magpie.offServersOpen") !== "1"; } catch {}
function renderServers(body) {
body.append(intro(agentless()
? t("Add the servers other apps should reach, and turn on the MCP router: they connect at its address, from another computer with a gateway key.")
@@ -2794,8 +2796,41 @@ magpie.plugin("library", (ctx) => {
if (agentless()) body.append(...hubPart());
} else {
const list = el("div", "list lib-list");
// turned off, they fold away below the ones on, as Providers' do
// (hzlxb on X), folded at first and remembered; while picking, the
// fold stays open, for every server picked to be in sight
const offList = el("div", "list lib-list lib-offlist");
offList.id = "lib-offServers";
const offHead = el("div", "row-head off-head lib-offhead");
const fold = el("button", "fold");
fold.type = "button";
fold.setAttribute("aria-controls", offList.id);
const offCount = el("span", "note");
fold.append(svg(CHEV_R, 11, 1.6), el("span", "label", t("Servers turned off")), offCount);
offHead.append(fold);
const syncFold = () => {
const offs = offList.childElementCount, open = !!picking || !serversOffFolded;
offHead.hidden = !offs;
list.hidden = offs > 0 && !list.childElementCount;
offList.hidden = !offs || !open;
offCount.textContent = offs || "";
fold.disabled = !!picking;
fold.setAttribute("aria-expanded", String(open));
fold.title = t(open ? "Fold the servers turned off away" : "Show the servers turned off");
};
fold.onclick = (e) => {
e.stopPropagation();
serversOffFolded = !serversOffFolded;
try { localStorage.setItem("magpie.offServersOpen", serversOffFolded ? "0" : "1"); } catch {}
syncFold();
};
// in the order the reader picked (#481), A→Z till then
const fill = () => list.replaceChildren(...[...lib.servers].sort(byName(sortOf("libServers"))).map((s) => serverRow(s, all)));
const fill = () => {
const sorted = [...lib.servers].sort(byName(sortOf("libServers")));
list.replaceChildren(...sorted.filter((s) => !s.hidden).map((s) => serverRow(s, all)));
offList.replaceChildren(...sorted.filter((s) => s.hidden).map((s) => serverRow(s, all)));
syncFold();
};
// one heading over the list, with what the skills' has (#1027): the
// order, Select, every server on or off for every agent shown, one
// agent's (#475, or out of a hidden one) and every server out
@@ -2815,7 +2850,7 @@ magpie.plugin("library", (ctx) => {
body.append(rh);
}
fill();
body.append(list);
body.append(list, offHead, offList);
if (picking) body.append(pickBar(all));
const after = el("div", "after-list");
after.append(button(t("+ Add server"), "", () => editServer(null)));
@@ -737,6 +737,9 @@ magpie.strings({
"Added {n} servers": "已添加 {n} 个服务器",
"A skill is a folder with a SKILL.md an agent loads when it's needed. The library keeps each one once and links it into the agents you pick.": "技能是一个带 SKILL.md 的文件夹,Agent 在需要时加载。资源库只保存一份,再链接到你选的 Agent 中。",
"In the library": "资源库中",
"Servers turned off": "已关闭的服务器",
"Show the servers turned off": "展开已关闭的服务器",
"Fold the servers turned off away": "收起已关闭的服务器",
"By source": "按来源",
"not in the library — bring one in to give it to the others": "不在资源库中 — 导入后可以给其他 Agent",
"{agents} has no skills folder.": "{agents} 没有技能文件夹。",
@@ -1813,6 +1816,9 @@ magpie.strings({
"Added {n} servers": "已新增 {n} 個伺服器",
"A skill is a folder with a SKILL.md an agent loads when it's needed. The library keeps each one once and links it into the agents you pick.": "技能是一個帶 SKILL.md 的資料夾,Agent 在需要時載入。資源庫只儲存一份,再連結到你選的 Agent 中。",
"In the library": "資源庫中",
"Servers turned off": "已關閉的伺服器",
"Show the servers turned off": "展開已關閉的伺服器",
"Fold the servers turned off away": "收起已關閉的伺服器",
"By source": "按來源",
"not in the library — bring one in to give it to the others": "不在資源庫中 — 匯入後可以給其他 Agent",
"{agents} has no skills folder.": "{agents} 沒有技能資料夾。",
@@ -2880,6 +2886,9 @@ magpie.strings({
"Added {n} servers": "{n} 個のサーバーを追加しました",
"A skill is a folder with a SKILL.md an agent loads when it's needed. The library keeps each one once and links it into the agents you pick.": "スキルとは、エージェントが必要なときに読み込む SKILL.md を含むフォルダです。ライブラリは各スキルを1つだけ保管し、選んだエージェントにリンクします。",
"In the library": "ライブラリ内",
"Servers turned off": "オフのサーバー",
"Show the servers turned off": "オフのサーバーを表示",
"Fold the servers turned off away": "オフのサーバーを折りたたむ",
"By source": "ソース別",
"not in the library — bring one in to give it to the others": "ライブラリにありません — 取り込むと他のエージェントにも渡せます",
"{agents} has no skills folder.": "{agents} にはスキルフォルダがありません。",
@@ -3952,6 +3961,9 @@ magpie.strings({
"Added {n} servers": "{n} Server hinzugefügt",
"A skill is a folder with a SKILL.md an agent loads when it's needed. The library keeps each one once and links it into the agents you pick.": "Ein Skill ist ein Ordner mit einer SKILL.md, die ein Agent bei Bedarf lädt. Die Bibliothek hält jeden nur einmal vor und verlinkt ihn in die Agenten, die Sie wählen.",
"In the library": "In der Bibliothek",
"Servers turned off": "Ausgeschaltete Server",
"Show the servers turned off": "Ausgeschaltete Server anzeigen",
"Fold the servers turned off away": "Ausgeschaltete Server einklappen",
"By source": "Nach Quelle",
"not in the library — bring one in to give it to the others": "nicht in der Bibliothek – übernehmen Sie einen, um ihn den anderen zu geben",
"{agents} has no skills folder.": "{agents} hat keinen Skills-Ordner.",
@@ -967,3 +967,5 @@ input.lib-memq:focus, input.lib-memtags:focus, input.lib-memwhy:focus { border-c
.lib-bili-phil { display: grid; gap: 6px; padding: 8px 0 0 15px; }
.lib-bili-phil > .name { font-size: 12.5px; color: var(--fg-2); }
.lib-bili-phil .lib-acts { justify-content: flex-end; }
/* the servers turned off, folded below the ones on, as Providers' */
#view-library .lib-offhead .fold:disabled { cursor: default; opacity: 1; }
@@ -0,0 +1,185 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// hzlxb on X: in Library → MCP servers the servers turned off sat among the
// ones on. They are kept apart now, as Providers' are: the list holds the
// ones on, and the ones off sit below it under a "Servers turned off (N)"
// fold, folded at first. The fold opens and closes on a click that leaves
// the page where it is and opens no editor, and is remembered across a
// reload; a server switched off moves under it, one switched on again comes
// back up. While picking (Select) the fold is open, for every server picked
// to be in sight. Every language, Chromium and WebKit, at 1100 and 420 wide
// with nothing running off to the side. No backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/tester";
const NAMES = ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel"];
const fixture = (st) => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", skills: `${HOME}/.claude/skills`, mcp: `${HOME}/.claude.json` }],
instructions: { agents: [], sets: [] }, foundSkills: [], skills: [], problems: [], foundServers: [], projects: [],
servers: NAMES.map((name) => st.off.has(name)
? { name, transport: "stdio", command: "uvx", args: [name + "-mcp"], agents: [], hidden: true, paused: ["claude"] }
: { name, transport: "stdio", command: "uvx", args: [name + "-mcp"], agents: ["claude"] }),
});
let I18N;
const tr = (lang, key, vars = {}) => {
let s = key;
if (lang !== "en") {
assert.equal(typeof I18N[lang][key], "string", `${lang} has no ${JSON.stringify(key)}`);
s = I18N[lang][key];
}
return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
};
function server(lang, st) {
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", gateway: "http://127.0.0.1:3425" } });
if (url.pathname === "/api/library") return json(fixture(st));
if (url.pathname === "/api/library/servers/on") {
const { name, on } = req.postDataJSON();
if (on) st.off.delete(name); else st.off.add(name);
return json({ ...fixture(st), result: { changed: [] } });
}
if (url.pathname === "/api/library/mcp/check") return json({ servers: Object.fromEntries(req.postDataJSON().names.map((n) => [n, { state: "ok", tools: 2 }])) });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
if (url.pathname.startsWith("/api/")) return json({});
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const sideways = (page) => page.evaluate(() => {
const over = [];
const w = document.documentElement.clientWidth;
if (document.documentElement.scrollWidth > w) over.push("page " + document.documentElement.scrollWidth);
for (const e of document.querySelectorAll("#view-library .lib-offhead, #view-library .lib-offhead .fold, #view-library .lib-server")) {
const r = e.getBoundingClientRect();
if (r.width && (r.right > w + 0.5 || r.left < -0.5)) over.push((e.className || e.tagName) + " " + Math.round(r.left) + "–" + Math.round(r.right));
}
return over;
});
const names = (page, sel) => page.locator(`#view-library ${sel} > .lib-server`).evaluateAll((rs) => rs.map((r) => r.dataset.server));
const top = (loc) => loc.evaluate((e) => e.getBoundingClientRect().top);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": MCP servers turned off fold away below the ones on", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
I18N = strings().I18N;
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
for (const width of [1100, 420]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
await t.test(`${lang} ${width}px`, async () => {
const w = (key, vars) => tr(lang, key, vars);
const st = { off: new Set(["bravo", "echo", "golf"]) };
const errors = [];
const ctx = await browser.newContext({ viewport: { width, height: 560 }, reducedMotion: "reduce" });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "mcp"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, st));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const v = page.locator("#view-library");
await v.locator('.lib-server[data-server="alpha"]').waitFor();
// the list holds the ones on; the ones off are under the fold, folded
assert.deepEqual(await names(page, ".lib-list:not(.lib-offlist)"), ["alpha", "charlie", "delta", "foxtrot", "hotel"]);
const fold = v.locator(".lib-offhead .fold");
assert(await fold.isVisible(), "the fold shows");
assert.equal((await fold.locator(".label").textContent()).trim(), w("Servers turned off"));
assert.equal((await fold.locator(".note").textContent()).trim(), "3");
assert.equal(await fold.getAttribute("aria-expanded"), "false", "folded at first");
assert.equal(await fold.getAttribute("title"), w("Show the servers turned off"));
const offList = v.locator(".lib-offlist");
assert(await offList.evaluate((l) => l.hidden), "folded, the ones off are hidden");
const listBottom = await v.locator(".lib-list:not(.lib-offlist)").first().evaluate((e) => e.getBoundingClientRect().bottom);
assert(await top(v.locator(".lib-offhead")) >= listBottom, "the fold is below the list");
assert(await top(v.locator(".lib-offhead")) < await top(v.locator(".after-list").first()), "the fold is above Add server");
assert.deepEqual(await sideways(page), [], "sideways scroll, folded");
// opened with the page scrolled to it by the wheel (a scroll by
// code is put back on the click, as not the reader's), the head
// stays where it is
await page.mouse.move(width / 2, 300);
for (let i = 0; i < 12 && await top(fold) > 420; i++) {
await page.mouse.wheel(0, 120);
await page.waitForTimeout(120);
}
await page.waitForTimeout(300);
const scrolled = await v.evaluate((x) => x.scrollTop);
const was = await top(fold);
await fold.click();
await page.waitForFunction(() => document.querySelector("#view-library .lib-offhead .fold")?.getAttribute("aria-expanded") === "true");
assert.deepEqual(await names(page, ".lib-offlist"), ["bravo", "echo", "golf"]);
assert(await offList.isVisible());
assert.equal(await fold.getAttribute("title"), w("Fold the servers turned off away"));
{ const now = await top(fold); assert(Math.abs(now - was) <= 1, `opening moved the head: ${was} → ${now}, scrollTop ${scrolled} → ${await v.evaluate((x) => x.scrollTop)}, window ${await page.evaluate(() => window.scrollY)}`); }
assert(Math.abs(await v.evaluate((x) => x.scrollTop) - scrolled) <= 1, "opening scrolled the page");
assert.equal(await page.locator("#modal").evaluate((m) => !m.hidden && m.getBoundingClientRect().height > 0).catch(() => false), false, "the fold opened the editor");
assert.deepEqual(await sideways(page), [], "sideways scroll, open");
// remembered across a reload
await page.reload();
await page.locator('button[data-view="library"]').click();
await v.locator('.lib-server[data-server="alpha"]').waitFor();
assert.equal(await v.locator(".lib-offhead .fold").getAttribute("aria-expanded"), "true", "the fold is remembered");
assert.deepEqual(await names(page, ".lib-offlist"), ["bravo", "echo", "golf"]);
// a server switched off moves under it, one switched on comes back up
await v.locator('.lib-list:not(.lib-offlist) > .lib-server[data-server="delta"] > .lib-switch').click();
await page.waitForFunction(() => document.querySelector('#view-library .lib-offlist > .lib-server[data-server="delta"]'));
assert.equal((await v.locator(".lib-offhead .note").textContent()).trim(), "4");
await v.locator('.lib-offlist > .lib-server[data-server="echo"] > .lib-switch').click();
await page.waitForFunction(() => document.querySelector('#view-library .lib-list:not(.lib-offlist) > .lib-server[data-server="echo"]'));
assert.deepEqual(await names(page, ".lib-offlist"), ["bravo", "delta", "golf"]);
// folded, picking opens it, and it can't be folded while picking
await v.locator(".lib-offhead .fold").click();
await page.waitForFunction(() => document.querySelector("#view-library .lib-offlist")?.hidden);
await v.locator(".lib-serverhead .lib-select").click();
await v.locator(".lib-pickbar").waitFor();
assert.equal(await v.locator(".lib-offhead .fold").getAttribute("aria-expanded"), "true");
assert(await v.locator(".lib-offhead .fold").isDisabled(), "the fold folds while picking");
assert(await v.locator(".lib-offlist").isVisible(), "a server off is out of sight while picking");
assert.equal(await v.locator(".lib-offlist .lib-pickbox, .lib-offlist input[type=checkbox]").count() > 0, true, "a server off can't be picked");
await v.locator(".lib-pickdone").click();
await page.waitForFunction(() => document.querySelector("#view-library .lib-offlist")?.hidden);
// every one off: the fold is all there is
for (const n of NAMES) st.off.add(n);
await page.reload();
await page.locator('button[data-view="library"]').click();
await v.locator(".lib-offhead .fold").waitFor();
assert.equal((await v.locator(".lib-offhead .note").textContent()).trim(), String(NAMES.length));
assert(await v.locator(".lib-list:not(.lib-offlist)").first().evaluate((l) => l.hidden), "an empty list shows");
// and none off: no fold
st.off.clear();
await page.reload();
await page.locator('button[data-view="library"]').click();
await v.locator('.lib-server[data-server="alpha"]').waitFor();
assert(await v.locator(".lib-offhead").evaluate((h) => h.hidden), "a fold over nothing");
assert.deepEqual(errors, []);
await ctx.close();
});
}
});
}
+6 -1
View File
@@ -2,7 +2,8 @@
// swang20201 on X (v0.1.3375, Docker gateway mode): an installed MCP server
// in Library could only be removed. Each server row has a switch: off
// posts servers/on {on:false}, says the settings are kept, and the row
// shows dimmed with its agent chips out of reach; on posts {on:true} and
// shows dimmed with its agent chips out of reach, under the fold of the
// ones turned off; on posts {on:true} and
// the row is as it was. The switch doesn't open the editor. In the app
// with an agent at 1100px and a browser in gateway mode at 420px, every
// language, both engines: no sideways scroll, no native select.
@@ -121,6 +122,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction((x) => document.querySelector("#status")?.textContent === x, w("{name} is off; its settings are kept", { name: "notes" }));
assert.deepEqual(st.sent, [{ name: "notes", on: false }]);
await page.waitForFunction(() => document.querySelector('#view-library .lib-server[data-server="notes"]')?.classList.contains("off"));
// turned off, it is under the fold below the ones on, folded at first
// (library-mcp-off-fold): opened to see it
assert.equal(await v.locator(".lib-offhead .fold").getAttribute("aria-expanded"), "false");
await v.locator(".lib-offhead .fold").click();
const offRow = v.locator('.lib-server[data-server="notes"]');
assert.equal(await offRow.locator(":scope > .lib-switch").getAttribute("aria-checked"), "false");
assert.equal(await page.locator("#modal").evaluate((m) => !m.hidden && m.getBoundingClientRect().height > 0).catch(() => false), false, `${where}: the switch opened the editor`);