From 98486ad208c32ec767376dae088db75b22cfab80 Mon Sep 17 00:00:00 2001 From: Yi LIU Date: Mon, 16 Feb 2026 15:33:51 +0800 Subject: [PATCH] fix: apply pagination to network request output Network request pagination was only cosmetic - the pagination header showed "Showing 1-10 of 30" but all 30 requests were rendered in both the text and structured content output. The format() method was computing pagination on raw requests but then iterating over all pre-built NetworkFormatter instances from handle(). Fix by applying pagination to the formatter array directly, matching the pattern already used by console message pagination. Also removed a redundant re-fetch of network requests in format() since the formatters from handle() already contain the filtered data. --- src/McpResponse.ts | 33 +--- tests/McpResponse.test.js.snapshot | 294 ----------------------------- 2 files changed, 9 insertions(+), 318 deletions(-) diff --git a/src/McpResponse.ts b/src/McpResponse.ts index 0ec11b541..8abce9f87 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -589,36 +589,21 @@ Call ${handleDialog.name} to handle it before continuing.`); } if (this.#networkRequestsOptions?.include) { - let requests = context.getNetworkRequests( - this.#networkRequestsOptions?.includePreservedRequests, - ); - - // Apply resource type filtering if specified - if (this.#networkRequestsOptions.resourceTypes?.length) { - const normalizedTypes = new Set( - this.#networkRequestsOptions.resourceTypes, - ); - requests = requests.filter(request => { - const type = request.resourceType(); - return normalizedTypes.has(type); - }); - } - response.push('## Network requests'); - if (requests.length) { + const networkFormatters = data.networkRequests ?? []; + if (networkFormatters.length) { const paginationData = this.#dataWithPagination( - requests, + networkFormatters, this.#networkRequestsOptions.pagination, ); structuredContent.pagination = paginationData.pagination; response.push(...paginationData.info); - if (data.networkRequests) { - structuredContent.networkRequests = []; - for (const formatter of data.networkRequests) { - response.push(formatter.toString()); - structuredContent.networkRequests.push(formatter.toJSON()); - } - } + structuredContent.networkRequests = paginationData.items.map( + formatter => formatter.toJSON(), + ); + response.push( + ...paginationData.items.map(formatter => formatter.toString()), + ); } else { response.push('No requests found.'); } diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshot index e11f94941..48c677d0c 100644 --- a/tests/McpResponse.test.js.snapshot +++ b/tests/McpResponse.test.js.snapshot @@ -483,27 +483,6 @@ exports[`McpResponse network pagination > handles invalid page number by showing "invalidPage": true }, "networkRequests": [ - { - "requestId": 1, - "method": "GET", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, { "requestId": 1, "method": "GET", @@ -654,146 +633,6 @@ exports[`McpResponse network pagination > returns first page by default 1`] = ` "url": "http://example.com", "status": "[pending]", "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-10", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-11", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-12", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-13", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-14", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-15", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-16", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-17", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-18", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-19", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-20", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-21", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-22", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-23", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-24", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-25", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-26", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-27", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-28", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-29", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false } ] } @@ -811,76 +650,6 @@ exports[`McpResponse network pagination > returns subsequent page when pageIdx p "invalidPage": false }, "networkRequests": [ - { - "requestId": 1, - "method": "GET-0", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-1", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-2", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-3", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-4", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-5", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-6", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-7", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-8", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-9", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, { "requestId": 1, "method": "GET-10", @@ -950,41 +719,6 @@ exports[`McpResponse network pagination > returns subsequent page when pageIdx p "url": "http://example.com", "status": "[pending]", "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-20", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-21", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-22", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-23", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false - }, - { - "requestId": 1, - "method": "GET-24", - "url": "http://example.com", - "status": "[pending]", - "selectedInDevToolsUI": false } ] } @@ -1445,31 +1179,3 @@ No requests found. exports[`McpResponse network request filtering > shows no requests when filter matches nothing 2`] = ` {} `; - -exports[`extensions > lists extensions 1`] = ` -# test response -## Extensions -id=id1 "Extension 1" v1.0 Enabled -id=id2 "Extension 2" v2.0 Disabled -`; - -exports[`extensions > lists extensions 2`] = ` -{ - "extensions": [ - { - "id": "id1", - "name": "Extension 1", - "version": "1.0", - "isEnabled": true, - "path": "/path/to/ext1" - }, - { - "id": "id2", - "name": "Extension 2", - "version": "2.0", - "isEnabled": false, - "path": "/path/to/ext2" - } - ] -} -`;