get_sleep_by_date_range
Retrieve sleep log data from Fitbit for a specified date range to analyze sleep patterns and duration over time.
Instructions
Get the raw JSON response for sleep logs from Fitbit for a specific date range. Requires 'startDate' and 'endDate' parameters in 'YYYY-MM-DD' format. Note: The API enforces a maximum range of 100 days.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | The start date for which to retrieve data (YYYY-MM-DD) | |
| endDate | Yes | The end date for which to retrieve data (YYYY-MM-DD) |
Implementation Reference
- src/sleep.ts:93-107 (handler)The tool handler function that constructs the specific Fitbit API endpoint for sleep data by date range and invokes the shared handleFitbitApiCall utility to perform the request, extract data, and format the response.handler: async ({ startDate, endDate }: SleepParams) => { const endpoint = `/sleep/date/${startDate}/${endDate}.json`; return handleFitbitApiCall<SleepLogRangeResponse, SleepParams>( endpoint, { startDate, endDate }, getAccessTokenFn, { apiBase: FITBIT_API_VERSIONS.V1_2, successDataExtractor: (data) => data.sleep || [], noDataMessage: `the date range '${startDate}' to '${endDate}'`, errorContext: `date range '${startDate}' to '${endDate}'` } ); }
- src/sleep.ts:86-108 (registration)The registration of the 'get_sleep_by_date_range' tool using the shared registerTool utility, including name, description, input schema, and inline handler.registerTool(server, { name: 'get_sleep_by_date_range', description: `Get the raw JSON response for sleep logs from Fitbit for a specific date range. Requires 'startDate' and 'endDate' parameters in 'YYYY-MM-DD' format. ${VALIDATION_MESSAGES.MAX_RANGE_100_DAYS}.`, parametersSchema: { startDate: CommonSchemas.startDate, endDate: CommonSchemas.endDate, }, handler: async ({ startDate, endDate }: SleepParams) => { const endpoint = `/sleep/date/${startDate}/${endDate}.json`; return handleFitbitApiCall<SleepLogRangeResponse, SleepParams>( endpoint, { startDate, endDate }, getAccessTokenFn, { apiBase: FITBIT_API_VERSIONS.V1_2, successDataExtractor: (data) => data.sleep || [], noDataMessage: `the date range '${startDate}' to '${endDate}'`, errorContext: `date range '${startDate}' to '${endDate}'` } ); } });
- src/sleep.ts:89-92 (schema)Input schema definition for the tool parameters 'startDate' and 'endDate', referencing shared Zod validation schemas from utils.parametersSchema: { startDate: CommonSchemas.startDate, endDate: CommonSchemas.endDate, },
- src/index.ts:78-78 (registration)Invocation of registerSleepTool to add the sleep tools (including 'get_sleep_by_date_range') to the MCP server instance.registerSleepTool(server, getAccessToken);
- src/sleep.ts:66-71 (schema)TypeScript interface defining the expected structure of the Fitbit Sleep API response for date range queries, used in the handler's type annotations.// Represents the overall structure of the response from the Fitbit Sleep API by date range interface SleepLogRangeResponse { sleep: SleepLogEntry[]; // Array of sleep log entries for the requested date range // Note: The summary object might not be present or might differ in the date range endpoint response. // Adjust based on actual API behavior if needed. }