MCPcopy Create free account
hub / github.com/echoVic/blade-code / statsExample

Function statsExample

examples/tools-example.ts:304–335  ·  view source on GitHub ↗

* 工具统计示例

()

Source from the content-addressed store, hash-verified

302 * 工具统计示例
303 */
304async function statsExample() {
305 console.log('=== 工具统计示例 ===\n');
306
307 const toolManager = await createToolManager();
308
309 // 执行一些工具调用以产生统计数据
310 await toolManager.callTool({
311 toolName: 'uuid',
312 parameters: { count: 1 },
313 });
314
315 await toolManager.callTool({
316 toolName: 'timestamp',
317 parameters: { operation: 'now' },
318 });
319
320 // 获取统计信息
321 const stats = toolManager.getStats();
322 console.log('工具统计信息:');
323 console.log(JSON.stringify(stats, null, 2));
324 console.log('');
325
326 // 获取执行历史
327 const history = toolManager.getExecutionHistory(5);
328 console.log('最近执行历史:');
329 history.forEach((record, index) => {
330 console.log(
331 `${index + 1}. ${record.toolName} - ${record.result.success ? '成功' : '失败'} (${record.result.duration}ms)`
332 );
333 });
334 console.log('');
335}
336
337/**
338 * 主函数

Callers 1

mainFunction · 0.85

Calls 5

createToolManagerFunction · 0.85
logMethod · 0.45
callToolMethod · 0.45
getStatsMethod · 0.45
getExecutionHistoryMethod · 0.45

Tested by

no test coverage detected