The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(client-runtime): MCP app results with images reach the app instead of waiting forever (#31338)
Julius Marminge committed
Nov 14, 2026 at 20:46 UTC
e6344bebd8f28f4f58ead7cb409ae8c64f1cdfc2
2 files changed
+70
-3
packages/client-runtime/src/mcpApps/host.test.ts
+45
@@ -130,6 +130,51 @@ describe("makeMcpAppHost", () => {
130
expect(sent.find((m) => m.id === 2)?.result).toEqual({ content: [] });
131
});
132
133
+ it("delivers results whose stored image blocks lost their bytes, which the MCP Apps SDK rejects", async () => {
134
+ const { host, sent } = setup({
135
+ callTool: async () => ({
136
+ content: [
137
+ { type: "text", text: "rendered" },
138
+ { type: "image", mimeType: "image/png", sizeBytes: 300 },
139
+ { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" },
140
+ ],
141
+ structuredContent: { rendered: true },
142
+ }),
143
+ });
144
+ initialize(host);
145
+ host.setToolCall({
146
+ arguments: {},
147
+ result: {
148
+ content: [
149
+ { type: "text", text: "Chart ready" },
150
+ { type: "image", source: { type: "base64", media_type: "image/png", sizeBytes: 300 } },
151
+ { type: "text", text: "[Image: source: /tmp/chart.png]" },
152
+ ],
153
+ structuredContent: { chart: "sales" },
154
+ },
155
+ });
156
+ host.receive({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: "render" } });
157
+ await flush();
158
+
159
+ const notified = sent.find((m) => m.method === "ui/notifications/tool-result")?.params as {
160
+ content: ReadonlyArray<unknown>;
161
+ structuredContent: unknown;
162
+ };
163
+ expect(notified.structuredContent).toEqual({ chart: "sales" });
164
+ expect(notified.content).toContainEqual({ type: "text", text: "Chart ready" });
165
+ expect(notified.content).not.toContainEqual(expect.objectContaining({ type: "image" }));
166
+
167
+ const answered = sent.find((m) => m.id === 2)?.result as {
168
+ content: ReadonlyArray<unknown>;
169
+ structuredContent: unknown;
170
+ };
171
+ expect(answered.structuredContent).toEqual({ rendered: true });
172
+ expect(answered.content).toEqual([
173
+ { type: "text", text: "rendered" },
174
+ { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" },
175
+ ]);
176
+ });
177
+
178
it("sends a later result for a call that had none, without repeating its input", () => {
179
const { host, sent } = setup();
180
initialize(host);
packages/client-runtime/src/mcpApps/host.ts
+25
-3
@@ -131,13 +131,35 @@ function isId(value: unknown): value is JsonRpcId {
131
return typeof value === "string" || (typeof value === "number" && Number.isFinite(value));
132
}
133
134
+const MCP_CONTENT_BLOCK_STRING_FIELDS: ReadonlyMap<string, ReadonlyArray<string>> = new Map([
135
+ ["text", ["text"]],
136
+ ["image", ["data", "mimeType"]],
137
+ ["audio", ["data", "mimeType"]],
138
+ ["resource_link", ["uri", "name"]],
139
+]);
140
+
141
+function isMcpContentBlock(block: unknown): boolean {
142
+ if (!Predicate.isObject(block) || typeof block.type !== "string") return false;
143
+ if (block.type === "resource") {
144
+ const resource = block.resource;
145
+ return (
146
+ Predicate.isObject(resource) &&
147
+ typeof resource.uri === "string" &&
148
+ (typeof resource.text === "string" || typeof resource.blob === "string")
149
+ );
150
+ }
151
+ const fields = MCP_CONTENT_BLOCK_STRING_FIELDS.get(block.type);
152
+ return fields !== undefined && fields.every((field) => typeof block[field] === "string");
153
+}
154
+
155
/**
135
- * Providers can report absent fields as null (Codex sends `_meta: null`), which
136
- * the MCP Apps SDK rejects, dropping the whole notification or response.
156
+ * The MCP Apps SDK rejects the whole notification or response over one field it
157
+ * does not accept: null for an absent field (Codex sends `_meta: null`), or a
158
+ * content block MCP does not define, such as an image whose bytes storage stripped.
159
*/
160
function normalizeMcpAppToolResult(result: McpAppCallToolResult): McpAppCallToolResult {
161
return {
140
- content: Array.isArray(result.content) ? result.content : [],
162
+ content: Array.isArray(result.content) ? result.content.filter(isMcpContentBlock) : [],
163
...(Predicate.isObject(result.structuredContent)
164
? { structuredContent: result.structuredContent }
165
: {}),