Skip to content

Commit 3890904

Browse files
fix(server): an MCP app keeps the image data of a result that fits the detail bound
Stripping image data from an app call's wrapped result also stripped it from the payload the app itself receives, so an app drawing an image got image blocks without data. The server now sends an app's result unchanged when it fits the 256 KiB detail bound and strips images only from one that does not. The tool row still shows `[image]` for app images. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 82c0581 commit 3890904

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/WireProjection.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ describe("orchestration V2 wire projection", () => {
238238
expect(projectTurnItemForDetail(appItem)).toMatchObject({
239239
output: { t3McpApp, result: { content: [text, { type: "image", mimeType: "image/png" }] } },
240240
});
241+
const largeOutput = projectTurnItemForDetail(appItem);
242+
expect(
243+
JSON.stringify(largeOutput.type === "dynamic_tool" ? largeOutput.output : null),
244+
).not.toContain(data);
245+
246+
const smallApp = {
247+
t3McpApp,
248+
result: { content: [text, { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" }] },
249+
};
250+
expect(projectTurnItemForDetail({ ...appItem, output: smallApp })).toMatchObject({
251+
output: smallApp,
252+
});
241253

242254
const forged = projectTurnItemForDetail({
243255
...appItem,

‎apps/server/src/orchestration-v2/WireProjection.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ function boundToolOutput(output: unknown): unknown {
246246
}
247247
const app =
248248
MCP_APP_OUTPUT_KEY in output ? readMcpAppReference(output[MCP_APP_OUTPUT_KEY]) : undefined;
249-
return app === undefined
250-
? boundToolResult(output)
251-
: { [MCP_APP_OUTPUT_KEY]: app, result: boundToolResult(output.result) };
249+
if (app === undefined) return boundToolResult(output);
250+
// The app receives this result, so its image data stays unless it is too large to send.
251+
const fits = boundDynamicValue(output.result) === output.result;
252+
return {
253+
[MCP_APP_OUTPUT_KEY]: app,
254+
result: fits ? output.result : boundToolResult(output.result),
255+
};
252256
}
253257

254258
export function projectTurnItemForDetail(item: OrchestrationV2TurnItem): OrchestrationV2TurnItem {

0 commit comments

Comments
 (0)