@@ -12,8 +12,11 @@ import type {ResourceType} from 'puppeteer-core';
1212import { formatConsoleEvent } from './formatters/consoleFormatter.js' ;
1313import {
1414 getFormattedHeaderValue ,
15+ getFormattedResponseBody ,
16+ getFormattedRequestBody ,
1517 getShortDescriptionForRequest ,
1618 getStatusFromRequest ,
19+ BODY_CONTEXT_SIZE_LIMIT ,
1720} from './formatters/networkFormatter.js' ;
1821import { formatA11ySnapshot } from './formatters/snapshotFormatter.js' ;
1922import type { McpContext } from './McpContext.js' ;
@@ -137,13 +140,13 @@ export class McpResponse implements Response {
137140 }
138141 }
139142
140- return this . format ( toolName , context ) ;
143+ return await this . format ( toolName , context ) ;
141144 }
142145
143- format (
146+ async format (
144147 toolName : string ,
145148 context : McpContext ,
146- ) : Array < TextContent | ImageContent > {
149+ ) : Promise < Array < TextContent | ImageContent > > {
147150 const response = [ `# ${ toolName } response` ] ;
148151 for ( const line of this . #textResponseLines) {
149152 response . push ( line ) ;
@@ -192,7 +195,7 @@ Call ${handleDialog.name} to handle it before continuing.`);
192195 }
193196 }
194197
195- response . push ( ...this . #getIncludeNetworkRequestsData( context ) ) ;
198+ response . push ( ...( await this . #getIncludeNetworkRequestsData( context ) ) ) ;
196199
197200 if ( this . #networkRequestsOptions?. include ) {
198201 let requests = context . getNetworkRequests ( ) ;
@@ -272,7 +275,7 @@ Call ${handleDialog.name} to handle it before continuing.`);
272275 } ;
273276 }
274277
275- #getIncludeNetworkRequestsData( context : McpContext ) : string [ ] {
278+ async #getIncludeNetworkRequestsData( context : McpContext ) : Promise < string [ ] > {
276279 const response : string [ ] = [ ] ;
277280 const url = this . #attachedNetworkRequestUrl;
278281 if ( ! url ) {
@@ -286,12 +289,30 @@ Call ${handleDialog.name} to handle it before continuing.`);
286289 response . push ( line ) ;
287290 }
288291
292+ const formattedRequestData = await getFormattedRequestBody (
293+ '### Request body' ,
294+ httpRequest ,
295+ BODY_CONTEXT_SIZE_LIMIT ,
296+ ) ;
297+ if ( formattedRequestData . length > 0 ) {
298+ response . push ( formattedRequestData ) ;
299+ }
300+
289301 const httpResponse = httpRequest . response ( ) ;
290302 if ( httpResponse ) {
291303 response . push ( `### Response Headers` ) ;
292304 for ( const line of getFormattedHeaderValue ( httpResponse . headers ( ) ) ) {
293305 response . push ( line ) ;
294306 }
307+
308+ const formattedResponseData = await getFormattedResponseBody (
309+ '### Response body' ,
310+ httpResponse ,
311+ BODY_CONTEXT_SIZE_LIMIT ,
312+ ) ;
313+ if ( formattedResponseData . length > 0 ) {
314+ response . push ( formattedResponseData ) ;
315+ }
295316 }
296317
297318 const httpFailure = httpRequest . failure ( ) ;
0 commit comments