@@ -242,6 +242,7 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
242242 case "puppeteer_screenshot" : {
243243 const width = args . width ?? 800 ;
244244 const height = args . height ?? 600 ;
245+ const encoded = args . encoded ?? false ;
245246 await page . setViewport ( { width, height } ) ;
246247
247248 const screenshot = await ( args . selector ?
@@ -269,52 +270,14 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
269270 type : "text" ,
270271 text : `Screenshot '${ args . name } ' taken at ${ width } x${ height } ` ,
271272 } as TextContent ,
272- {
273+ encoded ? ( {
274+ type : "text" ,
275+ text : `data:image/png;base64,${ screenshot } ` ,
276+ } as TextContent ) : ( {
273277 type : "image" ,
274278 data : screenshot ,
275279 mimeType : "image/png" ,
276- } as ImageContent ,
277- ] ,
278- isError : false ,
279- } ;
280- }
281-
282- case "puppeteer_screenshot_encoded" : {
283- const width = args . width ?? 800 ;
284- const height = args . height ?? 600 ;
285- await page . setViewport ( { width, height } ) ;
286-
287- const screenshot = await ( args . selector
288- ? ( await page . $ ( args . selector ) ) ?. screenshot ( { encoding : "base64" } )
289- : page . screenshot ( { encoding : "base64" , fullPage : false } ) ) ;
290-
291- if ( ! screenshot ) {
292- return {
293- content : [
294- {
295- type : "text" ,
296- text : args . selector ? `Element not found: ${ args . selector } ` : "Screenshot failed" ,
297- } ,
298- ] ,
299- isError : true ,
300- } ;
301- }
302-
303- screenshots . set ( args . name , screenshot as string ) ;
304- server . notification ( {
305- method : "notifications/resources/list_changed" ,
306- } ) ;
307-
308- return {
309- content : [
310- {
311- type : "text" ,
312- text : `Screenshot '${ args . name } ' taken at ${ width } x${ height } ` ,
313- } as TextContent ,
314- {
315- type : "text" ,
316- text : `data:image/png;base64,${ screenshot } ` ,
317- } as TextContent ,
280+ } as ImageContent ) ,
318281 ] ,
319282 isError : false ,
320283 } ;
0 commit comments