Skip to main content
Glama
cordlesssteve

Claude Telemetry MCP

get_current_session_usage

Monitor current Claude Code session metrics including token usage, cost, and activity to track resource consumption and manage spending.

Instructions

Get usage metrics for the current Claude Code session (tokens, cost, activity)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the tool logic by querying Prometheus for current session usage metrics across various dimensions (tokens, cost, etc.) and building the UsageData response.
    async getCurrentSessionUsage(): Promise<UsageData> {
      const sessionStart = this.sessionStartTime.toISOString();
      const now = new Date().toISOString();
    
      // Query for usage since session start - use sum() to aggregate across all label dimensions
      const queries = {
        tokens: `sum(increase(claude_code_token_usage_tokens_total[${this.getTimeRange()}]))`,
        cost: `sum(increase(claude_code_cost_usage_USD_total[${this.getTimeRange()}]))`,
        sessions: `sum(increase(claude_code_session_count_total[${this.getTimeRange()}]))`,
        activeTime: `sum(increase(claude_code_active_time_seconds_total[${this.getTimeRange()}]))`,
        linesOfCode: `sum(increase(claude_code_lines_of_code_count_total[${this.getTimeRange()}]))`,
        commits: `sum(increase(claude_code_commit_count_total[${this.getTimeRange()}]))`,
        editDecisions: `sum(increase(claude_code_code_edit_tool_decision_total[${this.getTimeRange()}]))`
      };
    
      const results = await this.executeQueries(queries);
      return this.buildUsageData(results);
    }
  • MCP CallToolRequestHandler case that handles calls to 'get_current_session_usage', delegates to TelemetryService, and formats the response as MCP content.
    case 'get_current_session_usage': {
      const usage = await this.telemetryService.getCurrentSessionUsage();
      return {
        content: [
          {
            type: 'text',
            text: this.formatUsageData('Current Session', usage),
          },
        ],
      };
    }
  • src/index.ts:38-45 (registration)
    Tool registration in the ListToolsRequestHandler response, defining the tool name, description, and input schema.
    {
      name: 'get_current_session_usage',
      description: 'Get usage metrics for the current Claude Code session (tokens, cost, activity)',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • Input schema definition for the tool (empty object, indicating no input parameters required).
    inputSchema: {
      type: 'object',
      properties: {},
    },
  • Helper usage of getCurrentSessionUsage within the getUsageSummary method.
    const [currentSession, today, thisWeek] = await Promise.all([
      this.getCurrentSessionUsage(),
      this.getTodayUsage(),
      this.getWeekUsage()
    ]);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Get usage metrics' but does not specify whether this is a read-only operation, if it requires authentication, any rate limits, or the format of returned data. This leaves significant gaps in understanding the tool's behavior and constraints.

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

Conciseness5/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 ('Get usage metrics') and specifies the scope ('current Claude Code session') and key metrics ('tokens, cost, activity'). There is no wasted language, making it highly concise and well-structured.

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 the complexity of usage metrics tools and the lack of annotations and output schema, the description is insufficient. It does not explain what the metrics entail, how they are formatted, or any behavioral aspects like data freshness or access requirements. This leaves the agent with incomplete context for effective tool invocation.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description does not add parameter details, which is appropriate here. A baseline of 4 is applied as it adequately handles the lack of parameters without introducing confusion.

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 with specific verbs ('Get usage metrics') and resources ('current Claude Code session'), specifying the metrics include tokens, cost, and activity. However, it does not explicitly distinguish it from sibling tools like 'get_today_usage' or 'get_week_usage', which might target similar metrics but different timeframes, leaving some ambiguity in differentiation.

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. With multiple sibling tools related to usage (e.g., 'get_today_usage', 'get_week_usage', 'get_usage_summary'), there is no indication of context, prerequisites, or exclusions, leaving the agent to infer usage based on tool names alone.

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/cordlesssteve/claude-telemetry-mcp'

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