@@ -441,7 +441,7 @@ describe('inPage', () => {
441441 } ) ;
442442 } ) ;
443443
444- it ( 'processToolResult replaces functions with "function "' , async ( ) => {
444+ it ( 'processToolResult replaces functions with "<Function object> "' , async ( ) => {
445445 await withMcpContext (
446446 async ( response , context ) => {
447447 await setupInPageTools ( response , context , ( ) => {
@@ -481,15 +481,15 @@ describe('inPage', () => {
481481 ) ;
482482 assert . strictEqual (
483483 response . responseLines [ 0 ] ,
484- JSON . stringify ( { foo : 'bar' , func : 'function ' } , null , 2 ) ,
484+ JSON . stringify ( { foo : 'bar' , func : '<Function object> ' } , null , 2 ) ,
485485 ) ;
486486 } ,
487487 undefined ,
488488 { categoryInPageTools : true } as ParsedArguments ,
489489 ) ;
490490 } ) ;
491491
492- it ( 'processToolResult respects cutoff depth ' , async ( ) => {
492+ it ( 'processToolResult replaces circular references with "<Circular reference>" ' , async ( ) => {
493493 await withMcpContext (
494494 async ( response , context ) => {
495495 await setupInPageTools ( response , context , ( ) => {
@@ -503,12 +503,8 @@ describe('inPage', () => {
503503 description : 'test tool description' ,
504504 inputSchema : { } ,
505505 execute : ( ) => {
506- const obj : Record < string , unknown > = { } ;
507- let current = obj ;
508- for ( let i = 0 ; i < 10 ; i ++ ) {
509- current . nested = { } ;
510- current = current . nested as Record < string , unknown > ;
511- }
506+ const obj : Record < string , unknown > = { foo : 'bar' } ;
507+ obj . self = obj ;
512508 return obj ;
513509 } ,
514510 } ,
@@ -532,15 +528,65 @@ describe('inPage', () => {
532528 response ,
533529 context ,
534530 ) ;
531+ assert . strictEqual (
532+ response . responseLines [ 0 ] ,
533+ JSON . stringify ( { foo : 'bar' , self : '<Circular reference>' } , null , 2 ) ,
534+ ) ;
535+ } ,
536+ undefined ,
537+ { categoryInPageTools : true } as ParsedArguments ,
538+ ) ;
539+ } ) ;
535540
536- const parsedResult = JSON . parse ( response . responseLines [ 0 ] ) ;
537- let current = parsedResult . result ;
538- let depth = 0 ;
539- while ( current && Object . keys ( current ) . length > 0 ) {
540- current = current . nested ;
541- depth ++ ;
542- }
543- assert . ok ( depth <= 7 , `Expected depth to be <= 7, got ${ depth } ` ) ;
541+ it ( 'processToolResult replaces non-plain objects with "<ConstructorName instance>"' , async ( ) => {
542+ await withMcpContext (
543+ async ( response , context ) => {
544+ await setupInPageTools ( response , context , ( ) => {
545+ class CustomClass {
546+ val = 'value' ;
547+ }
548+ window . __dtmcp = {
549+ toolGroup : {
550+ name : 'test-group' ,
551+ description : 'test description' ,
552+ tools : [
553+ {
554+ name : 'test-tool' ,
555+ description : 'test tool description' ,
556+ inputSchema : { } ,
557+ execute : ( ) => ( {
558+ foo : 'bar' ,
559+ custom : new CustomClass ( ) ,
560+ } ) ,
561+ } ,
562+ ] ,
563+ } ,
564+ } ;
565+ window . addEventListener ( 'devtoolstooldiscovery' , ( e : Event ) => {
566+ // @ts -expect-error Event has `respondWith`
567+ e . respondWith ( window . __dtmcp ?. toolGroup ) ;
568+ } ) ;
569+ } ) ;
570+
571+ await executeInPageTool . handler (
572+ {
573+ params : {
574+ toolName : 'test-tool' ,
575+ params : JSON . stringify ( { } ) ,
576+ } ,
577+ page : context . getSelectedMcpPage ( ) ,
578+ } ,
579+ response ,
580+ context ,
581+ ) ;
582+ assert . strictEqual (
583+ response . responseLines [ 0 ] ,
584+ JSON . stringify (
585+ { foo : 'bar' , custom : '<CustomClass instance>' } ,
586+ null ,
587+ 2 ,
588+ ) ,
589+ ) ;
544590 } ,
545591 undefined ,
546592 { categoryInPageTools : true } as ParsedArguments ,
0 commit comments