Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: allow for the structured reply in mcp (#38938)

Pavel Feldman4cc0c547c776
diff --git a/packages/playwright/src/mcp/browser/browserServerBackend.ts b/packages/playwright/src/mcp/browser/browserServerBackend.ts
index a9e576e043..a66e770612 100644
--- a/packages/playwright/src/mcp/browser/browserServerBackend.ts
+++ b/packages/playwright/src/mcp/browser/browserServerBackend.ts
@@ -17,7 +17,7 @@
import { FullConfig } from './config';
import { Context } from './context';
import { logUnhandledError } from '../log';
-import { Response } from './response';
+import { Response, serializeResponse, serializeStructuredResponse } from './response';
import { SessionLog } from './sessionLog';
import { browserTools, filteredTools } from './tools';
import { toMcpTool } from '../sdk/tool';
@@ -33,11 +33,13 @@ export class BrowserServerBackend implements ServerBackend {
private _sessionLog: SessionLog | undefined;
private _config: FullConfig;
private _browserContextFactory: BrowserContextFactory;
+ private _isStructuredOutput: boolean;
- constructor(config: FullConfig, factory: BrowserContextFactory, options: { allTools?: boolean } = {}) {
+ constructor(config: FullConfig, factory: BrowserContextFactory, options: { allTools?: boolean, structuredOutput?: boolean } = {}) {
this._config = config;
this._browserContextFactory = factory;
this._tools = options.allTools ? browserTools : filteredTools(config);
+ this._isStructuredOutput = options.structuredOutput ?? false;
}
async initialize(clientInfo: mcpServer.ClientInfo): Promise<void> {
@@ -69,7 +71,11 @@ export class BrowserServerBackend implements ServerBackend {
let responseObject: mcpServer.CallToolResult;
try {
await tool.handle(context, parsedArguments, response);
- responseObject = await response.build();
+ const sections = await response.build();
+ if (this._isStructuredOutput)
+ responseObject = await serializeStructuredResponse(sections);
+ else
+ responseObject = await serializeResponse(context, sections, context.firstRootPath());
this._sessionLog?.logResponse(name, parsedArguments, responseObject);
} catch (error: any) {
return {
diff --git a/packages/playwright/src/mcp/browser/response.ts b/packages/playwright/src/mcp/browser/response.ts
index 242d780d5c..55b2225507 100644
--- a/packages/playwright/src/mcp/browser/response.ts
+++ b/packages/playwright/src/mcp/browser/response.ts
@@ -20,6 +20,7 @@ import path from 'path';
import { debug } from 'playwright-core/lib/utilsBundle';
import { renderModalStates, shouldIncludeMessage } from './tab';
import { dateAsFileName } from './tools/utils';
+import { scaleImageToFitMessage } from './tools/screenshot';
import type { TabHeader } from './tab';
import type { CallToolResult, ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js';
@@ -28,17 +29,28 @@ import type { Context } from './context';
export const requestDebug = debug('pw:mcp:request');
type Result = {
- data: Buffer | string;
+ text?: string;
+ data?: Buffer;
+ isBase64?: boolean;
title: string;
- filename?: string;
+ file?: {
+ prefix: string;
+ ext: string;
+ suggestedFilename?: string;
+ contentType?: string;
+ };
+};
+
+export type Section = {
+ title: string;
+ content: Result[];
+ isError?: boolean;
};
export class Response {
- private _ordinal: number;
private _results: Result[] = [];
private _errors: string[] = [];
private _code: string[] = [];
- private _images: { contentType: string, data: Buffer }[] = [];
private _context: Context;
private _includeSnapshot: 'none' | 'full' | 'incremental' = 'none';
private _includeSnapshotFileName: string | undefined;
@@ -47,7 +59,6 @@ export class Response {
readonly toolArgs: Record<string, any>;
private constructor(ordinal: number, context: Context, toolName: string, toolArgs: Record<string, any>) {
- this._ordinal = ordinal;
this._context = context;
this.toolName = toolName;
this.toolArgs = toolArgs;
@@ -59,23 +70,17 @@ export class Response {
return new Response(++Response._ordinal, context, toolName, toolArgs);
}
- addTextResult(result: string) {
- this._results.push({ title: '', data: result });
+ addTextResult(text: string) {
+ this._results.push({ title: '', text });
}
- async addResult(title: string, data: string | Buffer, file: { prefix: string, ext: string, suggestedFilename?: string }) {
- let filename: string | undefined;
- if (!file.suggestedFilename) {
- // Binary always goes into a file.
- if (typeof data !== 'string')
- filename = dateAsFileName(file.prefix, file.ext);
- // What can go into a file goes into a file in outputMode === file.
- if (this._context.config.outputMode === 'file')
- filename = dateAsFileName(file.prefix, file.ext);
- } else {
- filename = await this._context.outputFile(file.suggestedFilename, { origin: 'llm', title });
- }
- this._results.push({ data, title, filename });
+ async addResult(title: string, data: string | Buffer, file: Result['file']) {
+ this._results.push({
+ text: typeof data === 'string' ? data : undefined,
+ data: typeof data === 'string' ? undefined : data,
+ title,
+ file
+ });
}
addError(error: string) {
@@ -86,10 +91,6 @@ export class Response {
this._code.push(code);
}
- addImage(image: { contentType: string, data: Buffer }) {
- this._images.push(image);
- }
-
setIncludeSnapshot() {
this._includeSnapshot = this._context.config.snapshot.mode;
}
@@ -99,94 +100,63 @@ export class Response {
this._includeSnapshotFileName = includeSnapshotFileName;
}
- async build(): Promise<{ content: (TextContent | ImageContent)[], isError?: boolean }> {
+ async build(): Promise<Section[]> {
const rootPath = this._context.firstRootPath();
- const sections: { title: string, content: string[] }[] = [];
- const addSection = (title: string): string[] => {
- const section = { title, content: [] as string[] };
+ const sections: Section[] = [];
+ const addSection = (title: string) => {
+ const section = { title, content: [] as Result[], isError: title === 'Error' };
sections.push(section);
return section.content;
};
if (this._errors.length) {
- const text = addSection('Error');
- text.push('### Error');
- text.push(this._errors.join('\n'));
+ const content = addSection('Error');
+ content.push({ text: this._errors.join('\n'), title: 'error' });
}
- // Results
if (this._results.length) {
- const text = addSection('Result');
- for (const result of this._results) {
- if (result.filename) {
- text.push(`- [${result.title}](${rootPath ? path.relative(rootPath, result.filename) : result.filename})`);
- if (typeof result.data === 'string')
- await fs.promises.writeFile(result.filename, this._redactText(result.data), 'utf-8');
- else
- await fs.promises.writeFile(result.filename, result.data);
- } else if (typeof result.data === 'string' && result.data.trim()) {
- text.push(result.data);
- }
- }
+ const content = addSection('Result');
+ content.push(...this._results);
}
+
// Code
if (this._context.config.codegen !== 'none' && this._code.length) {
- const text = addSection('Ran Playwright code');
- text.push(...this._code);
+ const content = addSection('Ran Playwright code');
+ for (const code of this._code)
+ content.push({ text: code, title: 'code' });
}
// Render tab titles upon changes or when more than one tab.
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot() : undefined;
const tabHeaders = await Promise.all(this._context.tabs().map(tab => tab.headerSnapshot()));
- if (tabHeaders.some(header => header.changed)) {
+ if (this._includeSnapshot !== 'none' || tabHeaders.some(header => header.changed)) {
if (tabHeaders.length !== 1) {
- const text = addSection('Open tabs');
- text.push(...renderTabsMarkdown(tabHeaders));
+ const content = addSection('Open tabs');
+ content.push({ text: renderTabsMarkdown(tabHeaders).join('\n'), title: 'Open tabs' });
}
- const text = addSection('Page');
- text.push(...renderTabMarkdown(tabHeaders[0]));
+ const content = addSection('Page');
+ content.push({ text: renderTabMarkdown(tabHeaders[0]).join('\n'), title: 'Page' });
}
// Handle modal states.
if (tabSnapshot?.modalStates.length) {
- const text = addSection('Modal state');
- text.push(...renderModalStates(this._context.config, tabSnapshot.modalStates));
+ const content = addSection('Modal state');
+ content.push({ text: renderModalStates(this._context.config, tabSnapshot.modalStates).join('\n'), title: 'Modal state' });
}
// Handle tab snapshot
- if (tabSnapshot && this._includeSnapshot === 'full') {
- let fileName: string | undefined;
- if (this._includeSnapshotFileName)
- fileName = await this._context.outputFile(this._includeSnapshotFileName, { origin: 'llm', title: 'Saved snapshot' });
- else if (this._context.config.outputMode === 'file')
- fileName = await this._context.outputFile(dateAsFileName('snapshot', 'yml'), { origin: 'code', title: 'Saved snapshot' });
- if (fileName) {
- await fs.promises.writeFile(fileName, tabSnapshot.ariaSnapshot, 'utf-8');
- const text = addSection('Snapshot');
- text.push(`- File: ${rootPath ? path.relative(rootPath, fileName) : fileName}`);
- } else {
- const text = addSection('Snapshot');
- text.push('```yaml');
- text.push(tabSnapshot.ariaSnapshot);
- text.push('```');
- }
- }
-
- if (tabSnapshot && this._includeSnapshot === 'incremental') {
- const text = addSection('Snapshot');
- text.push('```yaml');
- if (tabSnapshot.ariaSnapshotDiff !== undefined)
- text.push(tabSnapshot.ariaSnapshotDiff);
- else
- text.push(tabSnapshot.ariaSnapshot);
- text.push('```');
+ if (tabSnapshot && this._includeSnapshot !== 'none') {
+ const content = addSection('Snapshot');
+ const snapshot = this._includeSnapshot === 'full' ? tabSnapshot.ariaSnapshot : tabSnapshot.ariaSnapshotDiff ?? tabSnapshot.ariaSnapshot;
+ content.push({ text: snapshot, title: 'snapshot', file: { prefix: 'page', ext: 'yml', suggestedFilename: this._includeSnapshotFileName } });
}
// Handle tab log
if (tabSnapshot?.events.filter(event => event.type !== 'request').length) {
- const text = addSection('Events');
+ const content = addSection('Events');
+ const text: string[] = [];
for (const event of tabSnapshot.events) {
if (event.type === 'console') {
if (shouldIncludeMessage(this._context.config.console.level, event.message.type))
@@ -197,39 +167,9 @@ export class Response {
text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${rootPath ? path.relative(rootPath, event.download.outputFile) : event.download.outputFile}"`);
}
}
+ content.push({ text: text.join('\n'), title: 'events' });
}
-
- const allText = sections.flatMap(section => {
- const content: string[] = [];
- content.push(`### ${section.title}`);
- content.push(...section.content);
- content.push('');
- return content;
- }).join('\n');
-
- const content: (TextContent | ImageContent)[] = [
- {
- type: 'text',
- text: this._redactText(allText)
- },
- ];
-
- // Image attachments.
- if (this._context.config.imageResponses !== 'omit') {
- for (const image of this._images)
- content.push({ type: 'image', data: image.data.toString('base64'), mimeType: image.contentType });
- }
-
- return {
- content,
- ...this._errors.length > 0 ? { isError: true } : {},
- };
- }
-
- private _redactText(text: string): string {
- for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {}))
- text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
- return text;
+ return sections;
}
}
@@ -276,6 +216,76 @@ function parseSections(text: string): Map<string, string> {
return sections;
}
+export async function serializeResponse(context: Context, sections: Section[], rootPath?: string): Promise<CallToolResult> {
+ const redactText = (text: string): string => {
+ for (const [secretName, secretValue] of Object.entries(context.config.secrets ?? {}))
+ text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
+ return text;
+ };
+
+ const text: string[] = [];
+ for (const section of sections) {
+ text.push(`### ${section.title}`);
+ for (const result of section.content) {
+ if (!result.file) {
+ if (result.text !== undefined)
+ text.push(result.text);
+ continue;
+ }
+
+ if (result.file.suggestedFilename || context.config.outputMode === 'file' || result.data) {
+ const generatedFileName = await context.outputFile(dateAsFileName(result.file.prefix, result.file.ext), { origin: 'code', title: section.title });
+ const fileName = result.file.suggestedFilename ? await context.outputFile(result.file.suggestedFilename, { origin: 'llm', title: section.title }) : generatedFileName;
+ text.push(`- [${result.title}](${rootPath ? path.relative(rootPath, fileName) : fileName})`);
+ if (result.data)
+ await fs.promises.writeFile(fileName, result.data, 'utf-8');
+ else
+ await fs.promises.writeFile(fileName, result.text!);
+ } else {
+ if (result.file.ext === 'yml')
+ text.push(`\`\`\`yaml\n${result.text!}\n\`\`\``);
+ else
+ text.push(result.text!);
+ }
+ }
+ }
+ const content: (TextContent | ImageContent)[] = [
+ {
+ type: 'text',
+ text: redactText(text.join('\n')),
+ }
+ ];
+
+ // Image attachments.
+ if (context.config.imageResponses !== 'omit') {
+ for (const result of sections.flatMap(section => section.content).filter(result => result.file?.contentType)) {
+ const scaledData = scaleImageToFitMessage(result.data as Buffer, result.file!.contentType === 'image/png' ? 'png' : 'jpeg');
+ content.push({ type: 'image', data: scaledData.toString('base64'), mimeType: result.file!.contentType! });
+ }
+ }
+
+ return {
+ content,
+ ...(sections.some(section => section.isError) ? { isError: true } : {}),
+ };
+}
+
+export async function serializeStructuredResponse(sections: Section[]): Promise<CallToolResult> {
+ for (const section of sections) {
+ for (const result of section.content) {
+ if (!result.data)
+ continue;
+ result.isBase64 = true;
+ result.text = result.data.toString('base64');
+ result.data = undefined;
+ }
+ }
+ return {
+ content: [{ type: 'text' as const, text: '', _meta: { sections } }],
+ isError: sections.some(section => section.isError),
+ };
+}
+
export function parseResponse(response: CallToolResult) {
if (response.content?.[0].type !== 'text')
return undefined;
diff --git a/packages/playwright/src/mcp/browser/tools/screenshot.ts b/packages/playwright/src/mcp/browser/tools/screenshot.ts
index 8dbfd2e68f..898b05473b 100644
--- a/packages/playwright/src/mcp/browser/tools/screenshot.ts
+++ b/packages/playwright/src/mcp/browser/tools/screenshot.ts
@@ -66,12 +66,8 @@ const screenshot = defineTabTool({
else
response.addCode(`await page.screenshot(${formatObject({ ...options, path: suggestedFilename })});`);
- await response.addResult(`Screenshot of ${screenshotTarget}`, data, { prefix: ref ? 'element' : 'page', ext: fileType, suggestedFilename });
-
- response.addImage({
- contentType: fileType === 'png' ? 'image/png' : 'image/jpeg',
- data: scaleImageToFitMessage(data, fileType)
- });
+ const contentType = fileType === 'png' ? 'image/png' : 'image/jpeg';
+ await response.addResult(`Screenshot of ${screenshotTarget}`, data, { prefix: ref ? 'element' : 'page', ext: fileType, suggestedFilename, contentType });
}
});
diff --git a/packages/playwright/src/mcp/program.ts b/packages/playwright/src/mcp/program.ts
index e8d8312434..274dbb662d 100644
--- a/packages/playwright/src/mcp/program.ts
+++ b/packages/playwright/src/mcp/program.ts
@@ -17,7 +17,6 @@
/* eslint-disable no-console */
import fs from 'fs';
-import path from 'path';
import { colors, ProgramOption } from 'playwright-core/lib/utilsBundle';
import { registry } from 'playwright-core/lib/server';
@@ -43,6 +42,7 @@ export function decorateCommand(command: Command, version: string) {
.option('--caps <caps>', 'comma-separated list of additional capabilities to enable, possible values: vision, pdf.', commaSeparatedList)
.option('--cdp-endpoint <endpoint>', 'CDP endpoint to connect to.')
.option('--cdp-header <headers...>', 'CDP headers to send with the connect request, multiple can be specified.', headerParser)
+ .option('--codegen <lang>', 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', enumParser.bind(null, '--codegen', ['none', 'typescript']))
.option('--config <path>', 'path to the configuration file.')
.option('--console-level <level>', 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', enumParser.bind(null, '--console-level', ['error', 'warning', 'info', 'debug']))
.option('--device <device>', 'device to emulate, for example: "iPhone 15"')
@@ -75,7 +75,6 @@ export function decorateCommand(command: Command, version: string) {
.option('--user-agent <ua string>', 'specify user agent string')
.option('--user-data-dir <path>', 'path to the user data directory. If not specified, a temporary directory will be created.')
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280x720"', resolutionParser.bind(null, '--viewport-size'))
- .option('--codegen <lang>', 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', enumParser.bind(null, '--codegen', ['none', 'typescript']))
.addOption(new ProgramOption('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
.addOption(new ProgramOption('--daemon <socket>', 'run as daemon').hideHelp())
.action(async options => {
@@ -113,7 +112,6 @@ export function decorateCommand(command: Command, version: string) {
if (options.daemon) {
config.skillMode = true;
- config.outputDir = path.join(process.cwd(), '.playwright-cli');
config.outputMode = 'file';
config.codegen = 'none';
config.snapshot.mode = 'full';
@@ -122,7 +120,7 @@ export function decorateCommand(command: Command, version: string) {
name: 'Playwright',
nameInConfig: 'playwright-daemon',
version,
- create: () => new BrowserServerBackend(config, browserContextFactory, { allTools: true })
+ create: () => new BrowserServerBackend(config, browserContextFactory, { allTools: true, structuredOutput: true })
};
const socketPath = await startMcpDaemonServer(options.daemon, serverBackendFactory);
console.error(`Daemon server listening on ${socketPath}`);
diff --git a/packages/playwright/src/mcp/terminal/daemon.ts b/packages/playwright/src/mcp/terminal/daemon.ts
index 637b42ab18..f7c0786025 100644
--- a/packages/playwright/src/mcp/terminal/daemon.ts
+++ b/packages/playwright/src/mcp/terminal/daemon.ts
@@ -29,6 +29,8 @@ import { parseCommand } from './command';
import type { ServerBackendFactory } from '../sdk/server';
import type * as mcp from '../sdk/exports';
+import type { StructuredResponse } from './program';
+import type { Section } from '../browser/response';
const daemonDebug = debug('pw:daemon');
@@ -116,15 +118,11 @@ export async function startMcpDaemonServer(
});
}
-function formatResult(result: mcp.CallToolResult) {
- const lines = [];
- for (const content of result.content) {
- if (content.type === 'text')
- lines.push(content.text);
- else
- lines.push(`<${content.type} content>`);
- }
- return lines.join('\n');
+function formatResult(result: mcp.CallToolResult): StructuredResponse {
+ const isError = result.isError;
+ const text = result.content[0].type === 'text' ? result.content[0].text : undefined;
+ const sections = result.content[0]._meta?.sections as Section[];
+ return { isError, text, sections };
}
function parseCliCommand(args: Record<string, string> & { _: string[] }): { toolName: string, toolParams: mcp.CallToolRequest['params']['arguments'] } {
diff --git a/packages/playwright/src/mcp/terminal/program.ts b/packages/playwright/src/mcp/terminal/program.ts
index 90ec315c20..5a8a74c81c 100644
--- a/packages/playwright/src/mcp/terminal/program.ts
+++ b/packages/playwright/src/mcp/terminal/program.ts
@@ -28,6 +28,13 @@ import { debug } from 'playwright-core/lib/utilsBundle';
import { SocketConnection } from './socketConnection';
import type { SpawnOptions } from 'child_process';
+import type { Section } from '../browser/response';
+
+export type StructuredResponse = {
+ isError?: boolean;
+ text?: string;
+ sections: Section[];
+};
const debugCli = debug('pw:cli');
@@ -44,7 +51,7 @@ class Session {
this._connection.onclose = () => this.close();
}
- async run(args: any): Promise<string> {
+ async run(args: any) {
return await this._send('run', { args });
}
@@ -113,7 +120,7 @@ class SessionManager {
const sessionName = this._resolveSessionName(args.session);
const session = await this._connect(sessionName);
const result = await session.run(args);
- console.log(result);
+ await printResponse(result);
session.close();
}
@@ -341,3 +348,69 @@ export async function program(options: { version: string }) {
await sessionManager.run(args);
}
+
+export async function printResponse(response: StructuredResponse) {
+ const { sections } = response;
+ if (!sections) {
+ console.log('### Error\n' + response.text);
+ return;
+ }
+
+ const text: string[] = [];
+ for (const section of sections) {
+ text.push(`### ${section.title}`);
+ for (const result of section.content) {
+ if (!result.file) {
+ if (result.text !== undefined)
+ text.push(result.text);
+ continue;
+ }
+
+ const generatedFileName = await outputFile(dateAsFileName(result.file.prefix, result.file.ext), { origin: 'code' });
+ const fileName = result.file.suggestedFilename ? await outputFile(result.file.suggestedFilename, { origin: 'llm' }) : generatedFileName;
+ text.push(`- [${result.title}](${path.relative(process.cwd(), fileName)})`);
+ if (result.data)
+ await fs.promises.writeFile(fileName, result.data);
+ else if (result.isBase64)
+ await fs.promises.writeFile(fileName, Buffer.from(result.text!, 'base64'));
+ else
+ await fs.promises.writeFile(fileName, result.text!);
+ }
+ }
+ console.log(text.join('\n'));
+}
+
+function dateAsFileName(prefix: string, extension: string): string {
+ const date = new Date();
+ return `${prefix}-${date.toISOString().replace(/[:.]/g, '-')}.${extension}`;
+}
+
+const outputDir = path.join(process.cwd(), '.playwright-cli');
+
+async function outputFile(fileName: string, options: { origin: 'code' | 'llm' | 'web' }): Promise<string> {
+ await fs.promises.mkdir(outputDir, { recursive: true });
+
+ // Trust code.
+ if (options.origin === 'code')
+ return path.resolve(outputDir, fileName);
+
+ // Trust llm to use valid characters in file names.
+ if (options.origin === 'llm') {
+ fileName = fileName.split('\\').join('/');
+ const resolvedFile = path.resolve(outputDir, fileName);
+ if (!resolvedFile.startsWith(path.resolve(outputDir) + path.sep))
+ throw new Error(`Resolved file path ${resolvedFile} is outside of the output directory ${outputDir}. Use relative file names to stay within the output directory.`);
+ return resolvedFile;
+ }
+
+ // Do not trust web, at all.
+ return path.join(outputDir, sanitizeForFilePath(fileName));
+}
+
+function sanitizeForFilePath(s: string) {
+ const sanitize = (s: string) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
+ const separator = s.lastIndexOf('.');
+ if (separator === -1)
+ return sanitize(s);
+ return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
+}
diff --git a/tests/mcp/cli-fixtures.ts b/tests/mcp/cli-fixtures.ts
index 40ad1aa525..3e6536d496 100644
--- a/tests/mcp/cli-fixtures.ts
+++ b/tests/mcp/cli-fixtures.ts
@@ -115,12 +115,12 @@ export function loadAttachments(output: string) {
}
export async function loadSnapshot(output: string) {
- const match = output.match(/- File: (.+)/m);
- if (!match)
+ const lines = output.split('\n');
+ if (!lines.includes('### Snapshot'))
throw new Error('Snapshot file not found');
- const snapshotPath = match[1];
- const fileName = test.info().outputPath(snapshotPath);
- return await fs.promises.readFile(fileName, 'utf8');
+ const fileLine = lines[lines.indexOf('### Snapshot') + 1];
+ const fileName = fileLine.match(/- \[(.+)\]\((.+)\)/)![2];
+ return await fs.promises.readFile(test.info().outputPath(fileName), 'utf8');
}
export const eventsPage = `<!DOCTYPE html>
diff --git a/tests/mcp/core.spec.ts b/tests/mcp/core.spec.ts
index 57ab3ad88e..3832e4a2eb 100644
--- a/tests/mcp/core.spec.ts
+++ b/tests/mcp/core.spec.ts
@@ -116,7 +116,6 @@ test('browser_select_option', async ({ client, server }) => {
values: ['bar'],
},
})).toHaveResponse({
- page: undefined, // Did not change.
snapshot: `\`\`\`yaml
- <changed> combobox [ref=e2]:
- option "Foo"
@@ -149,7 +148,6 @@ test('browser_select_option (multiple)', async ({ client, server }) => {
},
})).toHaveResponse({
code: `await page.getByRole('listbox').selectOption(['bar', 'baz']);`,
- page: undefined, // did not change
snapshot: `\`\`\`yaml
- <changed> option "Bar" [selected] [ref=e4]
- <changed> option "Baz" [selected] [ref=e5]
diff --git a/tests/mcp/session-log.spec.ts b/tests/mcp/session-log.spec.ts
index eaffa5a026..d080d5b045 100644
--- a/tests/mcp/session-log.spec.ts
+++ b/tests/mcp/session-log.spec.ts
@@ -77,6 +77,7 @@ test('session log should record tool calls', async ({ startClient, server, mcpBr
\`\`\`json
{
"code": "await page.getByRole('button', { name: 'Submit' }).click();",
+ "page": "- Page URL: http://localhost:${server.PORT}/\\n- Page Title: Title",
"snapshot": "\`\`\`yaml\\n- <changed> button \\"Submit\\" [active] [ref=e2]\\n\`\`\`"
}
\`\`\`
diff --git a/tests/mcp/snapshot-mode.spec.ts b/tests/mcp/snapshot-mode.spec.ts
index bf692dedb0..65be63d38a 100644
--- a/tests/mcp/snapshot-mode.spec.ts
+++ b/tests/mcp/snapshot-mode.spec.ts
@@ -134,7 +134,7 @@ test('should respect snapshot[filename]', async ({ startClient, server }, testIn
arguments: {
filename: 'snapshot1.yml',
},
- })).toHaveTextResponse(expect.stringContaining('- File: output' + path.sep + 'snapshot1.yml'));
+ })).toHaveTextResponse(expect.stringContaining('output' + path.sep + 'snapshot1.yml'));
expect(await fs.promises.readFile(path.join(outputDir, 'snapshot1.yml'), 'utf8')).toContain(`- button "Button 1" [ref=e2]`);
});