get_usage_stats
Retrieve usage statistics for debugging and analysis. Provides tool usage summaries, success/failure rates, and performance metrics to monitor system operations.
Instructions
Get usage statistics for debugging and analysis.
Returns summary of tool usage, success/failure rates, and performance metrics.
This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/usage.ts:7-26 (handler)The handler function that implements the core logic of the get_usage_stats tool. It retrieves usage summary from the tracker and returns it formatted as ServerResult, handling errors gracefully.export async function getUsageStats(): Promise<ServerResult> { try { const summary = await usageTracker.getUsageSummary(); return { content: [{ type: "text", text: summary }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving usage stats: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/tools/schemas.ts:137-137 (schema)Zod schema for input arguments of get_usage_stats tool (empty object since no arguments required).export const GetUsageStatsArgsSchema = z.object({});
- src/server.ts:934-946 (registration)Tool registration in the ListToolsRequest handler: defines the tool name, description, input schema, and annotations for the MCP tools list.name: "get_usage_stats", description: ` Get usage statistics for debugging and analysis. Returns summary of tool usage, success/failure rates, and performance metrics. ${CMD_PREFIX_DESCRIPTION}`, inputSchema: zodToJsonSchema(GetUsageStatsArgsSchema), annotations: { title: "Get Usage Statistics", readOnlyHint: true, }, },
- src/server.ts:1122-1131 (registration)Tool execution handler in the CallToolRequest switch statement: calls the getUsageStats function directly (no args parsing needed) and handles errors.case "get_usage_stats": try { result = await getUsageStats(); } catch (error) { capture('server_request_error', { message: `Error in get_usage_stats handler: ${error}` }); result = { content: [{ type: "text", text: `Error: Failed to get usage statistics` }], isError: true, }; }
- src/utils/usageTracker.ts:365-396 (helper)Supporting utility method in usageTracker that generates the formatted usage summary string returned by the tool.async getUsageSummary(): Promise<string> { const stats = await this.getStats(); const now = Date.now(); const daysSinceFirst = Math.round((now - stats.firstUsed) / (1000 * 60 * 60 * 24)); const uniqueTools = Object.keys(stats.toolCounts).length; const successRate = stats.totalToolCalls > 0 ? Math.round((stats.successfulCalls / stats.totalToolCalls) * 100) : 0; const topTools = Object.entries(stats.toolCounts) .sort(([,a], [,b]) => b - a) .slice(0, 5) .map(([tool, count]) => `${tool}: ${count}`) .join(', '); return `📊 **Usage Summary** • Total calls: ${stats.totalToolCalls} (${stats.successfulCalls} successful, ${stats.failedCalls} failed) • Success rate: ${successRate}% • Days using: ${daysSinceFirst} • Sessions: ${stats.totalSessions} • Unique tools: ${uniqueTools} • Most used: ${topTools || 'None'} • Feedback given: ${(await configManager.getValue('feedbackGiven')) ? 'Yes' : 'No'} **By Category:** • Filesystem: ${stats.filesystemOperations} • Terminal: ${stats.terminalOperations} • Editing: ${stats.editOperations} • Search: ${stats.searchOperations} • Config: ${stats.configOperations} • Process: ${stats.processOperations}`; }