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() ]);

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