Skip to main content
Glama
wn01011

llm-token-tracker

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
NameRequiredDescriptionDefault
user_idNoUser ID (defaults to current-session)current-session
total_budgetNoTotal token budget (optional)

Implementation Reference

  • 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 }]
      };
    }
  • 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
        }
      }
    }
  • 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
          }
        }
      }
    },
  • 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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'intuitive format' but doesn't disclose behavioral traits such as whether this is a read-only operation, if it requires authentication, rate limits, or how it handles errors. The description is too vague to provide adequate transparency for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. However, it could be more structured by separating the purpose from the format details, but it avoids unnecessary verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a tool that likely returns usage data, the description is incomplete. It doesn't explain the return format beyond 'intuitive format', lacks details on what 'cost' refers to, and doesn't cover potential errors or edge cases, leaving significant gaps for an agent to understand the tool fully.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (user_id and total_budget) with descriptions and defaults. The description adds no additional meaning beyond what the schema provides, such as explaining how these parameters affect the output or their practical use cases.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get current session usage' with specific metrics (remaining, used, input/output tokens, cost). It uses a specific verb ('Get') and resource ('current session usage'), though it doesn't explicitly distinguish from sibling tools like 'get_usage' or 'track_usage'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_usage' or 'track_usage'. It mentions an 'intuitive format' but doesn't specify contexts or exclusions for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wn01011/llm-token-tracker'

If you have feedback or need assistance with the MCP directory API, please join our Discord server