@@ -7,28 +7,32 @@ import type {
77 ImageContent ,
88 TextContent ,
99} from '@modelcontextprotocol/sdk/types.js' ;
10+ import type { ResourceType } from 'puppeteer-core' ;
1011
11- import { formatConsoleEvent } from './formatters/consoleFormatter.js' ;
12+ import { formatConsoleEvent } from './formatters/consoleFormatter.js' ;
1213import {
1314 getFormattedHeaderValue ,
1415 getShortDescriptionForRequest ,
1516 getStatusFromRequest ,
1617} from './formatters/networkFormatter.js' ;
17- import { formatA11ySnapshot } from './formatters/snapshotFormatter.js' ;
18- import type { McpContext } from './McpContext.js' ;
19- import type { ImageContentData , Response } from './tools/ToolDefinition.js' ;
20- import { paginate , type PaginationOptions } from './utils/pagination.js' ;
18+ import { formatA11ySnapshot } from './formatters/snapshotFormatter.js' ;
19+ import type { McpContext } from './McpContext.js' ;
20+ import type { ImageContentData , Response } from './tools/ToolDefinition.js' ;
21+ import { paginate , type PaginationOptions } from './utils/pagination.js' ;
2122
2223export class McpResponse implements Response {
2324 #includePages = false ;
2425 #includeSnapshot = false ;
25- #includeNetworkRequests = false ;
2626 #attachedNetworkRequestUrl?: string ;
2727 #includeConsoleData = false ;
2828 #textResponseLines: string [ ] = [ ] ;
2929 #formattedConsoleData?: string [ ] ;
3030 #images: ImageContentData [ ] = [ ] ;
31- #networkRequestsPaginationOptions?: PaginationOptions ;
31+ #networkRequestsOptions?: {
32+ include : boolean ;
33+ pagination ?: PaginationOptions ;
34+ resourceTypes ?: ResourceType [ ] ;
35+ } ;
3236
3337 setIncludePages ( value : boolean ) : void {
3438 this . #includePages = value ;
@@ -40,17 +44,20 @@ export class McpResponse implements Response {
4044
4145 setIncludeNetworkRequests (
4246 value : boolean ,
43- options ?: { pageSize ?: number ; pageIdx ?: number } ,
47+ options ?: { pageSize ?: number ; pageIdx ?: number ; resourceTypes ?: ResourceType [ ] } ,
4448 ) : void {
45- this . #includeNetworkRequests = value ;
46- if ( ! value || ! options ) {
47- this . #networkRequestsPaginationOptions = undefined ;
49+ if ( ! value ) {
50+ this . #networkRequestsOptions = undefined ;
4851 return ;
4952 }
5053
51- this . #networkRequestsPaginationOptions = {
52- pageSize : options . pageSize ,
53- pageIdx : options . pageIdx ,
54+ this . #networkRequestsOptions = {
55+ include : value ,
56+ pagination : options ?. pageSize || options ?. pageIdx ? {
57+ pageSize : options . pageSize ,
58+ pageIdx : options . pageIdx ,
59+ } : undefined ,
60+ resourceTypes : options ?. resourceTypes ,
5461 } ;
5562 }
5663
@@ -67,7 +74,7 @@ export class McpResponse implements Response {
6774 }
6875
6976 get includeNetworkRequests ( ) : boolean {
70- return this . #includeNetworkRequests ;
77+ return this . #networkRequestsOptions ?. include ?? false ;
7178 }
7279
7380 get includeConsoleData ( ) : boolean {
@@ -77,7 +84,7 @@ export class McpResponse implements Response {
7784 return this . #attachedNetworkRequestUrl;
7885 }
7986 get networkRequestsPageIdx ( ) : number | undefined {
80- return this . #networkRequestsPaginationOptions ?. pageIdx ;
87+ return this . #networkRequestsOptions ?. pagination ?. pageIdx ;
8188 }
8289
8390 appendResponseLine ( value : string ) : void {
@@ -179,25 +186,35 @@ Call browser_handle_dialog to handle it before continuing.`);
179186
180187 response . push ( ...this . #getIncludeNetworkRequestsData( context ) ) ;
181188
182- if ( this . #includeNetworkRequests) {
183- const requests = context . getNetworkRequests ( ) ;
189+ if ( this . #networkRequestsOptions?. include ) {
190+ let requests = context . getNetworkRequests ( ) ;
191+
192+ // Apply resource type filtering if specified
193+ if ( this . #networkRequestsOptions. resourceTypes ) {
194+ const normalizedTypes = new Set ( this . #networkRequestsOptions. resourceTypes ) ;
195+ requests = requests . filter ( request => {
196+ const type = request . resourceType ( ) ;
197+ return normalizedTypes . has ( type ) ;
198+ } ) ;
199+ }
200+
184201 response . push ( '## Network requests' ) ;
185202 if ( requests . length ) {
186203 const paginationResult = paginate (
187204 requests ,
188- this . #networkRequestsPaginationOptions ,
205+ this . #networkRequestsOptions . pagination ,
189206 ) ;
190207 if ( paginationResult . invalidPage ) {
191208 response . push ( 'Invalid page number provided. Showing first page.' ) ;
192209 }
193210
194- const { startIndex, endIndex, currentPage, totalPages} =
211+ const { startIndex, endIndex, currentPage, totalPages } =
195212 paginationResult ;
196213 response . push (
197214 `Showing ${ startIndex + 1 } -${ endIndex } of ${ requests . length } (Page ${ currentPage + 1 } of ${ totalPages } ).` ,
198215 ) ;
199216
200- if ( this . #networkRequestsPaginationOptions ) {
217+ if ( this . #networkRequestsOptions . pagination ) {
201218 if ( paginationResult . hasNextPage ) {
202219 response . push ( `Next page: ${ currentPage + 1 } ` ) ;
203220 }
0 commit comments