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

Function getToolsAndCategories

scripts/generate-docs.ts:339–409  ·  view source on GitHub ↗
(tools: AnyToolDefinition[])

Source from the content-addressed store, hash-verified

337}
338
339function getToolsAndCategories(tools: AnyToolDefinition[]) {
340 // Convert ToolDefinitions to ToolWithAnnotations
341 const toolsWithAnnotations: ToolWithAnnotations[] = tools
342 .filter(tool => {
343 // Skipping in_page tools as they are not launched yet
344 if (tool.annotations.category === ToolCategory.IN_PAGE) {
345 return false;
346 }
347
348 // Skipping tools behind internal flags.
349 if (requiresHiddenFlag(tool)) {
350 return false;
351 }
352
353 // Skipping internal interop tools not meant for public documentation
354 const skipTools = ['get_tab_id'];
355 if (skipTools.includes(tool.name)) {
356 return false;
357 }
358
359 return true;
360 })
361 .map(tool => {
362 const inputSchema = zod.toJSONSchema(zod.object(tool.schema), {
363 io: 'input',
364 }) as ToolWithAnnotations['inputSchema'];
365
366 return {
367 name: tool.name,
368 description: tool.description,
369 inputSchema,
370 annotations: tool.annotations,
371 };
372 });
373 // Group tools by category (based on annotations)
374 const categories: Record<string, ToolWithAnnotations[]> = {};
375 toolsWithAnnotations.forEach((tool: ToolWithAnnotations) => {
376 const category = tool.annotations?.category || 'Uncategorized';
377 if (!categories[category]) {
378 categories[category] = [];
379 }
380 categories[category].push(tool);
381 });
382
383 // Sort categories using the enum order
384 const categoryOrder = Object.values(ToolCategory);
385 const sortedCategories = Object.keys(categories).sort((a, b) => {
386 const aOff = isCategoryOffByDefault(a);
387 const bOff = isCategoryOffByDefault(b);
388
389 if (aOff !== bOff) {
390 return aOff ? 1 : -1;
391 }
392
393 const aIndex = categoryOrder.indexOf(a as ToolCategory);
394 const bIndex = categoryOrder.indexOf(b as ToolCategory);
395
396 // Put known categories first, unknown categories last

Callers 1

Calls 2

requiresHiddenFlagFunction · 0.85
isCategoryOffByDefaultFunction · 0.85

Tested by

no test coverage detected