get_latest_glucose
Retrieve the most recent glucose reading for a user, including value, unit, timestamp, and data source to support diabetes management and health monitoring.
Instructions
Get the most recent glucose/blood sugar reading for a user. Returns value, unit, timestamp, and source.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | No | User identifier. Defaults to user_12345abcdef67890 if not specified. |
Implementation Reference
- src/index.ts:57-71 (registration)Registration of the 'get_latest_glucose' tool including name, description, and input schema used in ListTools response.{ name: 'get_latest_glucose', description: 'Get the most recent glucose/blood sugar reading for a user. Returns value, unit, timestamp, and source.', inputSchema: { type: 'object', properties: { userId: { type: 'string', description: `User identifier. Defaults to ${DEFAULT_USER_ID || 'configured user'} if not specified.`, }, }, required: [], }, },
- src/index.ts:164-195 (handler)MCP tool handler for 'get_latest_glucose': extracts userId, calls api.getLatestGlucose, handles null case, and returns formatted JSON response.case 'get_latest_glucose': { const reading = await api.getLatestGlucose(userId); if (!reading) { return { content: [ { type: 'text', text: 'No glucose readings found for this user.', }, ], }; } return { content: [ { type: 'text', text: JSON.stringify( { value: reading.value, unit: reading.unit, date: reading.date, source: reading.source, }, null, 2 ), }, ], }; }
- src/api-client.ts:74-96 (helper)Helper function implementing the glucose retrieval logic by querying the storage API's /api/samples/latest endpoint with userId and type 'BloodGlucose'.async getLatestGlucose(userId: string): Promise<GlucoseReading | null> { try { const response = await this.client.get('/api/samples/latest', { params: { userId, type: 'BloodGlucose', }, }); const sample = response.data; return { value: sample.value, unit: sample.unit, date: sample.start_date, source: sample.source, }; } catch (error: any) { if (error.response?.status === 404) { return null; } throw error; } }