A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 删除 MCP Server 被拒时,确认框留着,原因也留在框里(7.26)
lmliheng93971963c3b0
diff --git a/changelog/unreleased/2026-10-22-mcp-delete-refusal.md b/changelog/unreleased/2026-10-22-mcp-delete-refusal.mdnew file mode 100644index 00000000..4d7d9e98--- /dev/null+++ b/changelog/unreleased/2026-10-22-mcp-delete-refusal.md@@ -0,0 +1,37 @@+# A refused MCP Server removal keeps its confirmation and the reason in it++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-10-22-mcp-delete-refusal.zh.md)++The Tools tab's MCP Server table asks before it removes a row, and that card used to close as soon as the+request returned — whether or not the write landed. When the write was refused, the list was exactly as it+was, on the page and on the server ("remove one row" is that whole list PUT back without it), yet the reason+arrived as a toast: six seconds, floating above the card, and the retry meant finding the row again.++The card now closes only after the write landed: a refusal draws the server's words under the card's sentence,+so the retry is the same button, and the one write that succeeded closes it and drops the sentence. Opening the+card from a row's Remove button clears the previous reason first.++## Details++- The rule follows the model library, scheduled tasks, evaluation center, plugin market, conversation deletion+ and plugin settings rounds (`ConfirmModal`'s `refusal` slot): the reason is drawn inside the card that asked,+ not in a toast that dismisses itself and sits above it.+- `features/agents/mcp-servers-section.tsx`: `confirmDelete` only calls `setDeleting(null)` when `persist`+ came back clean; otherwise the message goes to a new `deleteRefusal` state that the confirmation draws+ (`S.common.refused(...)`). The card already carries `busy` while the write is in flight, so neither button+ can be pressed twice.+- New browser spec `e2e/mcp-delete-refusal.spec.mjs` (two tests): a refused removal keeps the card, its+ sentence and the row, raises no toast, and reopening it does not carry the old reason over; confirming again+ with the write allowed closes the card, removes the row, and the server's list no longer holds it.++## Compatibility++- No API, wire-format, stored-data or dependency change: this is only when the card closes and where the reason+ is drawn.+- The add / edit dialog in the same block already keeps the server's 400 inside itself (`modalError`), and the+ on/off switch has no card to keep; neither changed.diff --git a/changelog/unreleased/2026-10-22-mcp-delete-refusal.zh.md b/changelog/unreleased/2026-10-22-mcp-delete-refusal.zh.mdnew file mode 100644index 00000000..96fbf548--- /dev/null+++ b/changelog/unreleased/2026-10-22-mcp-delete-refusal.zh.md@@ -0,0 +1,30 @@+# 删除 MCP Server 被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-22-mcp-delete-refusal.md)++智能体设置「工具」页的 MCP Server 表里,删除一行要先确认,而那张卡片过去在请求返回时就关掉 —— 不管写没写+成功。被拒的时候列表在页面上与服务器上都一点没变(「删除一行」就是把整张表去掉这一行再 PUT 回去),可原因+却是一条 toast:六秒,浮在卡片上方,而重试要自己再去把那一行找回来。++现在卡片在**写成功之后**才关:被拒的写入把服务端的原话画在句子下面,重试就是同一个按钮;写成功的那一次才关+框并清掉那句话。从行上的「删除」打开卡片时先清掉上一次的原因。++## 细节++- 规则沿用模型库、定时任务、评估中心、插件市场、删除对话与插件设置那几轮(`ConfirmModal` 的 `refusal` 槽):+ 原因画在发起它的那张卡片里,而不是一条会自己消失、还浮在框上方的 toast。+- `features/agents/mcp-servers-section.tsx`:`confirmDelete` 只在 `persist` 回真时 `setDeleting(null)`;+ 被拒时把原话交给新的 `deleteRefusal` 状态,由确认框画出来(`S.common.refused(...)`)。写入在飞时确认框+ 本来就标着 `busy`,所以两个按钮不会被连点。+- 新增浏览器用例 `e2e/mcp-delete-refusal.spec.mjs`(两条):被拒的删除留着卡片、句子与那一行,不弹 toast,+ 重新打开时不带旧原因;被拒之后再确认一次、这次放行 —— 卡片关掉、行消失、服务器那份列表里也没有它。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」与「原因画在哪」。+- 同一个区块里新增 / 编辑的对话框本来就自己留着服务端的 400(`modalError`)、开关那条没有框可留,两者都没动。diff --git a/packages/web/e2e/mcp-delete-refusal.spec.mjs b/packages/web/e2e/mcp-delete-refusal.spec.mjsnew file mode 100644index 00000000..1aec1903--- /dev/null+++ b/packages/web/e2e/mcp-delete-refusal.spec.mjs@@ -0,0 +1,173 @@+/**+ * Regression: removing an MCP Server asks first, and a refused removal keeps that question —+ * with the server's words inside it — instead of closing on the way out of the request.+ *+ * The Tools tab's MCP block persists the whole list through one PUT, so "delete one row" is+ * that PUT without the row. The confirmation used to close unconditionally after the write+ * returned: when the write was refused, the list was exactly as it was — on the page and on+ * the server — yet the reason arrived as a toast that dismissed itself after six seconds and+ * sat above the card. The card now closes only once the write landed, and a refusal leaves it+ * open with the reason drawn under its sentence (`ConfirmModal`'s `refusal` slot), so the retry+ * is the same button.+ *+ * The row is seeded through the API (a valid http entry, nothing is connected until a Session+ * starts), and the refused write is the page's own PUT as seen by `page.route` — both halves+ * are the page's contract with the server.+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const P = "password123";+const AGENT = "default_agent";++/** The row under test (its name also scopes the server-side check). */+const NAME = "probe-mcp";++/** The refused save: a 500 with its own words proves the reason came back to the card. */+const REFUSAL = { code: "agent_config_read_only", message: "agent config is read-only" };++/**+ * Provision the user, give the Project a model (the onboarding overlay covers the page without+ * one), and put one MCP server on the Agent. The `PUT` replaces the whole list, so a rerun of+ * this file alone shares one data root with earlier runs without accumulating probe rows.+ */+async function projectWithServer(page, user) {+ await provisionAndLogin(page.request, user, P);+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]+ .projectId;+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(models.ok(), "put models").toBeTruthy();++ const seeded = await putServers(page, projectId, [+ { name: NAME, config: { url: "https://example.com/mcp" } },+ ]);+ expect(seeded.ok(), "seed the MCP server").toBeTruthy();++ /** The Agent's list as the server holds it: what the page reads and writes back. */+ const listed = async () => serversOf(await readConfig(page, projectId));+ return { projectId, listed };+}++/** The config write the page makes for every MCP edit (whole list, vault-style). */+const putServers = (page, projectId, mcpServers) =>+ page.request.put(`${BASE}/api/projects/${projectId}/agents/${AGENT}/config`, {+ data: { config: { mcpServers } },+ });++const readConfig = async (page, projectId) =>+ (await page.request.get(`${BASE}/api/projects/${projectId}/agents/${AGENT}/config`)).json();++const serversOf = (config) => (config.config?.mcpServers ?? []).map((s) => s.name);++/**+ * Take over the config write: every PUT is kept in `seen`, and while `state.refuse` is set it+ * is answered with the server's refusal instead of reaching the real route.+ */+async function interceptConfigPut(page, state) {+ await page.route("**/api/projects/*/agents/*/config", async (route) => {+ if (route.request().method() !== "PUT") return route.fallback();+ state.seen.push(route.request().postDataJSON());+ if (!state.refuse) return route.fallback();+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });+}++/** The seeded row: the only place the page writes the probe's name. */+const row = (page) => page.getByRole("row", { name: new RegExp(NAME) });++/** The row's Remove button, then the shared confirmation (named by its own title). */+async function askRemove(page) {+ await row(page).getByRole("button", { name: "删除", exact: true }).click();+ const dialog = page.getByRole("dialog", { name: "删除 MCP Server" });+ await expect(dialog).toBeVisible();+ return dialog;+}++/** The card's own text with the refusal line dropped — the only thing a refusal may change. */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}++/** The notification region: a refusal must not be announced there (that is the old toast). */+const notifications = (page) => page.getByRole("region", { name: "通知" });++test("a refused removal keeps the card, its sentence and the row", async ({ page }) => {+ const { listed } = await projectWithServer(page, "r108refuse");+ const before = await listed();+ expect(before).toContain(NAME);++ const state = { seen: [], refuse: true };+ await interceptConfigPut(page, state);++ await page.goto(`/agents/${AGENT}?tab=tools`);+ await expect(row(page)).toBeVisible();+ const dialog = await askRemove(page);+ const sentence = await cardText(dialog);+ expect(sentence).toContain(NAME);++ await dialog.getByRole("button", { name: "确认" }).click();++ // The reason is in the card that asked, and it is not a toast: the notification region holds+ // no dismissible button, and the card reads exactly as it did before the attempt plus one line.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.seen).toHaveLength(1);+ await expect(dialog).toBeVisible();+ expect(await cardText(dialog)).toBe(sentence);++ // Nothing was removed anywhere: the row is still on the page and still in the server's list.+ await expect(row(page)).toBeVisible();+ expect(await listed()).toEqual(before);++ // Closing the card decides nothing, and opening it again does not carry the old reason over.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ const reopened = await askRemove(page);+ await expect(reopened.getByText(REFUSAL.message)).toHaveCount(0);+});++test("the retry after a refused removal writes it, and only a written one closes the card", async ({+ page,+}) => {+ const { listed } = await projectWithServer(page, "r108retry");++ const state = { seen: [], refuse: true };+ await interceptConfigPut(page, state);++ await page.goto(`/agents/${AGENT}?tab=tools`);+ await expect(row(page)).toBeVisible();+ const dialog = await askRemove(page);+ await dialog.getByRole("button", { name: "确认" }).click();+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(dialog).toBeVisible();+ expect(state.seen).toHaveLength(1);++ // The retry is the same card; this time the write lands: card gone, row gone, list without it.+ state.refuse = false;+ await dialog.getByRole("button", { name: "确认" }).click();+ await expect(dialog).toHaveCount(0);+ expect(state.seen).toHaveLength(2);+ // The write the card sent is the list without the row — not an empty list wholesale.+ expect(state.seen[1].config.mcpServers).toEqual([]);+ await expect(row(page)).toHaveCount(0);+ expect(await listed()).not.toContain(NAME);+});diff --git a/packages/web/src/features/agents/mcp-servers-section.tsx b/packages/web/src/features/agents/mcp-servers-section.tsxindex f51dd9fb..2f41f38b 100644--- a/packages/web/src/features/agents/mcp-servers-section.tsx+++ b/packages/web/src/features/agents/mcp-servers-section.tsx@@ -140,6 +140,9 @@ export function McpServersSection({// Server-side rejection (transport validation 400) rendered at the modal's foot.const [modalError, setModalError] = useState<string | null>(null);const [deleting, setDeleting] = useState<number | null>(null);+ // The words for a delete the server refused, drawn inside the confirmation that asked for it+ // (see confirmDelete): retrying is the next thing the person does, and the button is in there.+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);// Connectivity probe: runs the current form state through POST /config/mcp-test// (server-side connect + discovery, nothing saved); the result pops as a toast.const [testing, setTesting] = useState(false);@@ -315,11 +318,31 @@ export function McpServersSection({if (err !== null) toastError(err);};+ /**+ * The delete row's button: opens the confirmation without the previous attempt's reason —+ * that sentence belonged to the attempt before, not to the row this one is about.+ */+ const askDelete = (index: number) => {+ setDeleting(index);+ setDeleteRefusal(null);+ };++ /**+ * Deletes one row through the same whole-list PUT as every other edit here. The confirmation+ * closes on the answer, not on the request: a refused write leaves the list exactly as it was+ * (nothing was removed, on either side), so the card stays open with the server's words in it+ * and the same button retries. Closing it as the request left used to take the reason away —+ * it landed in a toast that dismisses itself after six seconds and sits above the card.+ */const confirmDelete = async () => {if (deleting === null) return;const err = await persist(servers.filter((_, i) => i !== deleting));- if (err !== null) toastError(err);+ if (err !== null) {+ setDeleteRefusal(err);+ return;+ }setDeleting(null);+ setDeleteRefusal(null);};if (!projectId) return null;@@ -408,7 +431,7 @@ export function McpServersSection({size="sm"variant="ghost"disabled={busy}- onClick={() => setDeleting(index)}+ onClick={() => askDelete(index)}>{S.agent.mcpRemove}</Button>@@ -633,6 +656,7 @@ export function McpServersSection({onConfirm={() => void confirmDelete()}confirmLabel={S.common.confirm}cancelLabel={S.common.cancel}+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}><p className="text-sm text-gray-600 dark:text-gray-300">{deleting !== null ? S.agent.mcpDeleteConfirm(servers[deleting]?.name ?? "") : ""}