@@ -11,7 +11,12 @@ import {Client} from '@modelcontextprotocol/sdk/client/index.js';
1111import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' ;
1212
1313import { parseArguments } from '../build/src/bin/chrome-devtools-mcp-cli-options.js' ;
14- import { labels } from '../build/src/tools/categories.js' ;
14+ import { buildFlag } from '../build/src/index.js' ;
15+ import {
16+ labels ,
17+ ToolCategory ,
18+ OFF_BY_DEFAULT_CATEGORIES ,
19+ } from '../build/src/tools/categories.js' ;
1520import { createTools } from '../build/src/tools/tools.js' ;
1621
1722const OUTPUT_PATH = path . join (
@@ -29,7 +34,7 @@ async function fetchTools() {
2934
3035 const transport = new StdioClientTransport ( {
3136 command : 'node' ,
32- args : [ serverPath ] ,
37+ args : [ serverPath , '--viaCli' ] ,
3338 env : { ...process . env , CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS : 'true' } ,
3439 } ) ;
3540
@@ -103,6 +108,15 @@ function schemaToCLIOptions(schema: JsonSchema): CliOption[] {
103108async function generateCli ( ) {
104109 const tools = await fetchTools ( ) ;
105110
111+ const staticTools = createTools ( parseArguments ( ) ) ;
112+ const toolNameToCategoryEnum = new Map < string , string > ( ) ;
113+ const toolNameToConditions = new Map < string , string [ ] > ( ) ;
114+
115+ for ( const tool of staticTools ) {
116+ toolNameToCategoryEnum . set ( tool . name , tool . annotations . category ) ;
117+ toolNameToConditions . set ( tool . name , tool . annotations . conditions || [ ] ) ;
118+ }
119+
106120 // Sort tools by name
107121 const sortedTools = tools
108122 . sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
@@ -117,18 +131,17 @@ async function generateCli() {
117131 if ( tool . name === 'wait_for' ) {
118132 return false ;
119133 }
134+ // Skipping get_tab_id as it is for internal integrations
135+ if ( tool . name === 'get_tab_id' ) {
136+ return false ;
137+ }
138+ // Skipping in_page tools as they are not launched yet
139+ if ( toolNameToCategoryEnum . get ( tool . name ) === ToolCategory . IN_PAGE ) {
140+ return false ;
141+ }
120142 return true ;
121143 } ) ;
122144
123- const staticTools = createTools ( parseArguments ( ) ) ;
124- const toolNameToCategory = new Map < string , string > ( ) ;
125- for ( const tool of staticTools ) {
126- toolNameToCategory . set (
127- tool . name ,
128- labels [ tool . annotations . category as keyof typeof labels ] ,
129- ) ;
130- }
131-
132145 const commands : Record <
133146 string ,
134147 { description : string ; category : string ; args : Record < string , CliOption > }
@@ -140,15 +153,36 @@ async function generateCli() {
140153 for ( const opt of options ) {
141154 args [ opt . name ] = opt ;
142155 }
143- const category = toolNameToCategory . get ( tool . name ) ;
144- if ( ! category ) {
156+
157+ const categoryEnum = toolNameToCategoryEnum . get ( tool . name ) ;
158+ if ( ! categoryEnum ) {
145159 throw new Error ( `Tool ${ tool . name } has no category.` ) ;
146160 }
161+ const category = labels [ categoryEnum as unknown as keyof typeof labels ] ;
147162 if ( ! tool . description ) {
148- throw new Error ( `Tool ${ tool . name } is missing descripttion` ) ;
163+ throw new Error ( `Tool ${ tool . name } is missing description` ) ;
164+ }
165+
166+ let description = tool . description ;
167+ const requiredFlags : string [ ] = [ ] ;
168+
169+ const isOffByDefault = OFF_BY_DEFAULT_CATEGORIES . includes ( categoryEnum ) ;
170+ if ( isOffByDefault ) {
171+ const categoryFlag = buildFlag ( categoryEnum ) ;
172+ requiredFlags . push ( `--${ categoryFlag } =true` ) ;
149173 }
174+
175+ const conditions = toolNameToConditions . get ( tool . name ) || [ ] ;
176+ for ( const condition of conditions ) {
177+ requiredFlags . push ( `--${ condition } =true` ) ;
178+ }
179+
180+ if ( requiredFlags . length > 0 ) {
181+ description += ` (requires flag: ${ requiredFlags . join ( ', ' ) } )` ;
182+ }
183+
150184 commands [ tool . name ] = {
151- description : tool . description ,
185+ description,
152186 category,
153187 args,
154188 } ;
0 commit comments