MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / generateCli

Function generateCli

scripts/generate-cli.ts:108–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108async function generateCli() {
109 const tools = await fetchTools();
110
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
120 // Sort tools by name
121 const sortedTools = tools
122 .sort((a, b) => a.name.localeCompare(b.name))
123 .filter(tool => {
124 // Skipping fill_form because it is not relevant in shell scripts
125 // and CLI does not handle array/JSON args well.
126 if (tool.name === 'fill_form') {
127 return false;
128 }
129 // Skipping wait_for because CLI does not handle array/JSON args well
130 // and shell scripts have many mechanisms for waiting.
131 if (tool.name === 'wait_for') {
132 return false;
133 }
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 }
142 return true;
143 });
144
145 const commands: Record<
146 string,
147 {description: string; category: string; args: Record<string, CliOption>}
148 > = {};
149
150 for (const tool of sortedTools) {
151 const options = schemaToCLIOptions(tool.inputSchema);
152 const args: Record<string, CliOption> = {};
153 for (const opt of options) {
154 args[opt.name] = opt;
155 }
156
157 const categoryEnum = toolNameToCategoryEnum.get(tool.name);
158 if (!categoryEnum) {
159 throw new Error(`Tool ${tool.name} has no category.`);
160 }
161 const category = labels[categoryEnum as unknown as keyof typeof labels];
162 if (!tool.description) {
163 throw new Error(`Tool ${tool.name} is missing description`);
164 }
165

Callers 1

generate-cli.tsFile · 0.85

Calls 7

fetchToolsFunction · 0.85
createToolsFunction · 0.85
parseArgumentsFunction · 0.85
schemaToCLIOptionsFunction · 0.85
buildFlagFunction · 0.85
sortMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected