@@ -15,8 +15,9 @@ import { formatA11ySnapshot } from './formatters/snapshotFormatter.js';
1515import { formatConsoleEvent } from './formatters/consoleFormatter.js' ;
1616import {
1717 paginateNetworkRequests ,
18- type NetworkPaginationOptions ,
19- } from './utils/networkPagination.js' ;
18+ type NetworkRequestsListingOptions ,
19+ sanitizeRequestTypeFilter ,
20+ } from './utils/networkUtils.js' ;
2021
2122export class McpResponse implements Response {
2223 #includePages: boolean = false ;
@@ -27,7 +28,7 @@ export class McpResponse implements Response {
2728 #textResponseLines: string [ ] = [ ] ;
2829 #formattedConsoleData?: string [ ] ;
2930 #images: ImageContentData [ ] = [ ] ;
30- #networkRequestsPaginationOptions?: NetworkPaginationOptions ;
31+ #networkRequestsPaginationOptions?: NetworkRequestsListingOptions ;
3132
3233 setIncludePages ( value : boolean ) : void {
3334 this . #includePages = value ;
@@ -39,7 +40,7 @@ export class McpResponse implements Response {
3940
4041 setIncludeNetworkRequests (
4142 value : boolean ,
42- options ?: { pageSize ?: number ; pageToken ?: string | null } ,
43+ options ?: NetworkRequestsListingOptions ,
4344 ) : void {
4445 this . #includeNetworkRequests = value ;
4546 if ( ! value ) {
@@ -52,13 +53,21 @@ export class McpResponse implements Response {
5253 return ;
5354 }
5455
55- const sanitizedOptions : NetworkPaginationOptions = { } ;
56+ const sanitizedOptions : NetworkRequestsListingOptions = { } ;
5657 if ( options . pageSize !== undefined ) {
5758 sanitizedOptions . pageSize = options . pageSize ;
5859 }
5960 if ( options . pageToken !== undefined ) {
6061 sanitizedOptions . pageToken = options . pageToken ?? undefined ;
6162 }
63+ if ( options . requestType !== undefined ) {
64+ const sanitizedRequestType = sanitizeRequestTypeFilter (
65+ options . requestType ,
66+ ) ;
67+ if ( sanitizedRequestType !== undefined ) {
68+ sanitizedOptions . requestType = sanitizedRequestType ;
69+ }
70+ }
6271
6372 this . #networkRequestsPaginationOptions =
6473 Object . keys ( sanitizedOptions ) . length > 0 ? sanitizedOptions : undefined ;
@@ -193,18 +202,33 @@ Call browser_handle_dialog to handle it before continuing.`);
193202 if ( this . #includeNetworkRequests) {
194203 const requests = context . getNetworkRequests ( ) ;
195204 response . push ( '## Network requests' ) ;
196- if ( requests . length ) {
197- const paginationResult = paginateNetworkRequests (
198- requests ,
199- this . #networkRequestsPaginationOptions,
200- ) ;
201- if ( paginationResult . invalidToken ) {
202- response . push ( 'Invalid page token provided. Showing first page.' ) ;
205+ const paginationOptions = this . #networkRequestsPaginationOptions;
206+ const paginationResult = paginateNetworkRequests (
207+ requests ,
208+ paginationOptions ,
209+ ) ;
210+
211+ if ( paginationResult . appliedRequestType ) {
212+ const summary = Array . isArray ( paginationResult . appliedRequestType )
213+ ? paginationResult . appliedRequestType . join ( ', ' )
214+ : paginationResult . appliedRequestType ;
215+ response . push ( `Filtered by type: ${ summary } ` ) ;
216+ }
217+
218+ if ( paginationResult . invalidToken ) {
219+ response . push ( 'Invalid page token provided. Showing first page.' ) ;
220+ }
221+
222+ const { startIndex, endIndex, total } = paginationResult ;
223+ if ( total === 0 ) {
224+ if ( paginationOptions ?. requestType ) {
225+ response . push ( 'No requests found for the selected type(s).' ) ;
226+ } else {
227+ response . push ( 'No requests found.' ) ;
203228 }
204- const { startIndex, endIndex } = paginationResult ;
205- response . push (
206- `Showing ${ startIndex + 1 } -${ endIndex } of ${ requests . length } .` ,
207- ) ;
229+ }
230+ else {
231+ response . push ( `Showing ${ startIndex + 1 } -${ endIndex } of ${ total } .` ) ;
208232 for ( const request of paginationResult . requests ) {
209233 response . push ( getShortDescriptionForRequest ( request ) ) ;
210234 }
@@ -214,8 +238,6 @@ Call browser_handle_dialog to handle it before continuing.`);
214238 if ( paginationResult . previousPageToken ) {
215239 response . push ( `Prev: ${ paginationResult . previousPageToken } ` ) ;
216240 }
217- } else {
218- response . push ( 'No requests found.' ) ;
219241 }
220242 }
221243
0 commit comments