get_sleep_data_range
Retrieve daily sleep data including stages, score, and duration for a specified date range.
Instructions
Get sleep data over a date range (day-by-day). Returns array of {date, data} records with sleep stages, score, duration
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format |
Implementation Reference
- src/client/garmin.client.ts:606-608 (handler)The GarminClient.getSleepDataRange method that fetches sleep data over a date range. It delegates to fetchRange, calling getSleepData for each individual date.
async getSleepDataRange(startDate: string, endDate: string): Promise<{ date: string; data: unknown }[]> { return this.fetchRange(startDate, endDate, (d) => this.getSleepData(d)); } - src/tools/range.tools.ts:5-19 (registration)The registerRangeTools function that registers 'get_sleep_data_range' tool on the MCP server with input schema and handler that calls client.getSleepDataRange.
export function registerRangeTools(server: McpServer, client: GarminClient): void { server.registerTool( 'get_sleep_data_range', { description: 'Get sleep data over a date range (day-by-day). Returns array of {date, data} records with sleep stages, score, duration', inputSchema: dateRangeParamSchema.shape, }, async ({ startDate, endDate }) => { const data = await client.getSleepDataRange(startDate, endDate); return { content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }], }; }, ); - src/dtos/date-params.dto.ts:19-22 (schema)The dateRangeParamSchema Zod schema defining startDate and endDate string parameters used as the input schema for the tool.
export const dateRangeParamSchema = z.object({ startDate: dateString.describe('Start date in YYYY-MM-DD format'), endDate: dateString.describe('End date in YYYY-MM-DD format'), }); - src/client/garmin.client.ts:162-174 (helper)The fetchRange helper that iterates over each date in the range, calls the fetcher callback for each date, and returns an array of {date, data} records.
private async fetchRange( startDate: string, endDate: string, fetcher: (date: string) => Promise<unknown>, ): Promise<{ date: string; data: unknown }[]> { const dates = this.dateRange(startDate, endDate); const results: { date: string; data: unknown }[] = []; for (const date of dates) { const data = await fetcher(date).catch(() => null); results.push({ date, data }); } return results; } - src/client/garmin.client.ts:354-359 (helper)The getSleepData helper method called per individual date by the fetchRange loop inside getSleepDataRange.
async getSleepData(date?: string): Promise<unknown> { const resolvedDate = date ?? todayString(); return this.request( `${SLEEP_DAILY_ENDPOINT}/${this.displayName}?date=${resolvedDate}&nonSleepBufferMinutes=${SLEEP_NON_SLEEP_BUFFER_MINUTES}`, ); }