Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export class McpResponse implements Response {
extensionServiceWorkers?: object[];
} = {};

const response = [`# ${toolName} response`];
const response = [];
if (this.#textResponseLines.length) {
structuredContent.message = this.#textResponseLines.join('\n');
response.push(...this.#textResponseLines);
Expand All @@ -512,38 +512,33 @@ export class McpResponse implements Response {
const networkConditions = this.#page?.networkConditions;
if (networkConditions) {
const timeout = this.#page!.pptrPage.getDefaultNavigationTimeout();
response.push(`## Network emulation`);
response.push(`Emulating: ${networkConditions}`);
response.push(`Emulating network conditions: ${networkConditions}`);
response.push(`Default navigation timeout set to ${timeout} ms`);
structuredContent.networkConditions = networkConditions;
structuredContent.navigationTimeout = timeout;
}

const viewport = this.#page?.viewport;
if (viewport) {
response.push(`## Viewport emulation`);
response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);
structuredContent.viewport = viewport;
}

const userAgent = this.#page?.userAgent;
if (userAgent) {
response.push(`## UserAgent emulation`);
response.push(`Emulating userAgent: ${userAgent}`);
response.push(`Emulating user agent: ${userAgent}`);
structuredContent.userAgent = userAgent;
}

const cpuThrottlingRate = this.#page?.cpuThrottlingRate ?? 1;
if (cpuThrottlingRate > 1) {
response.push(`## CPU emulation`);
response.push(`Emulating: ${cpuThrottlingRate}x slowdown`);
response.push(`Emulating CPU throttling: ${cpuThrottlingRate}x slowdown`);
structuredContent.cpuThrottlingRate = cpuThrottlingRate;
}

const colorScheme = this.#page?.colorScheme;
if (colorScheme) {
response.push(`## Color Scheme emulation`);
response.push(`Emulating: ${colorScheme}`);
response.push(`Emulating color scheme: ${colorScheme}`);
structuredContent.colorScheme = colorScheme;
}

Expand Down
62 changes: 25 additions & 37 deletions tests/McpResponse.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
exports[`McpResponse > add network request when attached 1`] = `
# test response
## Request http://example.com
Status: pending
### Request Headers
Expand Down Expand Up @@ -42,7 +41,6 @@ exports[`McpResponse > add network request when attached 2`] = `
`;

exports[`McpResponse > add network request when attached with POST data 1`] = `
# test response
## Request http://example.com
Status: 200
### Request Headers
Expand Down Expand Up @@ -96,7 +94,6 @@ exports[`McpResponse > add network request when attached with POST data 2`] = `
`;

exports[`McpResponse > add network requests when setting is true 1`] = `
# test response
## Network requests
Showing 1-2 of 2 (Page 1 of 1).
reqid=1 GET http://example.com [pending]
Expand Down Expand Up @@ -134,7 +131,6 @@ exports[`McpResponse > add network requests when setting is true 2`] = `
`;

exports[`McpResponse > adds a message when no console messages exist 1`] = `
# test response
## Console messages
<no console messages found>
`;
Expand All @@ -144,7 +140,6 @@ exports[`McpResponse > adds a message when no console messages exist 2`] = `
`;

exports[`McpResponse > adds a prompt dialog 1`] = `
# test response
# Open dialog
prompt: message (default value: "default").
Call handle_dialog to handle it before continuing.
Expand All @@ -161,7 +156,6 @@ exports[`McpResponse > adds a prompt dialog 2`] = `
`;

exports[`McpResponse > adds an alert dialog 1`] = `
# test response
# Open dialog
alert: message.
Call handle_dialog to handle it before continuing.
Expand All @@ -178,9 +172,7 @@ exports[`McpResponse > adds an alert dialog 2`] = `
`;

exports[`McpResponse > adds color scheme emulation setting when it is set 1`] = `
# test response
## Color Scheme emulation
Emulating: dark
Emulating color scheme: dark
`;

exports[`McpResponse > adds color scheme emulation setting when it is set 2`] = `
Expand All @@ -190,7 +182,6 @@ exports[`McpResponse > adds color scheme emulation setting when it is set 2`] =
`;

exports[`McpResponse > adds console messages when the setting is true 1`] = `
# test response
## Console messages
Showing 1-1 of 1 (Page 1 of 1).
msgid=1 [log] Hello from the test (1 args)
Expand Down Expand Up @@ -219,9 +210,7 @@ exports[`McpResponse > adds console messages when the setting is true 2`] = `
`;

exports[`McpResponse > adds cpu throttling setting when it is over 1 1`] = `
# test response
## CPU emulation
Emulating: 4x slowdown
Emulating CPU throttling: 4x slowdown
`;

exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = `
Expand All @@ -231,13 +220,15 @@ exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = `
`;

exports[`McpResponse > adds image when image is attached 1`] = `

`;

exports[`McpResponse > adds image when image is attached 2`] = `
{}
`;

exports[`McpResponse > adds throttling setting when it is not null 1`] = `
# test response
## Network emulation
Emulating: Slow 3G
Emulating network conditions: Slow 3G
Default navigation timeout set to 100000 ms
`;

Expand All @@ -249,9 +240,7 @@ exports[`McpResponse > adds throttling setting when it is not null 2`] = `
`;

exports[`McpResponse > adds userAgent emulation setting when it is set 1`] = `
# test response
## UserAgent emulation
Emulating userAgent: MyUA
Emulating user agent: MyUA
`;

exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = `
Expand All @@ -261,8 +250,6 @@ exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = `
`;

exports[`McpResponse > adds viewport emulation setting when it is set 1`] = `
# test response
## Viewport emulation
Emulating viewport: {"deviceScaleFactor":1,"isMobile":false,"hasTouch":false,"isLandscape":false,"width":400,"height":400}
`;

Expand All @@ -280,7 +267,6 @@ exports[`McpResponse > adds viewport emulation setting when it is set 2`] = `
`;

exports[`McpResponse > allows response text lines to be added 1`] = `
# test response
Testing 1
Testing 2
`;
Expand All @@ -292,18 +278,34 @@ exports[`McpResponse > allows response text lines to be added 2`] = `
`;

exports[`McpResponse > does not include anything in response if snapshot is null 1`] = `

`;

exports[`McpResponse > does not include anything in response if snapshot is null 2`] = `
{}
`;

exports[`McpResponse > does not include cpu throttling setting when it is 1 1`] = `

`;

exports[`McpResponse > does not include cpu throttling setting when it is 1 2`] = `
{}
`;

exports[`McpResponse > does not include network requests when setting is false 1`] = `

`;

exports[`McpResponse > does not include network requests when setting is false 2`] = `
{}
`;

exports[`McpResponse > does not include throttling setting when it is null 1`] = `

`;

exports[`McpResponse > does not include throttling setting when it is null 2`] = `
{}
`;

Expand All @@ -312,7 +314,6 @@ exports[`McpResponse > doesn't list the issue message if mapping returns null 1`
`;

exports[`McpResponse > list pages 1`] = `
# test response
## Pages
1: about:blank [selected]
`;
Expand All @@ -330,7 +331,6 @@ exports[`McpResponse > list pages 2`] = `
`;

exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `
# test response
## Latest page snapshot
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 button "Click me" focusable focused
Expand Down Expand Up @@ -364,7 +364,6 @@ exports[`McpResponse > returns correctly formatted snapshot for a simple tree 2`
`;

exports[`McpResponse > returns values for textboxes 1`] = `
# test response
## Latest page snapshot
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 StaticText "username"
Expand Down Expand Up @@ -399,7 +398,6 @@ exports[`McpResponse > returns values for textboxes 2`] = `
`;

exports[`McpResponse > returns verbose snapshot and structured content 1`] = `
# test response
## Latest page snapshot
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 ignored
Expand Down Expand Up @@ -454,7 +452,6 @@ exports[`McpResponse > returns verbose snapshot and structured content 2`] = `
`;

exports[`McpResponse > saves snapshot to file and returns structured content 1`] = `
# test response
Saved snapshot to <file>
`;

Expand Down Expand Up @@ -728,7 +725,6 @@ exports[`McpResponse network pagination > returns subsequent page when pageIdx p
`;

exports[`McpResponse network pagination > trace insights > includes error if insight not found 1`] = `
# test response
No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.
`;

Expand All @@ -737,7 +733,6 @@ exports[`McpResponse network pagination > trace insights > includes error if ins
`;

exports[`McpResponse network pagination > trace insights > includes the trace insight output 1`] = `
# test response
## Insight Title: LCP breakdown

## Insight Summary:
Expand Down Expand Up @@ -787,7 +782,6 @@ exports[`McpResponse network pagination > trace insights > includes the trace in
`;

exports[`McpResponse network pagination > trace summaries > includes the trace summary text and structured data 1`] = `
# test response
## Summary of Performance trace findings:
URL: https://web.dev/
Trace bounds: {min: 122410994891, max: 122416385853}
Expand Down Expand Up @@ -982,7 +976,6 @@ exports[`McpResponse network pagination > trace summaries > includes the trace s
`;

exports[`McpResponse network request filtering > filters network requests by resource type 1`] = `
# test response
## Network requests
Showing 1-2 of 2 (Page 1 of 1).
reqid=1 GET http://example.com [pending]
Expand Down Expand Up @@ -1020,7 +1013,6 @@ exports[`McpResponse network request filtering > filters network requests by res
`;

exports[`McpResponse network request filtering > filters network requests by single resource type 1`] = `
# test response
## Network requests
Showing 1-1 of 1 (Page 1 of 1).
reqid=1 GET http://example.com [pending]
Expand Down Expand Up @@ -1050,7 +1042,6 @@ exports[`McpResponse network request filtering > filters network requests by sin
`;

exports[`McpResponse network request filtering > shows all requests when empty resourceTypes array is provided 1`] = `
# test response
## Network requests
Showing 1-5 of 5 (Page 1 of 1).
reqid=1 GET http://example.com [pending]
Expand Down Expand Up @@ -1112,7 +1103,6 @@ exports[`McpResponse network request filtering > shows all requests when empty r
`;

exports[`McpResponse network request filtering > shows all requests when no filters are provided 1`] = `
# test response
## Network requests
Showing 1-5 of 5 (Page 1 of 1).
reqid=1 GET http://example.com [pending]
Expand Down Expand Up @@ -1174,15 +1164,14 @@ exports[`McpResponse network request filtering > shows all requests when no filt
`;

exports[`McpResponse network request filtering > shows no requests when filter matches nothing 1`] = `
# test response

`;

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
Expand Down Expand Up @@ -1210,7 +1199,6 @@ exports[`extensions > lists extensions 2`] = `
`;

exports[`lighthouse > includes lighthouse report paths 1`] = `
# test response
## Lighthouse Audit Results
Mode: navigation
Device: desktop
Expand Down
13 changes: 5 additions & 8 deletions tests/McpResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ describe('McpResponse', () => {
'test',
context,
);
assert.equal(content[0].type, 'text');
assert.deepStrictEqual(getTextContent(content[0]), `# test response`);
t.assert.snapshot?.(getTextContent(content[0]));
t.assert.snapshot?.(
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
);
Expand All @@ -94,7 +93,6 @@ describe('McpResponse', () => {
'test',
context,
);
assert.equal(content[0].type, 'text');
t.assert.snapshot?.(getTextContent(content[0]));
t.assert.snapshot?.(
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
Expand Down Expand Up @@ -303,8 +301,7 @@ describe('McpResponse', () => {
context,
);
await context.emulate({});
assert.equal(content[0].type, 'text');
assert.strictEqual(getTextContent(content[0]), `# test response`);
t.assert.snapshot?.(getTextContent(content[0]));
t.assert.snapshot?.(
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
);
Expand All @@ -317,7 +314,7 @@ describe('McpResponse', () => {
'test',
context,
);
assert.strictEqual(getTextContent(content[0]), `# test response`);
t.assert.snapshot?.(getTextContent(content[0]));
assert.equal(content[1].type, 'image');
assert.strictEqual(getImageContent(content[1]).data, 'imageBase64');
assert.strictEqual(getImageContent(content[1]).mimeType, 'image/png');
Expand Down Expand Up @@ -348,7 +345,7 @@ describe('McpResponse', () => {
'test',
context,
);
assert.strictEqual(getTextContent(content[0]), `# test response`);
t.assert.snapshot?.(getTextContent(content[0]));
t.assert.snapshot?.(
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
);
Expand Down Expand Up @@ -474,7 +471,7 @@ describe('McpResponse', () => {
'test',
context,
);
assert.strictEqual(getTextContent(content[0]), `# test response`);
t.assert.snapshot?.(getTextContent(content[0]));
t.assert.snapshot?.(
JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),
);
Expand Down
7 changes: 7 additions & 0 deletions tests/index.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports[`e2e > calls a tool 1`] = `
[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]
`;

exports[`e2e > calls a tool multiple times 1`] = `
[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]
`;
Loading
Loading