@@ -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 , ToolCategory } from '../build/src/tools/categories.js' ;
14+ import { CONDITION_TO_FLAG , 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 (
@@ -83,10 +88,7 @@ function schemaToCLIOptions(schema: JsonSchema): CliOption[] {
8388 const properties = schema . properties ;
8489 return Object . entries ( properties ) . map ( ( [ name , prop ] ) => {
8590 const isRequired = required . includes ( name ) ;
86- let description = prop . description || '' ;
87- if ( isRequired ) {
88- description += ' (required)' ;
89- }
91+ const description = prop . description || '' ;
9092 if ( typeof prop . type !== 'string' ) {
9193 throw new Error (
9294 `Property ${ name } has a complex type not supported by CLI.` ,
@@ -107,12 +109,12 @@ async function generateCli() {
107109 const tools = await fetchTools ( ) ;
108110
109111 const staticTools = createTools ( parseArguments ( ) ) ;
110- const toolNameToCategory = new Map < string , string > ( ) ;
112+ const toolNameToCategoryEnum = new Map < string , string > ( ) ;
113+ const toolNameToConditions = new Map < string , string [ ] > ( ) ;
114+
111115 for ( const tool of staticTools ) {
112- toolNameToCategory . set (
113- tool . name ,
114- labels [ tool . annotations . category as keyof typeof labels ] ,
115- ) ;
116+ toolNameToCategoryEnum . set ( tool . name , tool . annotations . category ) ;
117+ toolNameToConditions . set ( tool . name , tool . annotations . conditions || [ ] ) ;
116118 }
117119
118120 // Sort tools by name
@@ -134,7 +136,7 @@ async function generateCli() {
134136 return false ;
135137 }
136138 // Skipping in_page tools as they are not launched yet
137- if ( toolNameToCategory . get ( tool . name ) === labels [ ToolCategory . IN_PAGE ] ) {
139+ if ( toolNameToCategoryEnum . get ( tool . name ) === ToolCategory . IN_PAGE ) {
138140 return false ;
139141 }
140142 return true ;
@@ -151,15 +153,40 @@ async function generateCli() {
151153 for ( const opt of options ) {
152154 args [ opt . name ] = opt ;
153155 }
154- const category = toolNameToCategory . get ( tool . name ) ;
155- if ( ! category ) {
156+
157+ const categoryEnum = toolNameToCategoryEnum . get ( tool . name ) ;
158+ if ( ! categoryEnum ) {
156159 throw new Error ( `Tool ${ tool . name } has no category.` ) ;
157160 }
161+ const category = labels [ categoryEnum as unknown as keyof typeof labels ] ;
158162 if ( ! tool . description ) {
159- throw new Error ( `Tool ${ tool . name } is missing descripttion ` ) ;
163+ throw new Error ( `Tool ${ tool . name } is missing description ` ) ;
160164 }
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` ) ;
173+ }
174+
175+ const conditions = toolNameToConditions . get ( tool . name ) || [ ] ;
176+ for ( const condition of conditions ) {
177+ const flag =
178+ CONDITION_TO_FLAG [ condition as keyof typeof CONDITION_TO_FLAG ] ;
179+ if ( flag ) {
180+ requiredFlags . push ( `--${ flag } =true` ) ;
181+ }
182+ }
183+
184+ if ( requiredFlags . length > 0 ) {
185+ description += ` (requires flag: ${ requiredFlags . join ( ', ' ) } )` ;
186+ }
187+
161188 commands [ tool . name ] = {
162- description : tool . description ,
189+ description,
163190 category,
164191 args,
165192 } ;
0 commit comments