@@ -64,6 +64,29 @@ const TOOLS: Tool[] = [
64
64
required : [ "selector" , "value" ] ,
65
65
} ,
66
66
} ,
67
+ {
68
+ name : "puppeteer_select" ,
69
+ description : "Select an element on the page with Select tag" ,
70
+ inputSchema : {
71
+ type : "object" ,
72
+ properties : {
73
+ selector : { type : "string" , description : "CSS selector for element to select" } ,
74
+ value : { type : "string" , description : "Value to select" } ,
75
+ } ,
76
+ required : [ "selector" , "value" ] ,
77
+ } ,
78
+ } ,
79
+ {
80
+ name : "puppeteer_hover" ,
81
+ description : "Hover an element on the page" ,
82
+ inputSchema : {
83
+ type : "object" ,
84
+ properties : {
85
+ selector : { type : "string" , description : "CSS selector for element to hover" } ,
86
+ } ,
87
+ required : [ "selector" ] ,
88
+ } ,
89
+ } ,
67
90
{
68
91
name : "puppeteer_evaluate" ,
69
92
description : "Execute JavaScript in the browser console" ,
@@ -88,7 +111,7 @@ async function ensureBrowser() {
88
111
browser = await puppeteer . launch ( { headless : false } ) ;
89
112
const pages = await browser . pages ( ) ;
90
113
page = pages [ 0 ] ;
91
-
114
+
92
115
page . on ( "console" , ( msg ) => {
93
116
const logEntry = `[${ msg . type ( ) } ] ${ msg . text ( ) } ` ;
94
117
consoleLogs . push ( logEntry ) ;
@@ -122,7 +145,7 @@ async function handleToolCall(name: string, args: any): Promise<{ toolResult: Ca
122
145
const height = args . height ?? 600 ;
123
146
await page . setViewport ( { width, height } ) ;
124
147
125
- const screenshot = await ( args . selector ?
148
+ const screenshot = await ( args . selector ?
126
149
( await page . $ ( args . selector ) ) ?. screenshot ( { encoding : "base64" } ) :
127
150
page . screenshot ( { encoding : "base64" , fullPage : false } ) ) ;
128
151
@@ -210,12 +233,62 @@ async function handleToolCall(name: string, args: any): Promise<{ toolResult: Ca
210
233
} ;
211
234
}
212
235
236
+ case "puppeteer_select" :
237
+ try {
238
+ await page . waitForSelector ( args . selector ) ;
239
+ await page . select ( args . selector , args . value ) ;
240
+ return {
241
+ toolResult : {
242
+ content : [ {
243
+ type : "text" ,
244
+ text : `Selected ${ args . selector } with: ${ args . value } ` ,
245
+ } ] ,
246
+ isError : false ,
247
+ } ,
248
+ } ;
249
+ } catch ( error ) {
250
+ return {
251
+ toolResult : {
252
+ content : [ {
253
+ type : "text" ,
254
+ text : `Failed to select ${ args . selector } : ${ ( error as Error ) . message } ` ,
255
+ } ] ,
256
+ isError : true ,
257
+ } ,
258
+ } ;
259
+ }
260
+
261
+ case "puppeteer_hover" :
262
+ try {
263
+ await page . waitForSelector ( args . selector ) ;
264
+ await page . hover ( args . selector ) ;
265
+ return {
266
+ toolResult : {
267
+ content : [ {
268
+ type : "text" ,
269
+ text : `Hovered ${ args . selector } ` ,
270
+ } ] ,
271
+ isError : false ,
272
+ } ,
273
+ } ;
274
+ } catch ( error ) {
275
+ return {
276
+ toolResult : {
277
+ content : [ {
278
+ type : "text" ,
279
+ text : `Failed to hover ${ args . selector } : ${ ( error as Error ) . message } ` ,
280
+ } ] ,
281
+ isError : true ,
282
+ } ,
283
+ } ;
284
+ }
285
+
213
286
case "puppeteer_evaluate" :
214
287
try {
215
288
const result = await page . evaluate ( ( script ) => {
216
289
const logs : string [ ] = [ ] ;
217
290
const originalConsole = { ...console } ;
218
-
291
+
219
292
[ 'log' , 'info' , 'warn' , 'error' ] . forEach ( method => {
220
293
( console as any ) [ method ] = ( ...args : any [ ] ) => {
221
294
logs . push ( `[${ method } ] ${ args . join ( ' ' ) } ` ) ;
@@ -301,7 +374,7 @@ server.setRequestHandler(ListResourcesRequestSchema, async () => ({
301
374
302
375
server . setRequestHandler ( ReadResourceRequestSchema , async ( request ) => {
303
376
const uri = request . params . uri . toString ( ) ;
304
-
377
+
305
378
if ( uri === "console://logs" ) {
306
379
return {
307
380
contents : [ {
@@ -333,7 +406,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
333
406
tools : TOOLS ,
334
407
} ) ) ;
335
408
336
- server . setRequestHandler ( CallToolRequestSchema , async ( request ) =>
409
+ server . setRequestHandler ( CallToolRequestSchema , async ( request ) =>
337
410
handleToolCall ( request . params . name , request . params . arguments ?? { } )
338
411
) ;
339
412
0 commit comments