Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
5 changes: 5 additions & 0 deletions src/McpPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ElementHandle,
Page,
Viewport,
WebMCPTool,
} from './third_party/index.js';
import type {ToolGroup, ToolDefinition} from './tools/inPage.js';
import {takeSnapshot} from './tools/snapshot.js';
Expand Down Expand Up @@ -78,6 +79,10 @@ export class McpPage implements ContextPage {
return this.inPageTools;
}

getWebMcpTools(): WebMCPTool[] {
return this.pptrPage.webmcp.tools();
}

get networkConditions(): string | null {
return this.emulationSettings.networkConditions ?? null;
}
Expand Down
44 changes: 44 additions & 0 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type {WebMCPTool} from 'puppeteer-core';

import type {ParsedArguments} from './bin/chrome-devtools-mcp-cli-options.js';
import {ConsoleFormatter} from './formatters/ConsoleFormatter.js';
import {IssueFormatter} from './formatters/IssueFormatter.js';
Expand Down Expand Up @@ -181,6 +183,7 @@ export class McpResponse implements Response {
};
#listExtensions?: boolean;
#listInPageTools?: boolean;
#listWebMcpTools?: boolean;
#devToolsData?: DevToolsData;
#tabId?: string;
#args: ParsedArguments;
Expand Down Expand Up @@ -232,6 +235,10 @@ export class McpResponse implements Response {
}
}

setListWebMcpTools(): void {
this.#listWebMcpTools = true;
}

