@devries-cameron20 / t3code-1 / commits / 3cd97a1ee2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): saved preview screenshots keep full resolution (#28255)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Antony committed Nov 8, 2026 at 06:12 UTC 3cd97a1ee230437b1bfd8441dffe65eac55be1e5
7 files changed +95 -11
apps/server/src/mcp/McpHttpServer.test.ts
+52
@@ -20,6 +20,7 @@ import {
20 import * as Context from "effect/Context";
21 import * as Deferred from "effect/Deferred";
22 import * as Effect from "effect/Effect";
23 +import * as FileSystem from "effect/FileSystem";
24 import * as Layer from "effect/Layer";
25 import * as Logger from "effect/Logger";
26 import * as Schema from "effect/Schema";
@@ -467,6 +468,57 @@ it.effect.each([
468 ).pipe(Effect.provide(layerTest)),
469 );
470
471 +it.effect("saves the uncapped screenshot while the agent sees the capped one", () =>
472 + Effect.scoped(
473 + Effect.gen(function* () {
474 + const server = yield* McpServer.McpServer;
475 + const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
476 + const connected = yield* Deferred.make<void>();
477 + const capped =
478 + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=";
479 + const full =
480 + "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAAAAABX3VL4AAAADklEQVR4nGNgYGBgYAAAAAYAAXKCmeoAAAAASUVORK5CYII=";
481 + const events = yield* broker.connect({ clientId: "mcp-save-client", environmentId });
482 + yield* Stream.runForEach(events, (event) => {
483 + if (event.type === "connected") return Deferred.succeed(connected, undefined);
484 + expect(event.request.input).toEqual({ fullScreenshot: true });
485 + return broker.respond({
486 + clientId: "mcp-save-client",
487 + connectionId: event.connectionId,
488 + requestId: event.request.requestId,
489 + ok: true,
490 + result: {
491 + ...snapshotResult,
492 + screenshot: { mimeType: "image/png", data: capped, width: 1, height: 1 },
493 + fullScreenshot: { data: full, width: 2, height: 2 },
494 + },
495 + });
496 + }).pipe(Effect.forkScoped);
497 + yield* Deferred.await(connected);
498 +
499 + const snapshot = yield* server
500 + .callTool({
501 + name: "preview_snapshot",
502 + arguments: { tabId: alternateTabId, save: true, includeImage: true },
503 + })
504 + .pipe(
505 + Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
506 + Effect.provideService(McpSchema.McpServerClient, client),
507 + );
508 + const { screenshotPath } = snapshot.structuredContent as { readonly screenshotPath: string };
509 + const saved = yield* (yield* FileSystem.FileSystem).readFile(screenshotPath);
510 +
511 + expect(Buffer.from(saved).toString("base64")).toBe(full);
512 + expect(snapshot.structuredContent).not.toHaveProperty("fullScreenshot");
513 + expect(snapshot.content.at(-1)).toEqual({
514 + type: "image",
515 + mimeType: "image/png",
516 + data: new Uint8Array(Buffer.from(capped, "base64")),
517 + });
518 + }),
519 + ).pipe(Effect.provide(layerTest)),
520 +);
521 +
522 it.effect("refuses preview tools to a client outside a thread before they run", () =>
523 Effect.gen(function* () {
524 const server = yield* McpServer.McpServer;
apps/server/src/mcp/McpHttpServer.ts
+10 -2
@@ -557,11 +557,19 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
557 readonly width: number;
558 readonly height: number;
559 };
560 + readonly fullScreenshot?: { readonly data: string };
561 };
561 - const { screenshot, ...page } = snapshot;
562 + const { screenshot, fullScreenshot, ...page } = snapshot;
563 const png = new Uint8Array(Buffer.from(screenshot.data, "base64"));
564 const screenshotPath =
564 - payload?.save === true ? yield* saveScreenshot(snapshot.url, png) : undefined;
565 + payload?.save === true
566 + ? yield* saveScreenshot(
567 + snapshot.url,
568 + fullScreenshot
569 + ? new Uint8Array(Buffer.from(fullScreenshot.data, "base64"))
570 + : png,
571 + )
572 + : undefined;
573 // Providers replay images on later requests, and some reject them; include images only when requested.
574 const includeImage = payload?.includeImage === true;
575 if (screenshotPath !== undefined && !includeImage) {
apps/server/src/mcp/toolkits/preview/handlers.ts
+6 -2
@@ -221,8 +221,12 @@ const handlers = {
221 invokeTargeted<PreviewAutomationSetColorSchemeResult>("setColorScheme", input),
222 ),
223 preview_snapshot: McpToolAccess.readsAsCaller((input) => {
224 - const { includeImage: _includeImage, save: _save, ...operationInput } = input ?? {};
225 - return invokeTargeted<PreviewAutomationSnapshot>("snapshot", operationInput);
224 + const { includeImage: _includeImage, save, ...operationInput } = input ?? {};
225 + // The saved file is for people, so it keeps the resolution the agent's image is capped below.
226 + return invokeTargeted<PreviewAutomationSnapshot>("snapshot", {
227 + ...operationInput,
228 + ...(save === true ? { fullScreenshot: true } : {}),
229 + });
230 }),
231 preview_act: McpToolAccess.actsAsCaller(({ action, ...input }) =>
232 decodeActInput[action](input).pipe(
apps/server/src/preview/ServerBrowser.ts
+2
@@ -30,6 +30,7 @@ import {
30 type PreviewAutomationScrollInput,
31 type PreviewAutomationSelectInput,
32 type PreviewAutomationSetColorSchemeInput,
33 + type PreviewAutomationSnapshotInput,
34 type PreviewAutomationStatus,
35 type PreviewAutomationTypeInput,
36 type PreviewAutomationUploadInput,
@@ -2241,6 +2242,7 @@ const make = Effect.gen(function* () {
2242 ServerBrowserPage.snapshot({
2243 ...tab,
2244 renderScale: tab.desktop ? "display" : RENDER_SCALE,
2245 + fullScreenshot: (input as PreviewAutomationSnapshotInput | undefined)?.fullScreenshot,
2246 }),
2247 );
2248 }
apps/server/src/preview/ServerBrowserPage.test.ts
+6 -4
@@ -309,10 +309,11 @@ describe("server browser snapshot screenshot", () => {
309 const screenshotOf = async (html: string) => {
310 const page = await context.newPage();
311 await page.setContent(html);
312 - const { screenshot } = await ServerBrowserPage.snapshot({
312 + const { screenshot, fullScreenshot } = await ServerBrowserPage.snapshot({
313 page,
314 cdp: await context.newCDPSession(page),
315 renderScale: 2,
316 + fullScreenshot: true,
317 consoleEntries: [],
318 networkEntries: [],
319 actionTimeline: [],
@@ -335,7 +336,7 @@ describe("server browser snapshot screenshot", () => {
336 Array.from(context.getImageData(x * bitmap.width, y * bitmap.height, 1, 1).data),
337 );
338 })()`)) as Array<[number, number, number, number]>;
338 - return { screenshot, pixels };
339 + return { screenshot, fullScreenshot, pixels };
340 };
341 const colorOf = ([red, green, blue]: readonly [number, number, number, number]) =>
342 blue - red > 100 ? "blue" : red - blue > 100 ? "red" : `rgb(${red}, ${green}, ${blue})`;
@@ -350,12 +351,13 @@ describe("server browser snapshot screenshot", () => {
351 });
352
353 it("captures a plain page at the shrunk size with its content in place", async () => {
353 - const { screenshot, pixels } = await screenshotOf(halves(""));
354 + const { screenshot, fullScreenshot, pixels } = await screenshotOf(halves(""));
355
356 expect({
357 size: [screenshot.width, screenshot.height],
358 + fullSize: [fullScreenshot?.width, fullScreenshot?.height],
359 colors: pixels.map(colorOf),
358 - }).toEqual({ size: [1280, 800], colors: ["blue", "red", "red"] });
360 + }).toEqual({ size: [1280, 800], fullSize: [2560, 1600], colors: ["blue", "red", "red"] });
361 });
362
363 it("shrinks the screenshot of an XML document, whose createElement makes no canvas", async () => {
apps/server/src/preview/ServerBrowserPage.ts
+10 -3
@@ -519,6 +519,7 @@ type SnapshotInput = {
519 readonly cdp: CDPSession;
520 /** Headless pages render at the scale the server set; a desktop page at its display's. */
521 readonly renderScale: number | "display";
522 + readonly fullScreenshot?: boolean | undefined;
523 readonly consoleEntries: ReadonlyArray<PreviewAutomationConsoleEntry>;
524 readonly networkEntries: ReadonlyArray<PreviewAutomationNetworkEntry>;
525 readonly actionTimeline: PreviewAutomationSnapshot["actionTimeline"];
@@ -562,8 +563,13 @@ const capture = async (
563 "url" | "title" | "loading" | "visibleText" | "interactiveElements"
564 >
565 >,
565 - captureViewport(input.cdp, { format: "png" }).then((png) =>
566 - scale < 1 ? shrinkPng(input.cdp, png, scale) : png,
566 + captureViewport(input.cdp, { format: "png" }).then(async (full) =>
567 + scale < 1
568 + ? {
569 + data: await shrinkPng(input.cdp, full, scale),
570 + full: input.fullScreenshot ? full : undefined,
571 + }
572 + : { data: full, full: undefined },
573 ),
574 ]);
575 void pageAndScreenshot.catch(constVoid);
@@ -588,7 +594,7 @@ const capture = async (
594 void iframe.dispose().catch(constVoid);
595 if (frame && unread.includes(frame)) throw tooBusy();
596 }
591 - const [page, data] = await pageAndScreenshot;
597 + const [page, { full, data }] = await pageAndScreenshot;
598 if (state.generation !== generation) throw pageChanged();
599 const mask = (text: string) => (dotted ? text.replace(dotted, MASKED_VALUE) : text);
600 // Redacted before the cut, so a payload crossing it can't leave its start showing, and before
@@ -615,6 +621,7 @@ const capture = async (
621 data,
622 ...pngSize(data),
623 },
624 + ...(full !== undefined ? { fullScreenshot: { data: full, ...pngSize(full) } } : {}),
625 };
626 };
627
packages/contracts/src/previewAutomation.ts
+9
@@ -552,9 +552,18 @@ export const PreviewAutomationSnapshot = Schema.Struct({
552 width: Schema.Int,
553 height: Schema.Int,
554 }),
555 + /** The capture before `screenshot` was capped for the agent, when requested and larger. */
556 + fullScreenshot: Schema.optional(
557 + Schema.Struct({ data: Schema.String, width: Schema.Int, height: Schema.Int }),
558 + ),
559 });
560 export type PreviewAutomationSnapshot = typeof PreviewAutomationSnapshot.Type;
561
562 +export const PreviewAutomationSnapshotInput = Schema.Struct({
563 + fullScreenshot: Schema.optional(Schema.Boolean),
564 +});
565 +export type PreviewAutomationSnapshotInput = typeof PreviewAutomationSnapshotInput.Type;
566 +
567 export const PreviewAutomationRecordingStatus = Schema.Struct({
568 tabId: PreviewTabId,
569 recording: Schema.Boolean,