From cb64570f13d1255efaf6b1f2ab940178318f5279 Mon Sep 17 00:00:00 2001 From: "Dr. Dominik Jain" Date: Thu, 24 Sep 2026 12:52:02 +0200 Subject: [PATCH] :bug: Fix text response construction from base64 data (#11422) Fixes SVG exports of shapes, as the export util method always produces a byte array, even for text data. --- mcp/packages/server/src/ToolResponse.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mcp/packages/server/src/ToolResponse.ts b/mcp/packages/server/src/ToolResponse.ts index db5babe4db..305fe6b5ff 100644 --- a/mcp/packages/server/src/ToolResponse.ts +++ b/mcp/packages/server/src/ToolResponse.ts @@ -10,12 +10,19 @@ export class TextContent implements TextItem { constructor(public text: string) {} /** - * @param data - Text data as string or as object (from JSON representation where indices are mapped to character codes) + * @param data - Text data as string or as object (wrapped base64 data or JSON representation of array where + * indices are mapped to character codes) */ public static textData(data: string | object): string { if (typeof data === "object") { - // convert object containing character codes (as obtained from JSON conversion of string) back to string - return String.fromCharCode(...(Object.values(data) as number[])); + // check for wrapped base64 data + if ("__type" in data && data["__type"] === "base64" && "data" in data && typeof data["data"] === "string") { + return Buffer.from(data["data"], "base64").toString("utf-8"); + } + // legacy fallback: assume object containing character codes (as obtained from direct JSON conversion) + else { + return String.fromCharCode(...(Object.values(data) as number[])); + } } else { return data; } @@ -84,8 +91,8 @@ export class TextResponse extends ToolResponse { } /** - * Creates a TextResponse from text data given as string or as object (from JSON representation where indices are mapped to - * character codes). + * Creates a TextResponse from text data given as string or as object (wrapped base64 data or JSON representation + * of array where indices are mapped to character codes). * * @param data - Text data as string or as object (from JSON representation where indices are mapped to character codes) */