get_usage
Retrieve token usage summaries for OpenAI and Claude APIs to monitor consumption and manage costs.
Instructions
Get usage summary
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_usage"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No | User ID (optional) |
Implementation Reference
- src/mcp-server.ts:270-301 (handler)The primary handler function for the 'get_usage' tool. Processes arguments to retrieve and format usage summary for a specific user_id or all users, returning structured content with token counts and costs.
private getUsage(args: any) { const { user_id } = args; if (user_id) { const usage = this.tracker.getUserUsage(user_id); if (!usage) { return { content: [{ type: 'text', text: `No usage data for ${user_id}` }] }; } let summary = `📊 Usage Summary for ${user_id}\n`; summary += `Total: ${usage.totalTokens} tokens (${formatCost(usage.totalCost)})\n\n`; Object.entries(usage.usageByModel).forEach(([model, data]) => { summary += `${model}: ${data.tokens} tokens (${formatCost(data.cost)})\n`; }); return { content: [{ type: 'text', text: summary }] }; } else { const allUsage = this.tracker.getAllUsersUsage(); let summary = '📊 All Users:\n'; allUsage.forEach(user => { summary += `${user.userId}: ${user.totalTokens} tokens (${formatCost(user.totalCost)})\n`; }); return { content: [{ type: 'text', text: summary || 'No usage data' }] }; } } - src/mcp-server.ts:100-112 (registration)Tool registration in ListToolsRequestSchema handler, defining name, description, and input schema for 'get_usage'.
{ name: 'get_usage', description: 'Get usage summary', inputSchema: { type: 'object', properties: { user_id: { type: 'string', description: 'User ID (optional)' } } } }, - src/mcp-server.ts:164-165 (registration)Dispatch routing in CallToolRequestSchema handler that maps 'get_usage' tool calls to the getUsage method.
case 'get_usage': return this.getUsage(request.params.arguments); - src/mcp-server.ts:103-110 (schema)Input schema definition for the get_usage tool, specifying optional user_id parameter.
inputSchema: { type: 'object', properties: { user_id: { type: 'string', description: 'User ID (optional)' } }