@@ -10,7 +10,7 @@ import type {McpContext, TextSnapshotNode} from '../McpContext.js';
1010import { zod } from '../third_party/modelcontextprotocol-sdk/index.js' ;
1111
1212import { ToolCategories } from './categories.js' ;
13- import { defineTool } from './ToolDefinition.js' ;
13+ import { defineTool , snapshotSchema } from './ToolDefinition.js' ;
1414
1515export const click = defineTool ( {
1616 name : 'click' ,
@@ -29,6 +29,9 @@ export const click = defineTool({
2929 . boolean ( )
3030 . optional ( )
3131 . describe ( 'Set to true for double clicks. Default is false.' ) ,
32+ snapshot : zod . object ( {
33+ ...snapshotSchema ,
34+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
3235 } ,
3336 handler : async ( request , response , context ) => {
3437 const uid = request . params . uid ;
@@ -44,7 +47,7 @@ export const click = defineTool({
4447 ? `Successfully double clicked on the element`
4548 : `Successfully clicked on the element` ,
4649 ) ;
47- response . setIncludeSnapshot ( true ) ;
50+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
4851 } finally {
4952 void handle . dispose ( ) ;
5053 }
@@ -64,6 +67,9 @@ export const hover = defineTool({
6467 . describe (
6568 'The uid of an element on the page from the page content snapshot' ,
6669 ) ,
70+ snapshot : zod . object ( {
71+ ...snapshotSchema ,
72+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
6773 } ,
6874 handler : async ( request , response , context ) => {
6975 const uid = request . params . uid ;
@@ -73,7 +79,7 @@ export const hover = defineTool({
7379 await handle . asLocator ( ) . hover ( ) ;
7480 } ) ;
7581 response . appendResponseLine ( `Successfully hovered over the element` ) ;
76- response . setIncludeSnapshot ( true ) ;
82+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
7783 } finally {
7884 void handle . dispose ( ) ;
7985 }
@@ -149,6 +155,9 @@ export const fill = defineTool({
149155 'The uid of an element on the page from the page content snapshot' ,
150156 ) ,
151157 value : zod . string ( ) . describe ( 'The value to fill in' ) ,
158+ snapshot : zod . object ( {
159+ ...snapshotSchema ,
160+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
152161 } ,
153162 handler : async ( request , response , context ) => {
154163 await context . waitForEventsAfterAction ( async ( ) => {
@@ -159,7 +168,7 @@ export const fill = defineTool({
159168 ) ;
160169 } ) ;
161170 response . appendResponseLine ( `Successfully filled out the element` ) ;
162- response . setIncludeSnapshot ( true ) ;
171+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
163172 } ,
164173} ) ;
165174
@@ -173,6 +182,9 @@ export const drag = defineTool({
173182 schema : {
174183 from_uid : zod . string ( ) . describe ( 'The uid of the element to drag' ) ,
175184 to_uid : zod . string ( ) . describe ( 'The uid of the element to drop into' ) ,
185+ snapshot : zod . object ( {
186+ ...snapshotSchema ,
187+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
176188 } ,
177189 handler : async ( request , response , context ) => {
178190 const fromHandle = await context . getElementByUid ( request . params . from_uid ) ;
@@ -184,7 +196,7 @@ export const drag = defineTool({
184196 await toHandle . drop ( fromHandle ) ;
185197 } ) ;
186198 response . appendResponseLine ( `Successfully dragged an element` ) ;
187- response . setIncludeSnapshot ( true ) ;
199+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
188200 } finally {
189201 void fromHandle . dispose ( ) ;
190202 void toHandle . dispose ( ) ;
@@ -208,6 +220,9 @@ export const fillForm = defineTool({
208220 } ) ,
209221 )
210222 . describe ( 'Elements from snapshot to fill out.' ) ,
223+ snapshot : zod . object ( {
224+ ...snapshotSchema ,
225+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
211226 } ,
212227 handler : async ( request , response , context ) => {
213228 for ( const element of request . params . elements ) {
@@ -220,7 +235,7 @@ export const fillForm = defineTool({
220235 } ) ;
221236 }
222237 response . appendResponseLine ( `Successfully filled out the form` ) ;
223- response . setIncludeSnapshot ( true ) ;
238+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
224239 } ,
225240} ) ;
226241
@@ -238,6 +253,9 @@ export const uploadFile = defineTool({
238253 'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot' ,
239254 ) ,
240255 filePath : zod . string ( ) . describe ( 'The local path of the file to upload' ) ,
256+ snapshot : zod . object ( {
257+ ...snapshotSchema ,
258+ } ) . optional ( ) . describe ( 'Options for the snapshot included in the response' ) ,
241259 } ,
242260 handler : async ( request , response , context ) => {
243261 const { uid, filePath} = request . params ;
@@ -264,7 +282,7 @@ export const uploadFile = defineTool({
264282 ) ;
265283 }
266284 }
267- response . setIncludeSnapshot ( true ) ;
285+ response . setIncludeSnapshot ( true , request . params . snapshot ?. verbose ?? false ) ;
268286 response . appendResponseLine ( `File uploaded from ${ filePath } .` ) ;
269287 } finally {
270288 void handle . dispose ( ) ;
0 commit comments