get_current_session
Retrieve current LLM session usage details including remaining tokens, costs, and input/output counts to monitor API consumption.
Instructions
Get current session usage with intuitive format (remaining, used, input/output tokens, cost)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No | User ID (defaults to current-session) | current-session |
| total_budget | No | Total token budget (optional) |
Implementation Reference
- src/mcp-server.ts:206-268 (handler)Main handler function for 'get_current_session' tool. Retrieves user usage from TokenTracker, computes input/output tokens by summing history, calculates remaining budget and progress bar, formats a comprehensive text response with emojis, stats, and optional model breakdown.private getCurrentSession(args: any) { const { user_id = 'current-session', total_budget = 190000 } = args; const usage = this.tracker.getUserUsage(user_id); if (!usage) { return { content: [{ type: 'text', text: `š° Current Session\n` + `āāāāāāāāāāāāāāāāāāāāāā\n` + `š Used: 0 tokens\n` + `⨠Remaining: ${total_budget.toLocaleString()} tokens\n` + `š„ Input: 0 tokens\n` + `š¤ Output: 0 tokens\n` + `šµ Cost: $0.0000\n` + `āāāāāāāāāāāāāāāāāāāāāā\n` + `No usage recorded yet.` }] }; } // Calculate input/output from model breakdown let totalInput = 0; let totalOutput = 0; const history = this.tracker.getUserHistory(user_id); history.forEach(record => { totalInput += record.inputTokens || 0; totalOutput += record.outputTokens || 0; }); const usedTokens = usage.totalTokens; const remaining = Math.max(0, total_budget - usedTokens); const percentUsed = ((usedTokens / total_budget) * 100).toFixed(1); // Progress bar const barLength = 20; const filledLength = Math.round((usedTokens / total_budget) * barLength); const progressBar = 'ā'.repeat(filledLength) + 'ā'.repeat(barLength - filledLength); let result = `š° Current Session\n`; result += `āāāāāāāāāāāāāāāāāāāāāā\n`; result += `š Used: ${usedTokens.toLocaleString()} tokens (${percentUsed}%)\n`; result += `⨠Remaining: ${remaining.toLocaleString()} tokens\n`; result += `[${progressBar}]\n\n`; result += `š„ Input: ${totalInput.toLocaleString()} tokens\n`; result += `š¤ Output: ${totalOutput.toLocaleString()} tokens\n`; result += `šµ Cost: ${formatCost(usage.totalCost)}\n`; result += `āāāāāāāāāāāāāāāāāāāāāā\n`; // Model breakdown if (Object.keys(usage.usageByModel).length > 0) { result += `\nš Model Breakdown:\n`; Object.entries(usage.usageByModel).forEach(([model, data]) => { result += ` ⢠${model}: ${data.tokens.toLocaleString()} tokens (${formatCost(data.cost)})\n`; }); } return { content: [{ type: 'text', text: result }] }; }
- src/mcp-server.ts:84-98 (schema)Input schema definition specifying optional user_id (defaults to 'current-session') and total_budget (defaults to 190000) parameters for the tool.inputSchema: { type: 'object', properties: { user_id: { type: 'string', description: 'User ID (defaults to current-session)', default: 'current-session' }, total_budget: { type: 'number', description: 'Total token budget (optional)', default: 190000 } } }
- src/mcp-server.ts:81-99 (registration)Registration of the tool in the ListToolsRequestSchema handler, providing name, description, and input schema.{ name: 'get_current_session', description: 'Get current session usage with intuitive format (remaining, used, input/output tokens, cost)', inputSchema: { type: 'object', properties: { user_id: { type: 'string', description: 'User ID (defaults to current-session)', default: 'current-session' }, total_budget: { type: 'number', description: 'Total token budget (optional)', default: 190000 } } } },
- src/mcp-server.ts:162-163 (registration)Handler registration/dispatch in the CallToolRequestSchema switch statement, mapping tool calls to the getCurrentSession method.case 'get_current_session': return this.getCurrentSession(request.params.arguments);