Skip to content

Commit 239e18f

Browse files
authored
Merge pull request #1201 from yomandawg/jun/puppeteer
Add optional parameter to Puppeteer tool to capture screenshot as base64 TextContent
2 parents bdf4323 + 3ce1efb commit 239e18f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/puppeteer/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A Model Context Protocol server that provides browser automation capabilities us
2222
- `selector` (string, optional): CSS selector for element to screenshot
2323
- `width` (number, optional, default: 800): Screenshot width
2424
- `height` (number, optional, default: 600): Screenshot height
25+
- `encoded` (boolean, optional): If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false.
2526

2627
- **puppeteer_click**
2728

src/puppeteer/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const TOOLS: Tool[] = [
3939
selector: { type: "string", description: "CSS selector for element to screenshot" },
4040
width: { type: "number", description: "Width in pixels (default: 800)" },
4141
height: { type: "number", description: "Height in pixels (default: 600)" },
42+
encoded: { type: "boolean", description: "If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false." },
4243
},
4344
required: ["name"],
4445
},
@@ -228,6 +229,7 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
228229
case "puppeteer_screenshot": {
229230
const width = args.width ?? 800;
230231
const height = args.height ?? 600;
232+
const encoded = args.encoded ?? false;
231233
await page.setViewport({ width, height });
232234

233235
const screenshot = await (args.selector ?
@@ -255,11 +257,14 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
255257
type: "text",
256258
text: `Screenshot '${args.name}' taken at ${width}x${height}`,
257259
} as TextContent,
258-
{
260+
encoded ? ({
261+
type: "text",
262+
text: `data:image/png;base64,${screenshot}`,
263+
} as TextContent) : ({
259264
type: "image",
260265
data: screenshot,
261266
mimeType: "image/png",
262-
} as ImageContent,
267+
} as ImageContent),
263268
],
264269
isError: false,
265270
};

0 commit comments

Comments
 (0)