get_latest_glucose
Retrieve the most recent glucose reading for a user, including value, unit, timestamp, and source, to monitor blood sugar levels for diabetes management.
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/api-client.ts:74-96 (handler)Core handler implementation in HealthDataAPI class. Fetches the latest glucose reading via HTTP GET to backend /api/samples/latest endpoint, handles 404 by returning null, maps response to GlucoseReading interface.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; } }
- src/api-client.ts:3-7 (schema)Type definition for GlucoseReading, used as return type for getLatestGlucose and structure for response data.export interface GlucoseReading { value: number; unit: string; date: string; source: string;
- src/index.ts:57-71 (registration)MCP Tool registration in stdio server, defines name, description, and input schema for get_latest_glucose.{ 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 call dispatcher in stdio server. Calls api.getLatestGlucose, handles null response, formats JSON output for MCP 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/http-server.ts:101-113 (registration)MCP Tool registration in HTTP SSE server.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: [], },