Skip to main content
Glama

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
NameRequiredDescriptionDefault
startDateYesThe start date for which to retrieve data (YYYY-MM-DD)
endDateYesThe end date for which to retrieve data (YYYY-MM-DD)

Implementation Reference

  • 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}'`
          }
        );
      }
    });
  • 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);
  • 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.
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively adds context by specifying the API's maximum range limit of 100 days, which is a crucial behavioral trait not covered by the schema. However, it lacks details on authentication needs, rate limits, or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in two sentences: the first states the purpose, and the second adds critical constraints. Every sentence earns its place by providing essential information without redundancy, making it front-loaded and concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is partially complete. It covers the purpose and a key constraint (100-day limit) but lacks details on authentication, response format, or error handling, leaving gaps for an AI agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters with patterns and descriptions. The description adds minimal value by reiterating the date format requirement and naming the parameters, but does not provide additional semantic context beyond what the schema offers.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get the raw JSON response for sleep logs'), identifies the resource ('from Fitbit'), and specifies the scope ('for a specific date range'). It distinguishes itself from siblings like 'get_heart_rate_by_date_range' by focusing on sleep data rather than other metrics.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for retrieving sleep logs within a date range but does not explicitly state when to use this tool versus alternatives like 'get_heart_rate_by_date_range' or other sibling tools. No exclusions or specific contexts are provided, leaving usage guidance incomplete.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TheDigitalNinja/mcp-fitbit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server