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
| Name | Required | Description | Default |
|---|---|---|---|
| userId | No | User identifier. Defaults to user_12345abcdef67890 if not specified. | |
| startDate | No | Start date in ISO 8601 format. Optional. | |
| endDate | No | End date in ISO 8601 format. Optional. |
Implementation Reference
- src/api-client.ts:101-130 (handler)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; } }
- src/index.ts:197-223 (handler)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: [], }, }, ];
- src/api-client.ts:10-16 (schema)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; }
- src/http-server.ts:388-416 (handler)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), }, ], }; }