Skip to main content
Glama

get_glucose_stats

Read-only

Calculate average glucose, GMI (estimated A1C), time-in-range percentages, and glucose variability from your LibreLink data. Gain insights for diabetes management and identify improvement areas.

Instructions

Calculate comprehensive glucose statistics including average glucose, GMI (estimated A1C), time-in-range percentages, and variability metrics. Essential for diabetes management insights and identifying areas for improvement.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoNumber of days to analyze (1-14). Default: 7. Note: LibreLinkUp data availability may be limited.

Implementation Reference

  • src/index.ts:110-126 (registration)
    Tool definition/registration for 'get_glucose_stats' in the tools array, with name, description, and inputSchema (accepts optional 'days' parameter).
    {
      name: 'get_glucose_stats',
      description: 'Calculate comprehensive glucose statistics including average glucose, GMI (estimated A1C), time-in-range percentages, and variability metrics. Essential for diabetes management insights and identifying areas for improvement.',
      inputSchema: {
        type: 'object',
        properties: {
          days: {
            type: 'number',
            description: 'Number of days to analyze (1-14). Default: 7. Note: LibreLinkUp data availability may be limited.'
          }
        },
        required: []
      },
      annotations: {
        readOnlyHint: true
      }
    },
  • Handler in CallToolRequestSchema that executes 'get_glucose_stats': fetches glucose history for N days, calls analytics.calculateGlucoseStats(), and returns structured JSON with average glucose, GMI, time-in-range percentages, and variability metrics.
    case 'get_glucose_stats': {
      if (!client || !analytics) {
        throw new Error('LibreLinkUp not configured. Use configure_credentials first.');
      }
    
      const days = (args?.days as number) || 7;
      const readings = await client.getGlucoseHistory(days * 24);
      const stats = analytics.calculateGlucoseStats(readings);
    
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            analysis_period_days: days,
            average_glucose: stats.average,
            glucose_management_indicator: stats.gmi,
            time_in_range: {
              target_70_180: stats.timeInRange,
              below_70: stats.timeBelowRange,
              above_180: stats.timeAboveRange
            },
            variability: {
              standard_deviation: stats.standardDeviation,
              coefficient_of_variation: stats.coefficientOfVariation
            },
            reading_count: stats.readingCount
          }, null, 2)
        }]
      };
    }
  • Core implementation: calculateGlucoseStats() method on GlucoseAnalytics class. Computes average, standard deviation, coefficient of variation, GMI (3.31 + 0.02392*mean), time-in-range percentages based on configurable targetLow/targetHigh thresholds.
    calculateGlucoseStats(readings: GlucoseReading[]): GlucoseStats {
      if (readings.length === 0) {
        return {
          average: 0,
          gmi: 0,
          timeInRange: 0,
          timeBelowRange: 0,
          timeAboveRange: 0,
          standardDeviation: 0,
          coefficientOfVariation: 0,
          readingCount: 0
        };
      }
    
      const values = readings.map(r => r.value);
      const n = values.length;
    
      // Calculate average
      const sum = values.reduce((a, b) => a + b, 0);
      const average = sum / n;
    
      // Calculate standard deviation
      const squaredDiffs = values.map(v => Math.pow(v - average, 2));
      const avgSquaredDiff = squaredDiffs.reduce((a, b) => a + b, 0) / n;
      const standardDeviation = Math.sqrt(avgSquaredDiff);
    
      // Calculate coefficient of variation
      const coefficientOfVariation = (standardDeviation / average) * 100;
    
      // Calculate GMI (Glucose Management Indicator)
      // GMI = 3.31 + 0.02392 × [mean glucose in mg/dL]
      const gmi = 3.31 + (0.02392 * average);
    
      // Calculate time in range
      const inRange = values.filter(v => v >= this.config.targetLow && v <= this.config.targetHigh).length;
      const belowRange = values.filter(v => v < this.config.targetLow).length;
      const aboveRange = values.filter(v => v > this.config.targetHigh).length;
    
      const timeInRange = (inRange / n) * 100;
      const timeBelowRange = (belowRange / n) * 100;
      const timeAboveRange = (aboveRange / n) * 100;
    
      return {
        average: Math.round(average * 100) / 100,
        gmi: Math.round(gmi * 100) / 100,
        timeInRange: Math.round(timeInRange * 100) / 100,
        timeBelowRange: Math.round(timeBelowRange * 100) / 100,
        timeAboveRange: Math.round(timeAboveRange * 100) / 100,
        standardDeviation: Math.round(standardDeviation * 100) / 100,
        coefficientOfVariation: Math.round(coefficientOfVariation * 100) / 100,
        readingCount: n
      };
    }
  • GlucoseStats interface defining the return type shape: average, gmi, timeInRange, timeBelowRange, timeAboveRange, standardDeviation, coefficientOfVariation, readingCount.
    export interface GlucoseStats {
      average: number;
      gmi: number;
      timeInRange: number;
      timeBelowRange: number;
      timeAboveRange: number;
      standardDeviation: number;
      coefficientOfVariation: number;
      readingCount: number;
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, so the description doesn't need to emphasize safety. It adds that the tool computes statistical metrics, which is useful but not a deep behavioral disclosure. No contradictions.

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?

Two sentences precisely conveying purpose and usage. No wasted words or redundancy. Information is front-loaded.

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

Completeness4/5

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

Tool has one optional parameter, no output schema. Description explains what metrics are computed (avg glucose, GMI, time-in-range, variability), which compensates for missing output schema. Adequately complete for a statistical aggregation tool.

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?

There is one parameter (days) with 100% schema description coverage. The tool description does not repeat parameter details, but the schema already explains days, default, and data availability. Baseline score applies as schema does the work.

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

Purpose5/5

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

Description clearly states it calculates comprehensive glucose statistics (average glucose, GMI, time-in-range, variability). This distinguishes it from siblings like get_current_glucose (single reading), get_glucose_history (raw data), and get_glucose_trends (trends).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Description says 'Essential for diabetes management insights and identifying areas for improvement,' which provides clear context for when to use this tool. No explicit when-not or alternatives, but the purpose is clear enough.

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/sedoglia/librelink-mcp-server'

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