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

Function writeToolCallMetricsConfig

scripts/update_metrics.ts:33–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31}
32
33function writeToolCallMetricsConfig() {
34 const outputPath = path.resolve('src/telemetry/tool_call_metrics.json');
35
36 const dir = path.dirname(outputPath);
37 if (!fs.existsSync(dir)) {
38 throw new Error(`Error: Directory ${dir} does not exist.`);
39 }
40
41 // Avoid 'as ParsedArguments' by using parseArguments
42 const fullTools = createTools(parseArguments('0.0.0', ['', '']));
43 const slimTools = createTools(parseArguments('0.0.0', ['', '', '--slim']));
44
45 const allTools = [...fullTools, ...slimTools];
46
47 if (!HaveUniqueNames(allTools)) {
48 throw new Error('Error: Duplicate tool names found.');
49 }
50
51 let existingMetrics: ToolMetric[] = [];
52 if (fs.existsSync(outputPath)) {
53 try {
54 existingMetrics = JSON.parse(
55 fs.readFileSync(outputPath, 'utf8'),
56 ) as ToolMetric[];
57 } catch {
58 console.warn(
59 `Warning: Failed to parse existing metrics from ${outputPath}. Starting fresh.`,
60 );
61 }
62 }
63
64 const newMetrics = generateToolMetrics(allTools);
65 const mergedMetrics = applyToExistingMetrics(existingMetrics, newMetrics);
66
67 fs.writeFileSync(outputPath, JSON.stringify(mergedMetrics, null, 2) + '\n');
68
69 console.log(
70 `Successfully wrote ${mergedMetrics.length} total tool metrics (including deprecated ones) to ${outputPath}`,
71 );
72}
73
74function writeFlagUsageMetrics() {
75 const outputPath = path.resolve('src/telemetry/flag_usage_metrics.json');

Callers 1

mainFunction · 0.85

Calls 5

createToolsFunction · 0.85
parseArgumentsFunction · 0.85
HaveUniqueNamesFunction · 0.85
generateToolMetricsFunction · 0.85
applyToExistingMetricsFunction · 0.85

Tested by

no test coverage detected