Skip to main content
Glama
cordlesssteve

Claude Telemetry MCP

get_usage_trends

Analyze usage patterns over time to identify trends and monitor activity in Claude Code sessions.

Instructions

Get usage trends over time to identify patterns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
days_backNoNumber of days to look back (default: 7)

Implementation Reference

  • Core handler function that executes the tool logic: queries Prometheus range data for tokens, cost, and sessions over the specified number of days and constructs UsageTrend array.
    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;
    }
  • src/index.ts:133-146 (registration)
    Tool registration in ListToolsRequest handler, defining name, description, and inputSchema with days_back parameter.
    {
      name: 'get_usage_trends',
      description: 'Get usage trends over time to identify patterns',
      inputSchema: {
        type: 'object',
        properties: {
          days_back: {
            type: 'number',
            description: 'Number of days to look back (default: 7)',
            default: 7,
          },
        },
      },
    },
  • Type definition for the output structure UsageTrend used by getUsageTrends.
    export interface UsageTrend {
      timestamp: string;
      tokens: number;
      cost: number;
      sessions: number;
    }
  • MCP CallToolRequest dispatcher case that parses arguments, calls the core handler, formats response, and returns MCP content.
    case 'get_usage_trends': {
      const daysBack = typeof args?.days_back === 'number' ? args.days_back : 7;
      const trends = await this.telemetryService.getUsageTrends(daysBack);
      return {
        content: [
          {
            type: 'text',
            text: this.formatUsageTrends(trends, daysBack),
          },
        ],
      };
    }
  • Helper function to format the UsageTrend data into a markdown table for the MCP response.
    private formatUsageTrends(trends: UsageTrend[], daysBack: number): string {
      let result = `## Usage Trends (${daysBack} days)\n\n`;
      
      if (trends.length === 0) {
        return result + 'No trend data available.';
      }
    
      result += '| Time | Tokens | Cost | Sessions |\n';
      result += '|------|--------|------|---------|\n';
      
      trends.slice(-10).forEach(trend => {
        const time = new Date(trend.timestamp).toLocaleString();
        result += `| ${time} | ${trend.tokens.toLocaleString()} | $${trend.cost.toFixed(3)} | ${trend.sessions} |\n`;
      });
    
      return result;
    }
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 for behavioral disclosure. It mentions 'over time' and 'identify patterns', which hints at temporal analysis, but doesn't specify what data is returned (e.g., time series, aggregated metrics), whether it's read-only (implied by 'Get'), or any constraints like rate limits or authentication needs. For a tool with no annotations, this leaves significant behavioral gaps.

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 directly states the tool's purpose without unnecessary words. It's front-loaded with the core action ('Get usage trends over time') and adds the goal ('to identify patterns') concisely. Every part of the sentence contributes meaning.

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 and no output schema, the description is incomplete for effective tool use. It doesn't explain what 'usage trends' entail (e.g., metrics returned, format), how patterns are identified, or any behavioral aspects like error conditions. For a tool with 1 parameter but rich sibling context, more detail is needed to guide the agent properly.

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, with the single parameter 'days_back' fully documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline of 3. Since there's only one parameter, the description doesn't need to compensate for schema gaps.

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 'usage trends over time' with the purpose 'to identify patterns'. It distinguishes from siblings like 'get_usage_summary' or 'get_today_usage' by focusing on trends over time rather than current or summary data. However, it doesn't explicitly differentiate from 'compare_usage_periods' which might also involve temporal analysis.

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 siblings like 'get_usage_summary', 'get_today_usage', and 'compare_usage_periods', there's no indication of when this trend analysis tool is preferred over other usage-related tools. 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