setIncludeNetworkRequests(
value: boolean,
options?: PaginationOptions & {
Expand Down Expand Up @@ -374,6 +381,10 @@ export class McpResponse implements Response {
return this.#snapshotParams;
}

get listWebMcpTools(): boolean | undefined {
return this.#listWebMcpTools;
}

async handle(
toolName: string,
context: McpContext,
Expand Down Expand Up @@ -490,6 +501,12 @@ export class McpResponse implements Response {
page.inPageTools = inPageTools;
}

let webmcpTools: WebMCPTool[] | undefined;
if (this.#listWebMcpTools && this.#args.experimentalWebmcp) {
const page = this.#page ?? context.getSelectedMcpPage();
webmcpTools = page.getWebMcpTools();
}

let consoleMessages: Array<ConsoleFormatter | IssueFormatter> | undefined;
if (this.#consoleDataOptions?.include) {
if (!this.#page) {
Expand Down Expand Up @@ -595,6 +612,7 @@ export class McpResponse implements Response {
extensions,
lighthouseResult: this.#attachedLighthouseResult,
inPageTools,
webmcpTools,
});
}

Expand All @@ -612,6 +630,7 @@ export class McpResponse implements Response {
extensions?: InstalledExtension[];
lighthouseResult?: LighthouseData;
inPageTools?: ToolGroup<ToolDefinition>;
webmcpTools?: WebMCPTool[];
},
): {content: Array<TextContent | ImageContent>; structuredContent: object} {
const structuredContent: {
Expand All @@ -627,6 +646,7 @@ export class McpResponse implements Response {
lighthouseResult?: object;
extensions?: object[];
inPageTools?: object;
webmcpTools?: object[];
message?: string;
networkConditions?: string;
navigationTimeout?: number;
Expand Down Expand Up @@ -884,6 +904,30 @@ Call ${handleDialog.name} to handle it before continuing.`);
}
}

if (this.#listWebMcpTools && data.webmcpTools) {
structuredContent.webmcpTools = data.webmcpTools.map(
({name, description, inputSchema, annotations}) => ({
name,
description,
inputSchema,
annotations,
}),
);
response.push('## WebMCP tools');
if (data.webmcpTools.length === 0) {
response.push('No WebMCP tools available.');
} else {
const webmcpToolsMessage = data.webmcpTools
.map(tool => {
return `name="${tool.name}", description="${tool.description}", inputSchema=${JSON.stringify(
tool.inputSchema,
)}, annotations=${JSON.stringify(tool.annotations)}`;
})
.join('\n');
response.push(webmcpToolsMessage);
}
}

if (this.#networkRequestsOptions?.include && data.networkRequests) {
const requests = data.networkRequests;

Expand Down
5 changes: 5 additions & 0 deletions src/bin/chrome-devtools-mcp-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ export const cliOptions = {
describe:
'Exposes experimental screencast tools (requires ffmpeg). Install ffmpeg https://www.ffmpeg.org/download.html and ensure it is available in the MCP server PATH.',
},
experimentalWebmcp: {
type: 'boolean',
describe: 'Set to true to enable debugging WebMCP tools.',
hidden: true,
},
chromeArg: {
type: 'array',
describe:
Expand Down
1 change: 1 addition & 0 deletions src/bin/chrome-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ delete startCliOptions.viewport;
// tools, they need to be enabled during CLI generation.
delete startCliOptions.experimentalPageIdRouting;
delete startCliOptions.experimentalVision;
delete startCliOptions.experimentalWebmcp;
delete startCliOptions.experimentalInteropTools;
delete startCliOptions.experimentalScreencast;
delete startCliOptions.categoryEmulation;
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export async function createMcpServer(
) {
return;
}
if (
tool.annotations.conditions?.includes('experimentalWebmcp') &&
!serverArgs.experimentalWebmcp
) {
return;
}
const schema =
'pageScoped' in tool &&
tool.pageScoped &&
Expand Down
4 changes: 4 additions & 0 deletions src/telemetry/tool_call_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,9 @@
"argType": "number"
}
]
},
{
"name": "list_webmcp_tools",
"args": []
}
]
1 change: 1 addition & 0 deletions src/tools/ToolDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface Response {
setListExtensions(): void;
attachLighthouseResult(result: LighthouseData): void;
setListInPageTools(): void;
setListWebMcpTools(): void;
}

export type SupportedExtensions =
Expand Down
3 changes: 3 additions & 0 deletions src/tools/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const listPages = defineTool(args => {
handler: async (_request, response) => {
response.setIncludePages(true);
response.setListInPageTools();
response.setListWebMcpTools();
Comment thread
beaufortfrancois marked this conversation as resolved.
},
};
});
Expand Down Expand Up @@ -55,6 +56,7 @@ export const selectPage = defineTool({
context.selectPage(page);
response.setIncludePages(true);
response.setListInPageTools();
response.setListWebMcpTools();
if (request.params.bringToFront) {
await page.pptrPage.bringToFront();
}
Expand Down Expand Up @@ -280,6 +282,7 @@ export const navigatePage = definePageTool({

response.setIncludePages(true);
response.setListInPageTools();
response.setListWebMcpTools();
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/tools/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as scriptTools from './script.js';
import * as slimTools from './slim/tools.js';
import * as snapshotTools from './snapshot.js';
import type {ToolDefinition} from './ToolDefinition.js';
import * as webmcpTools from './webmcp.js';

export const createTools = (args: ParsedArguments) => {
const rawTools = args.slim
Expand All @@ -41,6 +42,7 @@ export const createTools = (args: ParsedArguments) => {
...Object.values(screenshotTools),
...Object.values(scriptTools),
...Object.values(snapshotTools),
...Object.values(webmcpTools),
];

const tools = [];
Expand Down
22 changes: 22 additions & 0 deletions src/tools/webmcp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {ToolCategory} from './categories.js';
import {definePageTool} from './ToolDefinition.js';

export const listWebMcpTools = definePageTool({
name: 'list_webmcp_tools',
description: `Lists all WebMCP tools the page exposes.`,
annotations: {
category: ToolCategory.DEBUGGING,
readOnlyHint: true,
conditions: ['experimentalWebmcp'],
},
schema: {},
handler: async (_request, response, _context) => {
response.setListWebMcpTools();
},
});
110 changes: 110 additions & 0 deletions tests/McpResponse.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -1281,3 +1281,113 @@ exports[`lighthouse > includes lighthouse report paths 2`] = `
}
}
`;

exports[`webmcp > includes webmcp tools in list_pages response 1`] = `
## Pages
1: about:blank [selected]
## WebMCP tools
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
`;

exports[`webmcp > includes webmcp tools in list_pages response 2`] = `
{
"pages": [
{
"id": 1,
"url": "about:blank",
"selected": true
}
],
"webmcpTools": [
{
"name": "test_tool",
"description": "A test tool",
"inputSchema": {}
}
]
}
`;

exports[`webmcp > includes webmcp tools in navigate_page response 1`] = `
Successfully navigated to about:blank.
## Pages
1: about:blank [selected]
## WebMCP tools
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
`;

exports[`webmcp > includes webmcp tools in navigate_page response 2`] = `
{
"message": "Successfully navigated to about:blank.",
"pages": [
{
"id": 1,
"url": "about:blank",
"selected": true
}
],
"webmcpTools": [
{
"name": "test_tool",
"description": "A test tool",
"inputSchema": {}
}
]
}
`;

exports[`webmcp > includes webmcp tools in select_page response 1`] = `
## Pages
1: about:blank [selected]
## WebMCP tools
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
`;

exports[`webmcp > includes webmcp tools in select_page response 2`] = `
{
"pages": [
{
"id": 1,
"url": "about:blank",
"selected": true
}
],
"webmcpTools": [
{
"name": "test_tool",
"description": "A test tool",
"inputSchema": {}
}
]
}
`;

exports[`webmcp > list no webmcp tools if experimentalWebmcp is false 1`] = `
Successfully navigated to about:blank.
## Pages
1: about:blank [selected]
`;

exports[`webmcp > list no webmcp tools if experimentalWebmcp is false 2`] = `
{
"message": "Successfully navigated to about:blank.",
"pages": [
{
"id": 1,
"url": "about:blank",
"selected": true
}
]
}
`;

exports[`webmcp > list no webmcp tools if there are none 1`] = `
## WebMCP tools
No WebMCP tools available.
`;

exports[`webmcp > list no webmcp tools if there are none 2`] = `
{
"webmcpTools": []
}
`;
Loading
Loading