Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(mcp): allow text-only preview snapshots (#234)

Leo659833a442fb
diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts
index 65de982b2..71b150117 100644
--- a/apps/server/src/mcp/McpHttpServer.test.ts
+++ b/apps/server/src/mcp/McpHttpServer.test.ts
@@ -387,6 +387,21 @@ it.effect("registers annotated tools and preserves authenticated request context
alternateTabId,
);
+ const textOnly = yield* server
+ .callTool({
+ name: "preview_snapshot",
+ arguments: { tabId: alternateTabId, includeImage: false },
+ })
+ .pipe(
+ Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
+ Effect.provideService(McpSchema.McpServerClient, client),
+ );
+ expect(textOnly.isError).toBe(false);
+ expect(textOnly.content.some((content) => content.type === "image")).toBe(false);
+ expect(textOnly.structuredContent).toMatchObject({
+ screenshot: { mimeType: "image/png", width: 10, height: 5, redacted: true },
+ });
+
const evaluation = yield* server
.callTool({ name: "preview_evaluate", arguments: { expression: "document.body" } })
.pipe(
diff --git a/apps/server/src/mcp/McpHttpServer.ts b/apps/server/src/mcp/McpHttpServer.ts
index 0ea869536..9541ddfdb 100644
--- a/apps/server/src/mcp/McpHttpServer.ts
+++ b/apps/server/src/mcp/McpHttpServer.ts
@@ -343,11 +343,15 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
structuredContent: metadata,
content: [
{ type: "text", text: JSON.stringify(metadata) },
- {
- type: "image",
- data: new Uint8Array(Buffer.from(screenshot.data, "base64")),
- mimeType: screenshot.mimeType,
- },
+ ...(payload?.includeImage === false
+ ? []
+ : [
+ {
+ type: "image" as const,
+ data: new Uint8Array(Buffer.from(screenshot.data, "base64")),
+ mimeType: screenshot.mimeType,
+ },
+ ]),
],
}),
);
diff --git a/apps/server/src/mcp/toolkits/preview/handlers.ts b/apps/server/src/mcp/toolkits/preview/handlers.ts
index 17da78014..c501ee087 100644
--- a/apps/server/src/mcp/toolkits/preview/handlers.ts
+++ b/apps/server/src/mcp/toolkits/preview/handlers.ts
@@ -77,7 +77,11 @@ const handlers = {
invokeTargeted<PreviewAutomationResizeResult>("resize", input, input.timeoutMs),
preview_set_appearance: (input) =>
invokeTargeted<PreviewAutomationSetColorSchemeResult>("setColorScheme", input),
- preview_snapshot: (input) => invokeTargeted<PreviewAutomationSnapshot>("snapshot", input ?? {}),
+ preview_snapshot: (input) => {
+ // Output selection is MCP-only; the browser still produces a complete snapshot.
+ const { includeImage: _includeImage, ...operationInput } = input ?? {};
+ return invokeTargeted<PreviewAutomationSnapshot>("snapshot", operationInput);
+ },
preview_click: (input) =>
invokeTargeted<void>("click", input, input.timeoutMs).pipe(Effect.as({})),
preview_type: (input) => invokeTargeted<void>("type", input, input.timeoutMs).pipe(Effect.as({})),
diff --git a/apps/server/src/mcp/toolkits/preview/tools.ts b/apps/server/src/mcp/toolkits/preview/tools.ts
index e6cf035fb..b3b481da9 100644
--- a/apps/server/src/mcp/toolkits/preview/tools.ts
+++ b/apps/server/src/mcp/toolkits/preview/tools.ts
@@ -108,8 +108,16 @@ export const PreviewSetAppearanceTool = safeBrowserTool(
export const PreviewSnapshotTool = readonlyBrowserTool(
Tool.make("preview_snapshot", {
description:
- "Inspect a page before interacting. Pass tabId to inspect a specific tab; omit it to use this agent session's current tab. Returns page state, semantic elements, diagnostics, action history, and a PNG screenshot.",
- parameters: PreviewAutomationTabTargetInput,
+ "Inspect a page before interacting. Pass tabId to inspect a specific tab; omit it to use this agent session's current tab. Returns page state, semantic elements, diagnostics, action history, and a PNG screenshot. Set includeImage=false for text-only output with the same page metadata.",
+ parameters: Schema.Struct({
+ ...PreviewAutomationTabTargetInput.fields,
+ includeImage: Schema.optional(
+ Schema.Boolean.annotate({
+ description:
+ "Include the PNG image in the tool response. Defaults to true. Set false for text-only output.",
+ }),
+ ),
+ }),
success: PreviewAutomationSnapshot,
failure: PreviewAutomationError,
dependencies,