Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
library: a click on an MCP server's needs-sign-in status signs in
yetonef49cebb35b7a
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.jsindex a0eb4cc74..29134d441 100644--- a/internal/gui/assets/i18n.js+++ b/internal/gui/assets/i18n.js@@ -2120,6 +2120,8 @@ const I18N = {"checking…": "检查中…","Connecting to it to list its tools": "正在连接并列出它的工具","Click to check again": "点击重新检查",+ "Click to sign in": "点击登录",+ "Click to see the sign-in": "点击查看登录","not checked": "未检查","No agent has it, so it isn't checked on its own": "没有 agent 在用它,所以不会自动检查","No agent shown here has it on, so it isn't checked on its own": "这里显示的 agent 都没有开着它,所以不会自动检查",@@ -6227,6 +6229,8 @@ const I18N = {"checking…": "檢查中…","Connecting to it to list its tools": "正在連線並列出它的工具","Click to check again": "點選重新檢查",+ "Click to sign in": "點選登入",+ "Click to see the sign-in": "點選查看登入","not checked": "未檢查","No agent has it, so it isn't checked on its own": "沒有 agent 在用它,所以不會自動檢查","No agent shown here has it on, so it isn't checked on its own": "這裡顯示的 agent 都沒有開著它,所以不會自動檢查",@@ -10311,6 +10315,8 @@ const I18N = {"checking…": "確認中…","Connecting to it to list its tools": "接続してツールを一覧表示しています","Click to check again": "クリックして再確認",+ "Click to sign in": "クリックしてサインイン",+ "Click to see the sign-in": "クリックしてサインインを表示","not checked": "未確認","No agent has it, so it isn't checked on its own": "どのエージェントも使っていないため、自動では確認しません","No agent shown here has it on, so it isn't checked on its own": "ここに表示されているエージェントはどれも使っていないため、自動では確認しません",@@ -14425,6 +14431,8 @@ const I18N = {"checking…": "wird geprüft…","Connecting to it to list its tools": "Verbindung wird hergestellt, um die Tools aufzulisten","Click to check again": "Zum erneuten Prüfen klicken",+ "Click to sign in": "Zum Anmelden klicken",+ "Click to see the sign-in": "Zum Anzeigen der Anmeldung klicken","not checked": "nicht geprüft","No agent has it, so it isn't checked on its own": "Kein Agent nutzt ihn, daher wird er nicht von selbst geprüft","No agent shown here has it on, so it isn't checked on its own": "Kein hier angezeigter Agent nutzt ihn, daher wird er nicht von selbst geprüft",diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.jsindex d86967dcd..b212cacb9 100644--- a/internal/gui/assets/plugins/library/client.js+++ b/internal/gui/assets/plugins/library/client.js@@ -2066,6 +2066,11 @@ magpie.plugin("library", (ctx) => {b.dataset.server = name;b.onclick = (e) => {e.stopPropagation(); // the row opens the editor+ // a server that asks for a sign-in is signed in to from its status+ // (the owner: a click on "needs sign-in" signs in)+ const s = lib.servers.find((x) => x.name === name);+ if (mcpSigning?.name === name && mcpSigning.id) return editServer(s); // under way: its dialog has Cancel+ if (canSignIn(s)) return signInFromRow(s);if (!toolList(name).length) return recheck(name);if (toolsOpen.has(name)) toolsOpen.delete(name); else toolsOpen.add(name);paintHealth(name);@@ -2248,6 +2253,13 @@ magpie.plugin("library", (ctx) => {continue;}b.hidden = false;+ const sg = mcpSigning?.name === b.dataset.server ? mcpSigning : null;+ if (sg && (sg.state === "starting" || sg.state === "waiting")) {+ b.className = "lib-health auth";+ b.replaceChildren(el("span", "", sg.state === "starting" ? t("Opening the sign-in…") : t("Finish signing in in your browser…")));+ b.title = t("Click to see the sign-in");+ continue;+ }if (!e.h) {b.className = "lib-health checking";b.replaceChildren(el("span", "", t("checking…")));@@ -2274,7 +2286,7 @@ magpie.plugin("library", (ctx) => {b.classList.add("has-list");b.setAttribute("aria-expanded", String(open));b.title = tip + "\n" + (open ? t("Click to hide them") : t("Click to see them"));- } else b.title = tip + "\n" + t("Click to check again");+ } else b.title = tip + "\n" + (canSignIn(lib.servers.find((s) => s.name === b.dataset.server)) ? t("Click to sign in") : t("Click to check again"));}const name = typeof x === "string" ? x : x.dataset.server;for (const box of page.querySelectorAll(`.lib-tools[data-server="${CSS.escape(name)}"]`)) paintTools(box);@@ -2283,6 +2295,58 @@ magpie.plugin("library", (ctx) => {// magpie's sign-in to a remote server (#615): signed in once here, and// every agent given the server reaches it through magpie, with itlet mcpSigning = null; // { name, id, state, error } while one is under way+ let signDraw = null; // the open dialog's sign-in box, drawn as a sign-in moves+ function signMoved(name) {+ if (signDraw && !signDraw.box.isConnected) signDraw = null;+ signDraw?.draw();+ if (name) paintHealth(name);+ }+ // one the row's status signs in to: a remote server that asked for a+ // sign-in, unless an agent's own sign-in already uses it+ function canSignIn(s) {+ const h = s && health.get(s.name)?.h;+ return !!h && s.transport === "http" && h.state === "auth" && !!h.oauth && !h.agentSignIn?.length;+ }+ // a sign-in from a row's status, as the dialog's Sign in starts one; the+ // dialog opens when the user has something to do there: the browser+ // didn't open (the link to open by hand) or the sign-in failed+ async function signInFromRow(s) {+ const name = s.name;+ mcpSigning = { name, state: "starting" };+ signMoved(name);+ try {+ const st = await api("library/mcp-signin", { name });+ if (mcpSigning?.name !== name || mcpSigning.id) return; // canceled+ if (web && st.url) api("open", { url: st.url }).catch(() => {});+ mcpSigning = { ...st, name };+ signMoved(name);+ if (st.openError) editServer(s);+ followSignIn(st.id, name);+ } catch (e) {+ if (mcpSigning?.name !== name) return;+ mcpSigning = { name, state: "failed", error: t(e.message) };+ signMoved(name);+ editServer(s);+ }+ }+ // followed with the dialog closed too, for the row to say it's signed in+ async function followSignIn(id, name) {+ while (mcpSigning?.id === id) {+ await new Promise((r) => setTimeout(r, 800));+ let st;+ try { st = await api("library/mcp-signin/" + id); } catch { continue; }+ if (mcpSigning?.id !== id) return;+ if (st.state === "waiting") continue;+ if (st.state === "done") {+ mcpSigning = null;+ await api("library").then(take, () => {});+ status(t("Signed in to {name} — the agents given it use magpie's sign-in", { name }), "ok");+ render();+ } else mcpSigning = st.state === "canceled" ? null : { ...st, name };+ signMoved(name);+ return;+ }+ }// name is the server as saved ("" for one being added); ready saves what// the editor shows when it isn't that (a URL changed to the one that// signs in, as Exa's ?login) and gives the name it's saved as, for the@@ -2302,6 +2366,7 @@ magpie.plugin("library", (ctx) => {if (sg.id) await api("library/mcp-signin/" + sg.id + "/cancel", {}).catch(() => {});mcpSigning = null;draw();+ signMoved(name);}));} else if (cur.signedIn && !cur.dead) {line.append(tag(t("Signed in"), "lib-signed"), el("span", "note", t("The agents given it use magpie's sign-in")), el("span", "grow"), button(t("Sign out"), "", signOut));@@ -2340,7 +2405,7 @@ magpie.plugin("library", (ctx) => {if (web && st.url) api("open", { url: st.url }).catch(() => {});mcpSigning = { ...st, name };draw();- follow(st.id);+ followSignIn(st.id, name);} catch (e) {if (!mcpSigning) return; // canceled// magpie's words in the reader's language, where it has them@@ -2349,24 +2414,6 @@ magpie.plugin("library", (ctx) => {ready?.failed?.(e.message);}}- // followed with the dialog closed too, for the row to say it's signed in- async function follow(id) {- while (mcpSigning?.id === id) {- await new Promise((r) => setTimeout(r, 800));- let st;- try { st = await api("library/mcp-signin/" + id); } catch { continue; }- if (mcpSigning?.id !== id) return;- if (st.state === "waiting") continue;- if (st.state === "done") {- mcpSigning = null;- await api("library").then(take, () => {});- status(t("Signed in to {name} — the agents given it use magpie's sign-in", { name }), "ok");- render();- } else mcpSigning = st.state === "canceled" ? null : { ...st, name };- draw();- return;- }- }async function signOut() {try {take(await api("library/mcp-signout", { name }));@@ -2376,6 +2423,7 @@ magpie.plugin("library", (ctx) => {} catch (e) { status(e.message, "err", 6000); }}box.redraw = draw;+ signDraw = { box, draw };draw();return box;}diff --git a/internal/gui/tests/library-mcp-health.test.cjs b/internal/gui/tests/library-mcp-health.test.cjsindex 633e03301..4bd9eb1fe 100644--- a/internal/gui/tests/library-mcp-health.test.cjs+++ b/internal/gui/tests/library-mcp-health.test.cjs@@ -79,7 +79,7 @@ const words = {fetch: ["can't start: uvx not found", "Can't start it: there is no uvx on the PATH magpie has"],github: ["exited (1)", "It exited with code 1 before listing its tools\nError: GITHUB_PERSONAL_ACCESS_TOKEN is not set"],slow: ["no answer to tools/list", "No answer to tools/list in 60 seconds"],- again: "Click to check again", fresh: "13 tools", skills: "Skills",+ again: "Click to check again", signin: "Click to sign in", fresh: "13 tools", skills: "Skills",idle: ["not checked", "No agent has it, so it isn't checked on its own\nClick to check it"], idleOk: "2 tools",},zh: {@@ -89,7 +89,7 @@ const words = {fetch: ["无法启动:找不到 uvx", "无法启动:magpie 的 PATH 里没有 uvx"],github: ["已退出(1)", "列出工具前就退出了,退出码 1\nError: GITHUB_PERSONAL_ACCESS_TOKEN is not set"],slow: ["tools/list 无响应", "等了 60 秒,tools/list 仍没有响应"],- again: "点击重新检查", fresh: "13 个工具", skills: "技能",+ again: "点击重新检查", signin: "点击登录", fresh: "13 个工具", skills: "技能",idle: ["未检查", "没有 agent 在用它,所以不会自动检查\n点击检查"], idleOk: "2 个工具",},};@@ -138,7 +138,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",const cls = { files: "ok", linear: "auth", fetch: "err", github: "err", slow: "err" };for (const [n, [text, tip]] of Object.entries(w).filter(([k]) => k in found && k !== "idle")) {assert.equal(await status(n).textContent(), text, n);- assert.equal(await status(n).getAttribute("title"), tip + "\n" + w.again, n);+ // one asking for a sign-in is signed in to with a click+ assert.equal(await status(n).getAttribute("title"), tip + "\n" + (n === "linear" ? w.signin : w.again), n);assert.equal(await status(n).evaluate((b, c) => b.classList.contains(c), cls[n]), true, n);// a dot, not a coloured stripeassert.equal(await status(n).evaluate((b) => getComputedStyle(b).borderLeftWidth), "0px");diff --git a/internal/gui/tests/mcp-signin-click.test.cjs b/internal/gui/tests/mcp-signin-click.test.cjsnew file mode 100644index 000000000..d79f29aaf--- /dev/null+++ b/internal/gui/tests/mcp-signin-click.test.cjs@@ -0,0 +1,141 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// The owner, on the Library's MCP tab: a click on a server's "needs+// sign-in" signs in to it, as the dialog's Sign in does, not a check+// again. The status says the sign-in is under way and then lists the+// tools; no dialog opens unless there's something to do in it (the+// browser didn't open, so the link to open by hand). A server that+// refused magpie with no sign-in to offer (a key missing from its+// headers) is checked again, as before. Every language, Chromium and+// WebKit, 1100 and 390 wide. 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 assets = path.resolve(__dirname, "../assets");+const { I18N } = require("./strings.cjs").strings(); // i18n.js's and the plugins'+const tr = (lang, s, vars = {}) => ((lang === "en" ? s : I18N[lang][s]) || s).replace(/\{(\w+)\}/g, (_, k) => vars[k]);+const HOME = "/Users/xv";+const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });++function server(lang, calls, gate) {+ const lib = {+ dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,+ agents: [agent("claude", "Claude Code")],+ instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [],+ servers: [+ { name: "linear", transport: "http", url: "https://mcp.linear.app/mcp", agents: ["claude"], signIn: { signedIn: false } },+ // its browser doesn't open: the dialog shows the link+ { name: "notion", transport: "http", url: "https://mcp.notion.com/mcp", agents: ["claude"], signIn: { signedIn: false } },+ // refused without a sign-in to offer: a key in its headers+ { name: "keyed", transport: "http", url: "https://mcp.example.com/mcp", agents: ["claude"], signIn: { signedIn: false } },+ ],+ };+ return async (route) => {+ const req = route.request(), url = new URL(req.url());+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });+ if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });+ if (url.pathname === "/api/library") return route.fulfill({ json: lib });+ if (url.pathname === "/api/library/mcp/check") {+ const names = req.postDataJSON().names;+ calls.push("check " + names.join(","));+ const servers = {};+ for (const n of names) {+ const s = lib.servers.find((x) => x.name === n);+ if (n === "keyed") servers[n] = { state: "auth", code: 401 };+ else servers[n] = s.signIn.signedIn ? { state: "ok", tools: 7, signIn: s.signIn } : { state: "auth", code: 401, oauth: true, signIn: s.signIn };+ }+ return route.fulfill({ json: { servers } });+ }+ if (url.pathname === "/api/library/mcp-signin") {+ const name = req.postDataJSON().name;+ calls.push("start " + name);+ const st = { id: "s-" + name, server: name, state: "waiting", url: "https://example.com/authorize?n=" + name };+ if (name === "notion") st.openError = "no browser";+ return route.fulfill({ json: st });+ }+ if (url.pathname.startsWith("/api/library/mcp-signin/s-")) {+ const name = url.pathname.slice("/api/library/mcp-signin/s-".length);+ if (url.pathname.endsWith("/cancel")) { calls.push("cancel " + name.replace(/\/cancel$/, "")); return route.fulfill({ json: {} }); }+ if (!gate.done) return route.fulfill({ json: { id: "s-" + name, server: name, state: "waiting" } });+ lib.servers.find((x) => x.name === name).signIn = { signedIn: true, at: 2 };+ return route.fulfill({ json: { id: "s-" + name, server: name, state: "done" } });+ }+ if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });+ if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });+ if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });+ if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });+ 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)];+ await route.fulfill({ body: await fs.readFile(file), contentType });+ };+}++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(engine + ": a click on needs sign-in signs in", async (t) => {+ assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));+ const errors = [];+ t.after(async () => {+ if (errors.length) console.log(errors);+ await browser.close();+ });+ for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {+ for (const width of [1100, 390]) {+ await t.test(`${lang} ${width}`, async () => {+ const w = (s, v) => tr(lang, s, v);+ const calls = [], gate = { done: false };+ const ctx = await browser.newContext({ viewport: { width, height: 800 } });+ await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "mcp"); } catch {} });+ const page = await ctx.newPage();+ page.setDefaultTimeout(5000);+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", server(lang, calls, gate));+ await page.goto("http://magpie.test/");+ await page.locator('button[data-view="library"]').click();+ const row = (name) => page.locator("#view-library .lib-server", { has: page.locator(`.lib-health[data-server="${name}"]`) });+ const status = (name) => page.locator(`#view-library .lib-health[data-server="${name}"]`);+ for (const n of ["linear", "notion", "keyed"]) await status(n).locator("span", { hasText: w("needs sign-in") }).waitFor();+ assert.match(await status("linear").getAttribute("title"), new RegExp(w("Click to sign in")));++ // linear: the sign-in starts from the status, with no dialog+ await status("linear").click();+ await status("linear").locator("span", { hasText: w("Finish signing in in your browser…") }).waitFor();+ assert.equal(await page.locator("#modal .lib-editor").count(), 0, "no dialog for a sign-in the browser took");+ assert.deepEqual(calls.filter((c) => c.startsWith("start")), ["start linear"]);+ gate.done = true;+ await status("linear").locator("span", { hasText: w("{n} tools", { n: 7 }) }).waitFor();+ await row("linear").locator(".name .lib-tag", { hasText: w("Signed in") }).waitFor();+ assert.equal(calls.filter((c) => c === "start linear").length, 1);++ // notion: the browser didn't open, so the dialog shows the link+ gate.done = false;+ await status("notion").click();+ const box = page.locator("#modal .lib-signin");+ await box.locator(".lib-signin-link code", { hasText: "n=notion" }).waitFor();+ await box.getByRole("button", { name: w("Cancel"), exact: true }).click();+ await box.getByRole("button", { name: w("Sign in"), exact: true }).waitFor();+ assert(calls.includes("cancel notion"), calls.join("; "));+ await page.keyboard.press("Escape");+ await page.locator("#modal .lib-editor").waitFor({ state: "detached" });+ await status("notion").locator("span", { hasText: w("needs sign-in") }).waitFor();++ // keyed: nothing to sign in to, so a click checks it again+ await status("keyed").click();+ // the check asked again, then answered as before+ for (let i = 0; i < 100 && !calls.includes("check keyed"); i++) await page.waitForTimeout(50);+ assert(calls.includes("check keyed"), calls.join("; "));+ await status("keyed").locator("span", { hasText: w("needs sign-in") }).waitFor();+ assert(!calls.includes("start keyed"), calls.join("; "));+ assert.equal(await page.locator("#modal .lib-editor").count(), 0);+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "no sideways scroll");+ await ctx.close();+ });+ }+ }+ assert.deepEqual(errors, []);+ });+}