From 33dd6e1899e5efea5caa08f51602f0b86b69eae4 Mon Sep 17 00:00:00 2001 From: Ayush7614 Date: Fri, 4 Sep 2026 14:14:03 +0530 Subject: [PATCH] fix(mcp): name null parts instead of throwing in resultText --- server/src/plugins/mcp.ts | 1 + server/tests/mcp-result.test.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/server/src/plugins/mcp.ts b/server/src/plugins/mcp.ts index eba34a060..23e5599d7 100644 --- a/server/src/plugins/mcp.ts +++ b/server/src/plugins/mcp.ts @@ -49,6 +49,7 @@ export function resultText(content: unknown): { const parts = Array.isArray(content) ? content : []; const joined = parts .map((part) => { + if (!part || typeof part !== "object") return "[unknown]"; const item = part as { type?: string; text?: string }; if (item.type === "text" && typeof item.text === "string") { return item.text; diff --git a/server/tests/mcp-result.test.ts b/server/tests/mcp-result.test.ts index 8388c8bbe..4f0a83aa6 100644 --- a/server/tests/mcp-result.test.ts +++ b/server/tests/mcp-result.test.ts @@ -63,6 +63,13 @@ describe("a result with something in it", () => { expect(resultText([{}]).text).toBe("[unknown]"); }); + test("names a null or non-object part rather than throwing", () => { + // Content arrives from a vendor's server; a null entry must not throw. + expect(resultText([null]).text).toBe("[unknown]"); + expect(resultText([undefined]).text).toBe("[unknown]"); + expect(resultText([42]).text).toBe("[unknown]"); + }); + test("a part that is only whitespace still counts as something being there", () => { // One blank part beside a real one must not make the whole result look empty. expect(