File tree Expand file tree Collapse file tree 4 files changed +21
-8
lines changed
Expand file tree Collapse file tree 4 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -198,7 +198,6 @@ export type Context = Readonly<{
198198 triggerExtensionAction ( id : string ) : Promise < void > ;
199199 listExtensions ( ) : InstalledExtension [ ] ;
200200 getExtension ( id : string ) : InstalledExtension | undefined ;
201- setInPageTools ( toolGroup ?: ToolGroup < InPageToolDefinition > ) : void ;
202201 getInPageTools ( ) : ToolGroup < InPageToolDefinition > | undefined ;
203202 getSelectedMcpPage ( ) : McpPage ;
204203 getExtensionServiceWorkers ( ) : ExtensionServiceWorker [ ] ;
Original file line number Diff line number Diff line change @@ -66,14 +66,27 @@ export const executeInPageTool = definePageTool({
6666 schema : {
6767 toolName : zod . string ( ) . describe ( 'The name of the tool to execute' ) ,
6868 params : zod
69- . record ( zod . string ( ) , zod . unknown ( ) )
69+ . string ( )
7070 . optional ( )
71- . describe ( 'The parameters to pass to the tool' ) ,
71+ . describe ( 'The JSON-stringified parameters to pass to the tool' ) ,
7272 } ,
7373 handler : async ( request , response , context ) => {
7474 const page = context . getSelectedMcpPage ( ) ;
7575 const toolName = request . params . toolName ;
76- const params = request . params . params ?? { } ;
76+ let params : Record < string , unknown > = { } ;
77+ if ( request . params . params ) {
78+ try {
79+ const parsed = JSON . parse ( request . params . params ) ;
80+ if ( typeof parsed === 'object' && parsed !== null ) {
81+ params = parsed ;
82+ } else {
83+ throw new Error ( 'Parsed params is not an object' ) ;
84+ }
85+ } catch ( e ) {
86+ const errorMessage = e instanceof Error ? e . message : String ( e ) ;
87+ throw new Error ( `Failed to parse params as JSON: ${ errorMessage } ` ) ;
88+ }
89+ }
7790
7891 const toolGroup = context . getInPageTools ( ) ;
7992 const tool = toolGroup ?. tools . find ( t => t . name === toolName ) ;
Original file line number Diff line number Diff line change @@ -217,6 +217,7 @@ async function fillFormElement(
217217 }
218218}
219219
220+ // here
220221export const fill = definePageTool ( {
221222 name : 'fill' ,
222223 description : `Type text into a input, text area or select an option from a <select> element.` ,
Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ describe('inPage', () => {
194194 {
195195 params : {
196196 toolName : 'test-tool' ,
197- params : { arg : 'value' } ,
197+ params : JSON . stringify ( { arg : 'value' } ) ,
198198 } ,
199199 page : context . getSelectedMcpPage ( ) ,
200200 } ,
@@ -233,7 +233,7 @@ describe('inPage', () => {
233233 {
234234 params : {
235235 toolName : 'missing-tool' ,
236- params : { } ,
236+ params : JSON . stringify ( { } ) ,
237237 } ,
238238 page : context . getSelectedMcpPage ( ) ,
239239 } ,
@@ -282,7 +282,7 @@ describe('inPage', () => {
282282 {
283283 params : {
284284 toolName : 'test-tool' ,
285- params : { } , // Missing required 'arg'
285+ params : JSON . stringify ( { } ) , // Missing required 'arg'
286286 } ,
287287 page : context . getSelectedMcpPage ( ) ,
288288 } ,
@@ -326,7 +326,7 @@ describe('inPage', () => {
326326 {
327327 params : {
328328 toolName : 'test-tool' ,
329- params : { } ,
329+ params : JSON . stringify ( { } ) ,
330330 } ,
331331 page : context . getSelectedMcpPage ( ) ,
332332 } ,
You can’t perform that action at this time.
0 commit comments