Skip to content

Commit 522374e

Browse files
committed
fix: code formatting
1 parent d870210 commit 522374e

File tree

4 files changed

+81
-78
lines changed

4 files changed

+81
-78
lines changed

src/McpResponse.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import type { ImageContentData, Response } from './tools/ToolDefinition.js';
7-
import type { McpContext } from './McpContext.js';
8-
import { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js';
6+
import type {ImageContentData, Response} from './tools/ToolDefinition.js';
7+
import type {McpContext} from './McpContext.js';
8+
import {ImageContent, TextContent} from '@modelcontextprotocol/sdk/types.js';
99
import {
1010
getFormattedHeaderValue,
1111
getShortDescriptionForRequest,
1212
getStatusFromRequest,
1313
} from './formatters/networkFormatter.js';
14-
import { formatA11ySnapshot } from './formatters/snapshotFormatter.js';
15-
import { formatConsoleEvent } from './formatters/consoleFormatter.js';
16-
import { paginate, type PaginationOptions } from './utils/pagination.js';
14+
import {formatA11ySnapshot} from './formatters/snapshotFormatter.js';
15+
import {formatConsoleEvent} from './formatters/consoleFormatter.js';
16+
import {paginate, type PaginationOptions} from './utils/pagination.js';
1717

1818
export class McpResponse implements Response {
1919
#includePages: boolean = false;
@@ -36,7 +36,7 @@ export class McpResponse implements Response {
3636

3737
setIncludeNetworkRequests(
3838
value: boolean,
39-
options?: { pageSize?: number; pageToken?: string | null },
39+
options?: {pageSize?: number; pageToken?: string | null},
4040
): void {
4141
this.#includeNetworkRequests = value;
4242
if (!value || !options) {
@@ -180,12 +180,15 @@ Call browser_handle_dialog to handle it before continuing.`);
180180
const requests = context.getNetworkRequests();
181181
response.push('## Network requests');
182182
if (requests.length) {
183-
const paginationResult = paginate(requests, this.#networkRequestsPaginationOptions);
183+
const paginationResult = paginate(
184+
requests,
185+
this.#networkRequestsPaginationOptions,
186+
);
184187
if (paginationResult.invalidToken) {
185188
response.push('Invalid page token provided. Showing first page.');
186189
}
187190

188-
const { startIndex, endIndex } = paginationResult;
191+
const {startIndex, endIndex} = paginationResult;
189192
response.push(
190193
`Showing ${startIndex + 1}-${endIndex} of ${requests.length}.`,
191194
);

src/tools/network.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
import z from 'zod';
8-
import { defineTool } from './ToolDefinition.js';
9-
import { ToolCategories } from './categories.js';
8+
import {defineTool} from './ToolDefinition.js';
9+
import {ToolCategories} from './categories.js';
1010

1111
export const listNetworkRequests = defineTool({
1212
name: 'list_network_requests',

src/utils/pagination.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,83 @@
55
*/
66

77
export type PaginationOptions = {
8-
pageSize?: number;
9-
pageToken?: string;
8+
pageSize?: number;
9+
pageToken?: string;
1010
};
1111

1212
export type PaginationResult<TItem> = {
13-
items: readonly TItem[];
14-
nextPageToken?: string;
15-
previousPageToken?: string;
16-
startIndex: number;
17-
endIndex: number;
18-
invalidToken: boolean;
13+
items: readonly TItem[];
14+
nextPageToken?: string;
15+
previousPageToken?: string;
16+
startIndex: number;
17+
endIndex: number;
18+
invalidToken: boolean;
1919
};
2020

2121
const DEFAULT_PAGE_SIZE = 20;
2222

2323
export function paginate<TItem>(
24-
items: readonly TItem[],
25-
options?: PaginationOptions,
24+
items: readonly TItem[],
25+
options?: PaginationOptions,
2626
): PaginationResult<TItem> {
27-
const total = items.length;
28-
29-
if (!options || noPaginationOptions(options)) {
30-
return {
31-
items,
32-
nextPageToken: undefined,
33-
previousPageToken: undefined,
34-
startIndex: 0,
35-
endIndex: total,
36-
invalidToken: false,
37-
};
38-
}
39-
40-
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
41-
const { startIndex, invalidToken } = resolveStartIndex(options.pageToken, total);
42-
43-
const pageItems = items.slice(startIndex, startIndex + pageSize);
44-
const endIndex = startIndex + pageItems.length;
45-
46-
const nextPageToken = endIndex < total ? String(endIndex) : undefined;
47-
const previousPageToken =
48-
startIndex > 0 ? String(Math.max(startIndex - pageSize, 0)) : undefined;
27+
const total = items.length;
4928

29+
if (!options || noPaginationOptions(options)) {
5030
return {
51-
items: pageItems,
52-
nextPageToken,
53-
previousPageToken,
54-
startIndex,
55-
endIndex,
56-
invalidToken,
31+
items,
32+
nextPageToken: undefined,
33+
previousPageToken: undefined,
34+
startIndex: 0,
35+
endIndex: total,
36+
invalidToken: false,
5737
};
38+
}
39+
40+
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
41+
const {startIndex, invalidToken} = resolveStartIndex(
42+
options.pageToken,
43+
total,
44+
);
45+
46+
const pageItems = items.slice(startIndex, startIndex + pageSize);
47+
const endIndex = startIndex + pageItems.length;
48+
49+
const nextPageToken = endIndex < total ? String(endIndex) : undefined;
50+
const previousPageToken =
51+
startIndex > 0 ? String(Math.max(startIndex - pageSize, 0)) : undefined;
52+
53+
return {
54+
items: pageItems,
55+
nextPageToken,
56+
previousPageToken,
57+
startIndex,
58+
endIndex,
59+
invalidToken,
60+
};
5861
}
5962

6063
function noPaginationOptions(options: PaginationOptions): boolean {
61-
return (
62-
options.pageSize === undefined &&
63-
(options.pageToken === undefined || options.pageToken === null)
64-
);
64+
return (
65+
options.pageSize === undefined &&
66+
(options.pageToken === undefined || options.pageToken === null)
67+
);
6568
}
6669

67-
6870
function resolveStartIndex(
69-
pageToken: string | undefined,
70-
total: number,
71+
pageToken: string | undefined,
72+
total: number,
7173
): {
72-
startIndex: number;
73-
invalidToken: boolean;
74+
startIndex: number;
75+
invalidToken: boolean;
7476
} {
75-
if (pageToken === undefined || pageToken === null) {
76-
return { startIndex: 0, invalidToken: false };
77-
}
77+
if (pageToken === undefined || pageToken === null) {
78+
return {startIndex: 0, invalidToken: false};
79+
}
7880

79-
const parsed = Number.parseInt(pageToken, 10);
80-
if (Number.isNaN(parsed) || parsed < 0 || parsed >= total) {
81-
return { startIndex: 0, invalidToken: true };
82-
}
81+
const parsed = Number.parseInt(pageToken, 10);
82+
if (Number.isNaN(parsed) || parsed < 0 || parsed >= total) {
83+
return {startIndex: 0, invalidToken: true};
84+
}
8385

84-
return { startIndex: parsed, invalidToken: false };
86+
return {startIndex: parsed, invalidToken: false};
8587
}
86-
87-

tests/McpResponse.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import { describe, it } from 'node:test';
6+
import {describe, it} from 'node:test';
77
import assert from 'assert';
88

9-
import { getMockRequest, html, withBrowser } from './utils.js';
9+
import {getMockRequest, html, withBrowser} from './utils.js';
1010

1111
describe('McpResponse', () => {
1212
it('list pages', async () => {
@@ -120,7 +120,7 @@ Navigation timeout set to 100000 ms`,
120120
});
121121
it('adds image when image is attached', async () => {
122122
await withBrowser(async (response, context) => {
123-
response.attachImage({ data: 'imageBase64', mimeType: 'image/png' });
123+
response.attachImage({data: 'imageBase64', mimeType: 'image/png'});
124124
const result = await response.handle('test', context);
125125
assert.strictEqual(result[0].text, `# test response`);
126126
assert.equal(result[1].type, 'image');
@@ -267,7 +267,7 @@ Log>`),
267267
describe('McpResponse network pagination', () => {
268268
it('returns all requests when pagination is not provided', async () => {
269269
await withBrowser(async (response, context) => {
270-
const requests = Array.from({ length: 5 }, () => getMockRequest());
270+
const requests = Array.from({length: 5}, () => getMockRequest());
271271
context.getNetworkRequests = () => requests;
272272
response.setIncludeNetworkRequests(true);
273273
const result = await response.handle('test', context);
@@ -280,13 +280,13 @@ describe('McpResponse network pagination', () => {
280280

281281
it('returns first page by default', async () => {
282282
await withBrowser(async (response, context) => {
283-
const requests = Array.from({ length: 30 }, (_, idx) =>
284-
getMockRequest({ method: `GET-${idx}` }),
283+
const requests = Array.from({length: 30}, (_, idx) =>
284+
getMockRequest({method: `GET-${idx}`}),
285285
);
286286
context.getNetworkRequests = () => {
287287
return requests;
288288
};
289-
response.setIncludeNetworkRequests(true, { pageSize: 10 });
289+
response.setIncludeNetworkRequests(true, {pageSize: 10});
290290
const result = await response.handle('test', context);
291291
const text = (result[0].text as string).toString();
292292
assert.ok(text.includes('Showing 1-10 of 30.'));
@@ -297,8 +297,8 @@ describe('McpResponse network pagination', () => {
297297

298298
it('returns subsequent page when token provided', async () => {
299299
await withBrowser(async (response, context) => {
300-
const requests = Array.from({ length: 25 }, (_, idx) =>
301-
getMockRequest({ method: `GET-${idx}` }),
300+
const requests = Array.from({length: 25}, (_, idx) =>
301+
getMockRequest({method: `GET-${idx}`}),
302302
);
303303
context.getNetworkRequests = () => requests;
304304
response.setIncludeNetworkRequests(true, {
@@ -315,7 +315,7 @@ describe('McpResponse network pagination', () => {
315315

316316
it('handles invalid token by showing first page', async () => {
317317
await withBrowser(async (response, context) => {
318-
const requests = Array.from({ length: 5 }, () => getMockRequest());
318+
const requests = Array.from({length: 5}, () => getMockRequest());
319319
context.getNetworkRequests = () => requests;
320320
response.setIncludeNetworkRequests(true, {
321321
pageSize: 2,

0 commit comments

Comments
 (0)