44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7+ import type { WebMCPTool } from 'puppeteer-core' ;
8+
79import type { ParsedArguments } from './bin/chrome-devtools-mcp-cli-options.js' ;
810import { ConsoleFormatter } from './formatters/ConsoleFormatter.js' ;
911import { IssueFormatter } from './formatters/IssueFormatter.js' ;
@@ -181,6 +183,7 @@ export class McpResponse implements Response {
181183 } ;
182184 #listExtensions?: boolean ;
183185 #listInPageTools?: boolean ;
186+ #listWebMcpTools?: boolean ;
184187 #devToolsData?: DevToolsData ;
185188 #tabId?: string ;
186189 #args: ParsedArguments ;
@@ -232,6 +235,10 @@ export class McpResponse implements Response {
232235 }
233236 }
234237
238+ setListWebMcpTools ( ) : void {
239+ this . #listWebMcpTools = true ;
240+ }
241+
235242 setIncludeNetworkRequests (
236243 value : boolean ,
237244 options ?: PaginationOptions & {
@@ -374,6 +381,10 @@ export class McpResponse implements Response {
374381 return this . #snapshotParams;
375382 }
376383
384+ get listWebMcpTools ( ) : boolean | undefined {
385+ return this . #listWebMcpTools;
386+ }
387+
377388 async handle (
378389 toolName : string ,
379390 context : McpContext ,
@@ -490,6 +501,12 @@ export class McpResponse implements Response {
490501 page . inPageTools = inPageTools ;
491502 }
492503
504+ let webmcpTools : WebMCPTool [ ] | undefined ;
505+ if ( this . #listWebMcpTools && this . #args. experimentalWebmcp ) {
506+ const page = this . #page ?? context . getSelectedMcpPage ( ) ;
507+ webmcpTools = page . getWebMcpTools ( ) ;
508+ }
509+
493510 let consoleMessages : Array < ConsoleFormatter | IssueFormatter > | undefined ;
494511 if ( this . #consoleDataOptions?. include ) {
495512 if ( ! this . #page) {
@@ -595,6 +612,7 @@ export class McpResponse implements Response {
595612 extensions,
596613 lighthouseResult : this . #attachedLighthouseResult,
597614 inPageTools,
615+ webmcpTools,
598616 } ) ;
599617 }
600618
@@ -612,6 +630,7 @@ export class McpResponse implements Response {
612630 extensions ?: InstalledExtension [ ] ;
613631 lighthouseResult ?: LighthouseData ;
614632 inPageTools ?: ToolGroup < ToolDefinition > ;
633+ webmcpTools ?: WebMCPTool [ ] ;
615634 } ,
616635 ) : { content : Array < TextContent | ImageContent > ; structuredContent : object } {
617636 const structuredContent : {
@@ -627,6 +646,7 @@ export class McpResponse implements Response {
627646 lighthouseResult ?: object ;
628647 extensions ?: object [ ] ;
629648 inPageTools ?: object ;
649+ webmcpTools ?: object [ ] ;
630650 message ?: string ;
631651 networkConditions ?: string ;
632652 navigationTimeout ?: number ;
@@ -884,6 +904,30 @@ Call ${handleDialog.name} to handle it before continuing.`);
884904 }
885905 }
886906
907+ if ( this . #listWebMcpTools && data . webmcpTools ) {
908+ structuredContent . webmcpTools = data . webmcpTools . map (
909+ ( { name, description, inputSchema, annotations} ) => ( {
910+ name,
911+ description,
912+ inputSchema,
913+ annotations,
914+ } ) ,
915+ ) ;
916+ response . push ( '## WebMCP tools' ) ;
917+ if ( data . webmcpTools . length === 0 ) {
918+ response . push ( 'No WebMCP tools available.' ) ;
919+ } else {
920+ const webmcpToolsMessage = data . webmcpTools
921+ . map ( tool => {
922+ return `name="${ tool . name } ", description="${ tool . description } ", inputSchema=${ JSON . stringify (
923+ tool . inputSchema ,
924+ ) } , annotations=${ JSON . stringify ( tool . annotations ) } `;
925+ } )
926+ . join ( '\n' ) ;
927+ response . push ( webmcpToolsMessage ) ;
928+ }
929+ }
930+
887931 if ( this . #networkRequestsOptions?. include && data . networkRequests ) {
888932 const requests = data . networkRequests ;
889933
0 commit comments