Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/server/src/mcp/McpHttpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 9 additions & 5 deletions apps/server/src/mcp/McpHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]),
],
}),
);
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/mcp/toolkits/preview/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({})),
Expand Down
12 changes: 10 additions & 2 deletions apps/server/src/mcp/toolkits/preview/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading