Skip to main content
Glama
cordlesssteve

Claude Telemetry MCP

compare_usage_periods

Analyze and contrast Claude usage metrics across two distinct timeframes to identify trends and monitor changes in token consumption and tool patterns.

Instructions

Compare usage between different time periods

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
period1_daysNoDays back for first period (default: 7)
period2_daysNoDays back for second period (default: 14)

Implementation Reference

  • The main execution handler for the 'compare_usage_periods' tool. It extracts period parameters from input arguments, fetches usage trends for both periods using TelemetryService, and returns a formatted comparison text response.
    case 'compare_usage_periods': {
      const period1Days = typeof args?.period1_days === 'number' ? args.period1_days : 7;
      const period2Days = typeof args?.period2_days === 'number' ? args.period2_days : 14;
      
      const [trends1, trends2] = await Promise.all([
        this.telemetryService.getUsageTrends(period1Days),
        this.telemetryService.getUsageTrends(period2Days)
      ]);
    
      return {
        content: [
          {
            type: 'text',
            text: this.formatPeriodComparison(trends1, trends2, period1Days, period2Days),
          },
        ],
      };
    }
  • Input schema definition for the 'compare_usage_periods' tool, specifying optional parameters for the two comparison periods with defaults.
    inputSchema: {
      type: 'object',
      properties: {
        period1_days: {
          type: 'number',
          description: 'Days back for first period (default: 7)',
          default: 7,
        },
        period2_days: {
          type: 'number',
          description: 'Days back for second period (default: 14)',
          default: 14,
        },
      },
    },
  • src/index.ts:163-181 (registration)
    Tool registration entry in the ListTools response, including name, description, and input schema.
    {
      name: 'compare_usage_periods',
      description: 'Compare usage between different time periods',
      inputSchema: {
        type: 'object',
        properties: {
          period1_days: {
            type: 'number',
            description: 'Days back for first period (default: 7)',
            default: 7,
          },
          period2_days: {
            type: 'number',
            description: 'Days back for second period (default: 14)',
            default: 14,
          },
        },
      },
    },
  • Helper method to format the comparison results between two usage periods, calculating totals, change, and percentage difference.
    private formatPeriodComparison(trends1: UsageTrend[], trends2: UsageTrend[], period1: number, period2: number): string {
      const total1 = trends1.reduce((sum, t) => sum + t.tokens, 0);
      const total2 = trends2.reduce((sum, t) => sum + t.tokens, 0);
      
      const change = total1 - total2;
      const changePercent = total2 > 0 ? ((change / total2) * 100) : 0;
    
      return `## Usage Comparison\n\n` +
        `**Last ${period1} days**: ${total1.toLocaleString()} tokens\n` +
        `**Previous ${period2} days**: ${total2.toLocaleString()} tokens\n` +
        `**Change**: ${change > 0 ? '+' : ''}${change.toLocaleString()} tokens (${changePercent > 0 ? '+' : ''}${changePercent.toFixed(1)}%)`;
    }
  • Supporting method in TelemetryService that queries Prometheus for usage trends over a specified number of days, used by the tool handler for both periods.
    async getUsageTrends(daysBack: number = 7): Promise<UsageTrend[]> {
      const endTime = new Date();
      const startTime = new Date(endTime.getTime() - (daysBack * 24 * 60 * 60 * 1000));
    
      const [tokensResult, costResult, sessionsResult] = await Promise.all([
        this.prometheus.queryRange('claude_code_token_usage_tokens_total', startTime, endTime, '1h'),
        this.prometheus.queryRange('claude_code_cost_usage_USD_total', startTime, endTime, '1h'),
        this.prometheus.queryRange('claude_code_session_count_total', startTime, endTime, '1h')
      ]);
    
      const tokensSeries = this.prometheus.getTimeSeries(tokensResult);
      const costSeries = this.prometheus.getTimeSeries(costResult);
      const sessionsSeries = this.prometheus.getTimeSeries(sessionsResult);
    
      // Combine the series data
      const trends: UsageTrend[] = [];
      for (let i = 0; i < tokensSeries.length; i++) {
        trends.push({
          timestamp: tokensSeries[i].timestamp.toISOString(),
          tokens: tokensSeries[i].value,
          cost: costSeries[i]?.value || 0,
          sessions: sessionsSeries[i]?.value || 0
        });
      }
    
      return trends;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the action ('compare') without disclosing behavioral traits such as whether this is a read-only operation, if it requires authentication, rate limits, or what the output format might be. It lacks details on how the comparison is performed or any side effects.

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 with zero waste, front-loading the core purpose. It's appropriately sized for a simple tool, making it easy for an agent to parse quickly.

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 comparing usage data, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'usage' entails, how results are formatted, or any limitations, leaving significant gaps for the agent to infer behavior.

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?

The input schema has 100% description coverage, clearly documenting both parameters with defaults. The description adds no additional meaning beyond the schema, as it doesn't explain parameter interactions or usage context. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Compare usage between different time periods' states a clear verb ('compare') and resource ('usage'), but it's vague about what specific usage metrics are compared and doesn't distinguish from sibling tools like 'get_usage_trends' or 'get_usage_summary' which might offer similar functionality. It provides a basic purpose but lacks specificity.

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 offers no guidance on when to use this tool versus alternatives like 'get_usage_trends' or 'get_usage_summary' from the sibling list. It implies usage comparison but doesn't specify contexts, exclusions, or prerequisites, leaving the agent to guess 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