whoop-get-sleep-collection
Retrieve paginated sleep records from WHOOP data, allowing filtering by date range and limiting results for comprehensive sleep analysis.
Instructions
Get all sleep records for a user, paginated
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limit on the number of sleep records returned (max 25) | |
| start | No | Return sleep records that occurred after or during this time (ISO 8601) | |
| end | No | Return sleep records that intersect this time or ended before this time (ISO 8601) | |
| nextToken | No | Next token from the previous response to get the next page |
Implementation Reference
- src/mcp-server.ts:434-449 (handler)MCP server handler for the 'whoop-get-sleep-collection' tool. Parses arguments, calls WhoopApiClient.getSleepCollection, and returns the result as a JSON-formatted text response.case 'whoop-get-sleep-collection': { const result = await this.whoopClient.getSleepCollection({ limit: args?.limit as number | undefined, start: args?.start as string | undefined, end: args?.end as string | undefined, nextToken: args?.nextToken as string | undefined, }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/mcp-server.ts:172-197 (registration)Tool registration in the MCP server's ListTools handler, defining the name, description, and input schema for pagination parameters.{ name: 'whoop-get-sleep-collection', description: 'Get all sleep records for a user, paginated', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Limit on the number of sleep records returned (max 25)', }, start: { type: 'string', description: 'Return sleep records that occurred after or during this time (ISO 8601)', }, end: { type: 'string', description: 'Return sleep records that intersect this time or ended before this time (ISO 8601)', }, nextToken: { type: 'string', description: 'Next token from the previous response to get the next page', }, }, required: [], }, },
- src/whoop-api.ts:107-118 (helper)Implementation of the sleep collection fetcher in WhoopApiClient. Builds query parameters from input and makes authenticated GET request to Whoop API's /activity/sleep endpoint.async getSleepCollection(params?: PaginationParams): Promise<WhoopSleepCollection> { const queryParams = new URLSearchParams(); if (params?.limit) queryParams.append('limit', params.limit.toString()); if (params?.start) queryParams.append('start', params.start); if (params?.end) queryParams.append('end', params.end); if (params?.nextToken) queryParams.append('nextToken', params.nextToken); const url = `/activity/sleep${queryParams.toString() ? `?${queryParams.toString()}` : ''}`; const response = await this.client.get(url); return response.data; }