Skip to content

Commit 05df4e9

Browse files
committed
chore: format run
1 parent 429444d commit 05df4e9

File tree

2 files changed

+65
-61
lines changed

2 files changed

+65
-61
lines changed

src/McpResponse.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type {
77
ImageContent,
88
TextContent,
99
} from '@modelcontextprotocol/sdk/types.js';
10-
import type { HTTPRequest, HTTPResponse, ResourceType } from 'puppeteer-core';
10+
import type {HTTPRequest, HTTPResponse, ResourceType} from 'puppeteer-core';
1111

12-
import { formatConsoleEvent } from './formatters/consoleFormatter.js';
12+
import {formatConsoleEvent} from './formatters/consoleFormatter.js';
1313
import {
1414
getFormattedHeaderValue,
1515
getFormattedResponseBody,
@@ -18,14 +18,13 @@ import {
1818
getStatusFromRequest,
1919
BODY_CONTEXT_SIZE_LIMIT,
2020
} from './formatters/networkFormatter.js';
21-
import { formatA11ySnapshot } from './formatters/snapshotFormatter.js';
22-
import { McpContext } from './McpContext.js';
23-
import { handleDialog } from './tools/pages.js';
24-
import type { ImageContentData, Response } from './tools/ToolDefinition.js';
21+
import {formatA11ySnapshot} from './formatters/snapshotFormatter.js';
22+
import type {McpContext} from './McpContext.js';
23+
import {handleDialog} from './tools/pages.js';
24+
import type {ImageContentData, Response} from './tools/ToolDefinition.js';
25+
import {paginate, type PaginationOptions} from './utils/pagination.js';
2526

26-
import { paginate, type PaginationOptions } from './utils/pagination.js';
27-
28-
export type NetworkRequestData = {
27+
export interface NetworkRequestData {
2928
networkRequestUrl: string;
3029
requestBody: string | null;
3130
responseBody: string | null;
@@ -71,9 +70,9 @@ export class McpResponse implements Response {
7170
pagination:
7271
options?.pageSize || options?.pageIdx
7372
? {
74-
pageSize: options.pageSize,
75-
pageIdx: options.pageIdx,
76-
}
73+
pageSize: options.pageSize,
74+
pageIdx: options.pageIdx,
75+
}
7776
: undefined,
7877
resourceTypes: options?.resourceTypes,
7978
};
@@ -87,7 +86,7 @@ export class McpResponse implements Response {
8786
this.#attachedNetworkRequestData = {
8887
networkRequestUrl: url,
8988
responseBody: null,
90-
requestBody: null
89+
requestBody: null,
9190
};
9291
}
9392

@@ -143,10 +142,14 @@ export class McpResponse implements Response {
143142
let formattedConsoleMessages: string[];
144143

145144
if (this.#attachedNetworkRequestData?.networkRequestUrl) {
146-
const request = context.getNetworkRequestByUrl(this.#attachedNetworkRequestData.networkRequestUrl);
145+
const request = context.getNetworkRequestByUrl(
146+
this.#attachedNetworkRequestData.networkRequestUrl,
147+
);
147148

148-
this.#attachedNetworkRequestData.requestBody = await this.processRequestBody(request);
149-
this.#attachedNetworkRequestData.responseBody = await this.processResponseBody(request.response());
149+
this.#attachedNetworkRequestData.requestBody =
150+
await this.processRequestBody(request);
151+
this.#attachedNetworkRequestData.responseBody =
152+
await this.processResponseBody(request.response());
150153
}
151154

152155
if (this.#includeConsoleData) {
@@ -162,7 +165,9 @@ export class McpResponse implements Response {
162165
return this.format(toolName, context);
163166
}
164167

165-
async processResponseBody(httpResponse: HTTPResponse | null): Promise<string | null> {
168+
async processResponseBody(
169+
httpResponse: HTTPResponse | null,
170+
): Promise<string | null> {
166171
if (!httpResponse) {
167172
return null;
168173
}
@@ -178,7 +183,6 @@ export class McpResponse implements Response {
178183
return null;
179184
}
180185

181-
182186
async processRequestBody(httpRequest: HTTPRequest): Promise<string | null> {
183187
if (!httpRequest) {
184188
return null;
@@ -308,7 +312,7 @@ Call ${handleDialog.name} to handle it before continuing.`);
308312
response.push('Invalid page number provided. Showing first page.');
309313
}
310314

311-
const { startIndex, endIndex, currentPage, totalPages } = paginationResult;
315+
const {startIndex, endIndex, currentPage, totalPages} = paginationResult;
312316
response.push(
313317
`Showing ${startIndex + 1}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`,
314318
);
@@ -342,9 +346,9 @@ Call ${handleDialog.name} to handle it before continuing.`);
342346
response.push(line);
343347
}
344348

345-
if(this.#attachedNetworkRequestData?.requestBody) {
349+
if (this.#attachedNetworkRequestData?.requestBody) {
346350
response.push(`### Request Body`);
347-
response.push(this.#attachedNetworkRequestData.requestBody)
351+
response.push(this.#attachedNetworkRequestData.requestBody);
348352
}
349353

350354
const httpResponse = httpRequest.response();
@@ -355,9 +359,9 @@ Call ${handleDialog.name} to handle it before continuing.`);
355359
}
356360
}
357361

358-
if(this.#attachedNetworkRequestData?.responseBody) {
362+
if (this.#attachedNetworkRequestData?.responseBody) {
359363
response.push(`### Response Body`);
360-
response.push(this.#attachedNetworkRequestData.responseBody)
364+
response.push(this.#attachedNetworkRequestData.responseBody);
361365
}
362366

363367
const httpFailure = httpRequest.failure();

tests/McpResponse.test.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import assert from 'node:assert';
7-
import { describe, it } from 'node:test';
7+
import {describe, it} from 'node:test';
88

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

1111
describe('McpResponse', () => {
1212
it('list pages', async () => {
@@ -120,7 +120,7 @@ Default 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');
@@ -207,18 +207,18 @@ http://example.com GET [pending]`,
207207
response.setIncludeNetworkRequests(true);
208208
const httpResponse = getMockResponse();
209209
httpResponse.buffer = () => {
210-
return Promise.resolve(Buffer.from(JSON.stringify({ response: "body" })));
210+
return Promise.resolve(Buffer.from(JSON.stringify({response: 'body'})));
211211
};
212212
httpResponse.headers = () => {
213213
return {
214-
"Content-Type": "application/json"
214+
'Content-Type': 'application/json',
215215
};
216-
}
216+
};
217217
const request = getMockRequest({
218-
method: "POST",
218+
method: 'POST',
219219
hasPostData: true,
220-
postData: JSON.stringify({ request: "body" }),
221-
response: httpResponse
220+
postData: JSON.stringify({request: 'body'}),
221+
response: httpResponse,
222222
});
223223
context.getNetworkRequests = () => {
224224
return [request];
@@ -235,11 +235,11 @@ Status: [success - 200]
235235
### Request Headers
236236
- content-size:10
237237
### Request Body
238-
${JSON.stringify({ request: "body" })}
238+
${JSON.stringify({request: 'body'})}
239239
### Response Headers
240240
- Content-Type:application/json
241241
### Response Body
242-
${JSON.stringify({ response: "body" })}
242+
${JSON.stringify({response: 'body'})}
243243
## Network requests
244244
Showing 1-1 of 1 (Page 1 of 1).
245245
http://example.com POST [success - 200]`,
@@ -318,10 +318,10 @@ describe('McpResponse network request filtering', () => {
318318
});
319319
context.getNetworkRequests = () => {
320320
return [
321-
getMockRequest({ resourceType: 'script' }),
322-
getMockRequest({ resourceType: 'image' }),
323-
getMockRequest({ resourceType: 'stylesheet' }),
324-
getMockRequest({ resourceType: 'document' }),
321+
getMockRequest({resourceType: 'script'}),
322+
getMockRequest({resourceType: 'image'}),
323+
getMockRequest({resourceType: 'stylesheet'}),
324+
getMockRequest({resourceType: 'document'}),
325325
];
326326
};
327327
const result = await response.handle('test', context);
@@ -343,9 +343,9 @@ http://example.com GET [pending]`,
343343
});
344344
context.getNetworkRequests = () => {
345345
return [
346-
getMockRequest({ resourceType: 'script' }),
347-
getMockRequest({ resourceType: 'image' }),
348-
getMockRequest({ resourceType: 'stylesheet' }),
346+
getMockRequest({resourceType: 'script'}),
347+
getMockRequest({resourceType: 'image'}),
348+
getMockRequest({resourceType: 'stylesheet'}),
349349
];
350350
};
351351
const result = await response.handle('test', context);
@@ -366,9 +366,9 @@ http://example.com GET [pending]`,
366366
});
367367
context.getNetworkRequests = () => {
368368
return [
369-
getMockRequest({ resourceType: 'script' }),
370-
getMockRequest({ resourceType: 'image' }),
371-
getMockRequest({ resourceType: 'stylesheet' }),
369+
getMockRequest({resourceType: 'script'}),
370+
getMockRequest({resourceType: 'image'}),
371+
getMockRequest({resourceType: 'stylesheet'}),
372372
];
373373
};
374374
const result = await response.handle('test', context);
@@ -386,11 +386,11 @@ No requests found.`,
386386
response.setIncludeNetworkRequests(true);
387387
context.getNetworkRequests = () => {
388388
return [
389-
getMockRequest({ resourceType: 'script' }),
390-
getMockRequest({ resourceType: 'image' }),
391-
getMockRequest({ resourceType: 'stylesheet' }),
392-
getMockRequest({ resourceType: 'document' }),
393-
getMockRequest({ resourceType: 'font' }),
389+
getMockRequest({resourceType: 'script'}),
390+
getMockRequest({resourceType: 'image'}),
391+
getMockRequest({resourceType: 'stylesheet'}),
392+
getMockRequest({resourceType: 'document'}),
393+
getMockRequest({resourceType: 'font'}),
394394
];
395395
};
396396
const result = await response.handle('test', context);
@@ -415,11 +415,11 @@ http://example.com GET [pending]`,
415415
});
416416
context.getNetworkRequests = () => {
417417
return [
418-
getMockRequest({ resourceType: 'script' }),
419-
getMockRequest({ resourceType: 'image' }),
420-
getMockRequest({ resourceType: 'stylesheet' }),
421-
getMockRequest({ resourceType: 'document' }),
422-
getMockRequest({ resourceType: 'font' }),
418+
getMockRequest({resourceType: 'script'}),
419+
getMockRequest({resourceType: 'image'}),
420+
getMockRequest({resourceType: 'stylesheet'}),
421+
getMockRequest({resourceType: 'document'}),
422+
getMockRequest({resourceType: 'font'}),
423423
];
424424
};
425425
const result = await response.handle('test', context);
@@ -441,7 +441,7 @@ http://example.com GET [pending]`,
441441
describe('McpResponse network pagination', () => {
442442
it('returns all requests when pagination is not provided', async () => {
443443
await withBrowser(async (response, context) => {
444-
const requests = Array.from({ length: 5 }, () => getMockRequest());
444+
const requests = Array.from({length: 5}, () => getMockRequest());
445445
context.getNetworkRequests = () => requests;
446446
response.setIncludeNetworkRequests(true);
447447
const result = await response.handle('test', context);
@@ -454,13 +454,13 @@ describe('McpResponse network pagination', () => {
454454

455455
it('returns first page by default', async () => {
456456
await withBrowser(async (response, context) => {
457-
const requests = Array.from({ length: 30 }, (_, idx) =>
458-
getMockRequest({ method: `GET-${idx}` }),
457+
const requests = Array.from({length: 30}, (_, idx) =>
458+
getMockRequest({method: `GET-${idx}`}),
459459
);
460460
context.getNetworkRequests = () => {
461461
return requests;
462462
};
463-
response.setIncludeNetworkRequests(true, { pageSize: 10 });
463+
response.setIncludeNetworkRequests(true, {pageSize: 10});
464464
const result = await response.handle('test', context);
465465
const text = (result[0].text as string).toString();
466466
assert.ok(text.includes('Showing 1-10 of 30 (Page 1 of 3).'));
@@ -471,8 +471,8 @@ describe('McpResponse network pagination', () => {
471471

472472
it('returns subsequent page when pageIdx provided', async () => {
473473
await withBrowser(async (response, context) => {
474-
const requests = Array.from({ length: 25 }, (_, idx) =>
475-
getMockRequest({ method: `GET-${idx}` }),
474+
const requests = Array.from({length: 25}, (_, idx) =>
475+
getMockRequest({method: `GET-${idx}`}),
476476
);
477477
context.getNetworkRequests = () => requests;
478478
response.setIncludeNetworkRequests(true, {
@@ -489,7 +489,7 @@ describe('McpResponse network pagination', () => {
489489

490490
it('handles invalid page number by showing first page', async () => {
491491
await withBrowser(async (response, context) => {
492-
const requests = Array.from({ length: 5 }, () => getMockRequest());
492+
const requests = Array.from({length: 5}, () => getMockRequest());
493493
context.getNetworkRequests = () => requests;
494494
response.setIncludeNetworkRequests(true, {
495495
pageSize: 2,

0 commit comments

Comments
 (0)