Python
Legacy MCP notices collapse too: server name recovered from the persisted text
Rohit C Prasad2733eb84cac9
diff --git a/surfaces/gui/e2e/seeded-history.spec.ts b/surfaces/gui/e2e/seeded-history.spec.tsindex c04d97a1..9c9fb957 100644--- a/surfaces/gui/e2e/seeded-history.spec.ts+++ b/surfaces/gui/e2e/seeded-history.spec.ts@@ -127,3 +127,28 @@ test("a dead MCP server replays as one quiet line with Details and Open Connectoawait page.getByTestId("mcp-notice-connectors").click();await expect(page.getByText("Connectors", { exact: true }).first()).toBeVisible();});++test("a LEGACY mcp_error notice (pre-server-field) also collapses to the quiet line", async ({+ page,+}) => {+ // Old sessions persisted the full text + a plain "see Settings ▸ Connectors" pointer;+ // display-time parsing recovers the server name so old transcripts clean up too.+ await seedSessionMessages(page, "pinned-cowork-1", [+ { role: "user", content: "hi", ts: TS },+ {+ role: "notice",+ kind: "mcp_error",+ text: "MCP server “sales-db” failed to start: unhandled errors in a TaskGroup <function f at 0x102ab40f0> — see Settings ▸ Connectors",+ },+ ]);+ await page.goto("/");+ await page.getByText("Draft the launch note").first().click();++ const line = page.getByTestId("mcp-notice");+ await expect(line).toContainText("sales-db");+ await page.getByTestId("mcp-notice-details").click();+ const detail = page.getByTestId("mcp-notice-detail");+ await expect(detail).toContainText("TaskGroup");+ // The old plain-text pointer is dropped — the button replaces it.+ await expect(detail).not.toContainText("see Settings");+});diff --git a/surfaces/gui/src/itemsFromMessages.test.ts b/surfaces/gui/src/itemsFromMessages.test.tsindex 0c2b4680..524c18e9 100644--- a/surfaces/gui/src/itemsFromMessages.test.ts+++ b/surfaces/gui/src/itemsFromMessages.test.ts@@ -110,7 +110,9 @@ describe("itemsFromMessages reasoning", () => {});describe("itemsFromMessages mcp failure", () => {- it("replays the persisted mcp_error marker as a warn notice WITHOUT retry", () => {+ it("replays the persisted mcp_error marker as a collapsed notice WITHOUT retry", () => {+ // Legacy format (no `server` field): the name is recovered from the text and the+ // old plain-text Settings pointer is dropped — the Open Connectors button owns it.const items = itemsFromMessages([{ role: "user", content: "hi" },{ role: "notice", kind: "mcp_error", text: "MCP server “sales-db” failed to start — see Settings ▸ Connectors" },@@ -118,7 +120,16 @@ describe("itemsFromMessages mcp failure", () => {expect(items[1]).toEqual({kind: "notice",tone: "warn",- text: "MCP server “sales-db” failed to start — see Settings ▸ Connectors",+ text: "MCP server “sales-db” didn’t start — its tools are unavailable here",+ server: "sales-db",+ detail: "MCP server “sales-db” failed to start",});});++ it("keeps an unparseable mcp_error text as a plain warn notice", () => {+ const items = itemsFromMessages([+ { role: "notice", kind: "mcp_error", text: "something opaque went wrong" },+ ] as any);+ expect(items[0]).toEqual({ kind: "notice", tone: "warn", text: "something opaque went wrong" });+ });});diff --git a/surfaces/gui/src/itemsFromMessages.ts b/surfaces/gui/src/itemsFromMessages.tsindex cc88bf96..8d7e68bd 100644--- a/surfaces/gui/src/itemsFromMessages.ts+++ b/surfaces/gui/src/itemsFromMessages.ts@@ -81,17 +81,10 @@ export function itemsFromMessages(messages: ConversationMessage[]): Item[] {: m.kind === "mcp_error"? // A configured MCP server failed to start for this session — informational,// NOT retriable (retry re-runs the model turn, which can't fix a dead server).- // With a `server` field it renders as one quiet line + disclosure; legacy- // notices (no field) keep showing their full text.- m.server- ? {- kind: "notice",- tone: "warn",- text: `MCP server “${m.server}” didn’t start — its tools are unavailable here`,- server: String(m.server),- detail: m.text || undefined,- }- : { kind: "notice", tone: "warn", text: m.text || "An MCP server failed to start" }+ // Renders as one quiet line + disclosure. Legacy notices (persisted before+ // the `server` field existed) recover the name from their own text, so old+ // transcripts collapse too instead of keeping the wall of stderr.+ mcpNoticeItem(m): { kind: "notice", tone: "warn", text: "Error: " + (m.text || "unknown"), retriable: true },);}@@ -100,6 +93,23 @@ export function itemsFromMessages(messages: ConversationMessage[]): Item[] {return items;}+function mcpNoticeItem(m: ConversationMessage): Item {+ const text = typeof m.text === "string" ? m.text : "";+ const server =+ (m.server && String(m.server)) || (text.match(/MCP server [“"]([^”"]+)[”"]/) || [])[1];+ if (!server)+ return { kind: "notice", tone: "warn", text: text || "An MCP server failed to start" };+ // The old format appended a plain-text Settings pointer — the button replaces it.+ const detail = text.replace(/\s*—\s*see Settings ▸ Connectors\s*$/u, "");+ return {+ kind: "notice",+ tone: "warn",+ text: `MCP server “${server}” didn’t start — its tools are unavailable here`,+ server,+ detail: detail || undefined,+ };+}+export function userItemFromContent(content: any): Extract<Item, { kind: "user" }> {if (typeof content === "string") return { kind: "user", text: content };if (!Array.isArray(content)) return { kind: "user", text: "" };