Skip to main content
Glama
cordlesssteve

Claude Telemetry MCP

get_session_analytics

Analyze Claude Code session patterns to track productivity metrics, token usage, and cost monitoring for usage optimization.

Instructions

Get analytics about session patterns (averages, totals, productivity metrics)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the tool logic by querying Prometheus for aggregate session metrics and computing averages, totals, and session extremes.
    async getSessionAnalytics(): Promise<SessionAnalytics> {
      const queries = {
        totalSessions: 'sum(claude_code_session_count_total)',
        totalTokens: 'sum(claude_code_token_usage_tokens_total)',
        totalActiveTime: 'sum(claude_code_active_time_seconds_total)',
        totalCost: 'sum(claude_code_cost_usage_USD_total)',
        totalLines: 'sum(claude_code_lines_of_code_count_total)',
        totalCommits: 'sum(claude_code_commit_count_total)'
      };
    
      const results = await this.executeQueries(queries);
    
      const totalSessions = results.totalSessions || 1; // Avoid division by zero
      
      return {
        totalSessions,
        averageTokensPerSession: (results.totalTokens || 0) / totalSessions,
        averageActiveTimePerSession: (results.totalActiveTime || 0) / totalSessions,
        averageCostPerSession: (results.totalCost || 0) / totalSessions,
        longestSession: {
          tokens: results.totalTokens || 0, // This would need more sophisticated querying for actual longest session
          activeTime: results.totalActiveTime || 0
        },
        mostProductiveSession: {
          linesOfCode: results.totalLines || 0,
          commits: results.totalCommits || 0
        }
      };
    }
  • MCP server handler that dispatches the tool call to the TelemetryService and returns formatted response.
    case 'get_session_analytics': {
      const analytics = await this.telemetryService.getSessionAnalytics();
      return {
        content: [
          {
            type: 'text',
            text: this.formatSessionAnalytics(analytics),
          },
        ],
      };
    }
  • src/index.ts:147-154 (registration)
    Tool registration in the list of tools provided to ListToolsRequest, including name, description, and input schema.
    {
      name: 'get_session_analytics',
      description: 'Get analytics about session patterns (averages, totals, productivity metrics)',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • TypeScript interface defining the structure of the SessionAnalytics return type.
    export interface SessionAnalytics {
      totalSessions: number;
      averageTokensPerSession: number;
      averageActiveTimePerSession: number;
      averageCostPerSession: number;
      longestSession: {
        tokens: number;
        activeTime: number;
      };
      mostProductiveSession: {
        linesOfCode: number;
        commits: number;
      };
    }
  • Helper function that formats the SessionAnalytics data into a human-readable markdown string for the tool response.
    private formatSessionAnalytics(analytics: SessionAnalytics): string {
      return `## Session Analytics\n\n` +
        `**Total Sessions**: ${analytics.totalSessions}\n` +
        `**Average Tokens/Session**: ${Math.round(analytics.averageTokensPerSession).toLocaleString()}\n` +
        `**Average Active Time/Session**: ${Math.round(analytics.averageActiveTimePerSession / 60)}m\n` +
        `**Average Cost/Session**: $${analytics.averageCostPerSession.toFixed(4)}\n\n` +
        `**Peak Session**:\n` +
        `- Tokens: ${analytics.longestSession.tokens.toLocaleString()}\n` +
        `- Active Time: ${Math.round(analytics.longestSession.activeTime / 60)}m\n\n` +
        `**Most Productive Session**:\n` +
        `- Lines of Code: ${analytics.mostProductiveSession.linesOfCode.toLocaleString()}\n` +
        `- Commits: ${analytics.mostProductiveSession.commits}`;
    }
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 states the tool retrieves analytics but doesn't disclose behavioral traits such as whether it requires authentication, has rate limits, returns real-time or historical data, or what format the output takes. For a tool with zero annotation coverage, this leaves significant gaps in understanding its operation.

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 analytics about session patterns') and adds clarifying examples ('averages, totals, productivity metrics'). There is no wasted verbiage, and every word earns its place in defining the tool's scope.

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

Completeness3/5

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

Given the tool has no parameters, no output schema, and no annotations, the description is minimally adequate. It explains what the tool does but lacks details on behavioral context, output format, or differentiation from siblings. For a simple read operation, it meets basic needs but doesn't provide full guidance for an agent in a crowded toolset.

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 appropriately doesn't discuss parameters, and the baseline for 0 parameters is 4, as it avoids unnecessary detail while matching the schema's simplicity.

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 verb 'Get' and the resource 'analytics about session patterns', with specific examples of metrics (averages, totals, productivity metrics). It distinguishes itself from siblings by focusing on session patterns rather than usage, limits, or telemetry. However, it doesn't explicitly differentiate from all siblings (e.g., 'get_usage_summary' might overlap).

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 its many siblings. With 11 sibling tools focused on usage, analytics, and telemetry, there is no indication of context, prerequisites, or alternatives. The agent must infer usage from the name and description 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