@@ -307,7 +307,6 @@ export class McpResponse implements Response {
307307 if ( this . #listExtensions) {
308308 extensions = context . listExtensions ( ) ;
309309 }
310-
311310 let consoleMessages : Array < ConsoleFormatter | IssueFormatter > | undefined ;
312311 if ( this . #consoleDataOptions?. include ) {
313312 let messages = context . getConsoleData (
@@ -378,13 +377,8 @@ export class McpResponse implements Response {
378377 }
379378
380379 if ( requests . length ) {
381- const data = this . #dataWithPagination(
382- requests ,
383- this . #networkRequestsOptions. pagination ,
384- ) ;
385-
386380 networkRequests = await Promise . all (
387- data . items . map ( request =>
381+ requests . map ( request =>
388382 NetworkFormatter . from ( request , {
389383 requestId : context . getNetworkRequestStableId ( request ) ,
390384 selectedInDevToolsUI :
@@ -424,9 +418,36 @@ export class McpResponse implements Response {
424418 extensions ?: InstalledExtension [ ] ;
425419 } ,
426420 ) : { content : Array < TextContent | ImageContent > ; structuredContent : object } {
421+ const structuredContent : {
422+ snapshot ?: object ;
423+ snapshotFilePath ?: string ;
424+ tabId ?: string ;
425+ networkRequest ?: object ;
426+ networkRequests ?: object [ ] ;
427+ consoleMessage ?: object ;
428+ consoleMessages ?: object [ ] ;
429+ traceSummary ?: string ;
430+ traceInsights ?: Array < { insightName : string ; insightKey : string } > ;
431+ extensions ?: object [ ] ;
432+ message ?: string ;
433+ networkConditions ?: string ;
434+ navigationTimeout ?: number ;
435+ viewport ?: object ;
436+ userAgent ?: string ;
437+ cpuThrottlingRate ?: number ;
438+ dialog ?: {
439+ type : string ;
440+ message : string ;
441+ defaultValue ?: string ;
442+ } ;
443+ pages ?: object [ ] ;
444+ pagination ?: object ;
445+ } = { } ;
446+
427447 const response = [ `# ${ toolName } response` ] ;
428- for ( const line of this . #textResponseLines) {
429- response . push ( line ) ;
448+ if ( this . #textResponseLines. length ) {
449+ structuredContent . message = this . #textResponseLines. join ( '\n' ) ;
450+ response . push ( ...this . #textResponseLines) ;
430451 }
431452
432453 const networkConditions = context . getNetworkConditions ( ) ;
@@ -436,24 +457,29 @@ export class McpResponse implements Response {
436457 response . push (
437458 `Default navigation timeout set to ${ context . getNavigationTimeout ( ) } ms` ,
438459 ) ;
460+ structuredContent . networkConditions = networkConditions ;
461+ structuredContent . navigationTimeout = context . getNavigationTimeout ( ) ;
439462 }
440463
441464 const viewport = context . getViewport ( ) ;
442465 if ( viewport ) {
443466 response . push ( `## Viewport emulation` ) ;
444467 response . push ( `Emulating viewport: ${ JSON . stringify ( viewport ) } ` ) ;
468+ structuredContent . viewport = viewport ;
445469 }
446470
447471 const userAgent = context . getUserAgent ( ) ;
448472 if ( userAgent ) {
449473 response . push ( `## UserAgent emulation` ) ;
450474 response . push ( `Emulating userAgent: ${ userAgent } ` ) ;
475+ structuredContent . userAgent = userAgent ;
451476 }
452477
453478 const cpuThrottlingRate = context . getCpuThrottlingRate ( ) ;
454479 if ( cpuThrottlingRate > 1 ) {
455480 response . push ( `## CPU emulation` ) ;
456481 response . push ( `Emulating: ${ cpuThrottlingRate } x slowdown` ) ;
482+ structuredContent . cpuThrottlingRate = cpuThrottlingRate ;
457483 }
458484
459485 const dialog = context . getDialog ( ) ;
@@ -465,6 +491,11 @@ export class McpResponse implements Response {
465491 response . push ( `# Open dialog
466492${ dialog . type ( ) } : ${ dialog . message ( ) } ${ defaultValueIfNeeded } .
467493Call ${ handleDialog . name } to handle it before continuing.` ) ;
494+ structuredContent . dialog = {
495+ type : dialog . type ( ) ,
496+ message : dialog . message ( ) ,
497+ defaultValue : dialog . defaultValue ( ) ,
498+ } ;
468499 }
469500
470501 if ( this . #includePages) {
@@ -475,21 +506,15 @@ Call ${handleDialog.name} to handle it before continuing.`);
475506 ) ;
476507 }
477508 response . push ( ...parts ) ;
509+ structuredContent . pages = context . getPages ( ) . map ( page => {
510+ return {
511+ id : context . getPageId ( page ) ,
512+ url : page . url ( ) ,
513+ selected : context . isPageSelected ( page ) ,
514+ } ;
515+ } ) ;
478516 }
479517
480- const structuredContent : {
481- snapshot ?: object ;
482- snapshotFilePath ?: string ;
483- tabId ?: string ;
484- networkRequest ?: object ;
485- networkRequests ?: object [ ] ;
486- consoleMessage ?: object ;
487- consoleMessages ?: object [ ] ;
488- traceSummary ?: string ;
489- traceInsights ?: Array < { insightName : string ; insightKey : string } > ;
490- extensions ?: object [ ] ;
491- } = { } ;
492-
493518 if ( this . #tabId) {
494519 structuredContent . tabId = this . #tabId;
495520 }
@@ -582,6 +607,7 @@ Call ${handleDialog.name} to handle it before continuing.`);
582607 requests ,
583608 this . #networkRequestsOptions. pagination ,
584609 ) ;
610+ structuredContent . pagination = paginationData . pagination ;
585611 response . push ( ...paginationData . info ) ;
586612 if ( data . networkRequests ) {
587613 structuredContent . networkRequests = [ ] ;
@@ -600,13 +626,16 @@ Call ${handleDialog.name} to handle it before continuing.`);
600626
601627 response . push ( '## Console messages' ) ;
602628 if ( messages . length ) {
603- const data = this . #dataWithPagination(
629+ const paginationData = this . #dataWithPagination(
604630 messages ,
605631 this . #consoleDataOptions. pagination ,
606632 ) ;
607- response . push ( ...data . info ) ;
608- response . push ( ...data . items . map ( message => message . toString ( ) ) ) ;
609- structuredContent . consoleMessages = data . items . map ( message =>
633+ structuredContent . pagination = paginationData . pagination ;
634+ response . push ( ...paginationData . info ) ;
635+ response . push (
636+ ...paginationData . items . map ( message => message . toString ( ) ) ,
637+ ) ;
638+ structuredContent . consoleMessages = paginationData . items . map ( message =>
610639 message . toJSON ( ) ,
611640 ) ;
612641 } else {
@@ -654,6 +683,15 @@ Call ${handleDialog.name} to handle it before continuing.`);
654683 return {
655684 info : response ,
656685 items : paginationResult . items ,
686+ pagination : {
687+ currentPage : paginationResult . currentPage ,
688+ totalPages : paginationResult . totalPages ,
689+ hasNextPage : paginationResult . hasNextPage ,
690+ hasPreviousPage : paginationResult . hasPreviousPage ,
691+ startIndex : paginationResult . startIndex ,
692+ endIndex : paginationResult . endIndex ,
693+ invalidPage : paginationResult . invalidPage ,
694+ } ,
657695 } ;
658696 }
659697
0 commit comments