Skip to main content
Glama
lucas-1000

MCP Glucose Server

by lucas-1000

get_glucose_stats

Calculate glucose statistics including count, average, minimum, and maximum values for a user within a specified date range to analyze trends and patterns.

Instructions

Get glucose statistics (count, average, min, max) for a user within a date range. Useful for understanding glucose trends and patterns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdNoUser identifier. Defaults to user_12345abcdef67890 if not specified.
startDateNoStart date in ISO 8601 format. Optional.
endDateNoEnd date in ISO 8601 format. Optional.

Implementation Reference

  • Core tool logic: Fetches glucose statistics (count, avg, min, max, unit) from backend API /api/samples/stats endpoint using query params for userId, date range, and BloodGlucose type.
    async getGlucoseStats(params: {
      userId: string;
      startDate?: string;
      endDate?: string;
    }): Promise<GlucoseStats | null> {
      try {
        const queryParams = new URLSearchParams({
          userId: params.userId,
          type: 'BloodGlucose',
        });
    
        if (params.startDate) queryParams.append('startDate', params.startDate);
        if (params.endDate) queryParams.append('endDate', params.endDate);
    
        const response = await this.client.get(`/api/samples/stats?${queryParams}`);
    
        return {
          count: parseInt(response.data.count),
          average: parseFloat(response.data.average),
          min: parseFloat(response.data.min),
          max: parseFloat(response.data.max),
          unit: response.data.unit,
        };
      } catch (error: any) {
        if (error.response?.status === 404) {
          return null;
        }
        throw error;
      }
    }
  • MCP stdio server tool handler: Dispatches get_glucose_stats calls to api.getGlucoseStats, handles null response, and returns JSON-formatted stats.
    case 'get_glucose_stats': {
      const stats = await api.getGlucoseStats({
        userId,
        startDate: args?.startDate as string | undefined,
        endDate: args?.endDate as string | undefined,
      });
    
      if (!stats) {
        return {
          content: [
            {
              type: 'text',
              text: 'No glucose data found for the specified time range.',
            },
          ],
        };
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(stats, null, 2),
          },
        ],
      };
    }
  • src/index.ts:72-95 (registration)
    Tool registration in stdio server's tools list: Defines name, description, and inputSchema (userId optional, startDate/endDate optional).
      {
        name: 'get_glucose_stats',
        description:
          'Get glucose statistics (count, average, min, max) for a user within a date range. Useful for understanding glucose trends and patterns.',
        inputSchema: {
          type: 'object',
          properties: {
            userId: {
              type: 'string',
              description: `User identifier. Defaults to ${DEFAULT_USER_ID || 'configured user'} if not specified.`,
            },
            startDate: {
              type: 'string',
              description: 'Start date in ISO 8601 format. Optional.',
            },
            endDate: {
              type: 'string',
              description: 'End date in ISO 8601 format. Optional.',
            },
          },
          required: [],
        },
      },
    ];
  • TypeScript interface defining the output schema for glucose statistics returned by getGlucoseStats.
    export interface GlucoseStats {
      count: number;
      average: number;
      min: number;
      max: number;
      unit: string;
    }
  • HTTP SSE server tool handler: Similar to index.ts, calls api.getGlucoseStats with logging.
    case 'get_glucose_stats': {
      console.log(`📊 Fetching glucose stats for user: ${userId}`);
      const stats = await api.getGlucoseStats({
        userId,
        startDate: args?.startDate as string | undefined,
        endDate: args?.endDate as string | undefined,
      });
    
      if (!stats) {
        return {
          content: [
            {
              type: 'text',
              text: 'No glucose data found for the specified time range.',
            },
          ],
        };
      }
    
      console.log(`✅ Glucose stats: avg ${stats.average} ${stats.unit}`);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(stats, null, 2),
          },
        ],
      };
    }

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/lucas-1000/mcp-glucose'

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