Skip to main content
Glama

get_heart_rate_by_date_range

Retrieve heart rate data from Fitbit for a specified date range using start and end dates in YYYY-MM-DD format.

Instructions

Get the raw JSON response for heart rate data 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 1 year.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startDateYesThe start date for which to retrieve heart rate data (YYYY-MM-DD).
endDateYesThe end date for which to retrieve heart rate data (YYYY-MM-DD).

Implementation Reference

  • Handler function that constructs the Fitbit API endpoint for heart rate data by date range, fetches the data using makeFitbitRequest, handles errors and empty responses, and returns the raw JSON as text content.
    async ({
      startDate,
      endDate,
    }: HeartRateRangeParams): Promise<ToolResponseStructure> => {
      // Construct the endpoint dynamically
      const endpoint = `activities/heart/date/${startDate}/${endDate}.json`;
    
      // Make the request
      const heartRateData =
        await makeFitbitRequest<HeartRateTimeSeriesResponse>(
          endpoint,
          getAccessTokenFn,
          FITBIT_API_BASE
        );
    
      // Handle API call failure
      if (!heartRateData) {
        return {
          content: [
            {
              type: 'text',
              text: `Failed to retrieve heart rate data from Fitbit API for the date range '${startDate}' to '${endDate}'. Check token, permissions, date format, and ensure the range is 1 year or less.`,
            },
          ],
          isError: true,
        };
      }
    
      // Handle no data found
      const heartRateEntries = heartRateData['activities-heart'] || [];
      if (heartRateEntries.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: `No heart rate data found for the date range '${startDate}' to '${endDate}'.`,
            },
          ],
        };
      }
    
      // Return successful response
      const rawJsonResponse = JSON.stringify(heartRateData, null, 2);
      return {
        content: [{ type: 'text', text: rawJsonResponse }],
      };
    }
  • Schema definition including tool name, description, Zod input schema for startDate and endDate with regex validation, and TypeScript type for parameters.
    const rangeToolName = 'get_heart_rate_by_date_range';
    const rangeDescription =
      "Get the raw JSON response for heart rate data 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 1 year.";
    
    const rangeParametersSchemaShape = {
      startDate: z
        .string()
        .regex(/^\d{4}-\d{2}-\d{2}$/, 'Start date must be in YYYY-MM-DD format.')
        .describe(
          'The start date for which to retrieve heart rate data (YYYY-MM-DD).'
        ),
      endDate: z
        .string()
        .regex(/^\d{4}-\d{2}-\d{2}$/, 'End date must be in YYYY-MM-DD format.')
        .describe(
          'The end date for which to retrieve heart rate data (YYYY-MM-DD).'
        ),
    };
  • Registration of the 'get_heart_rate_by_date_range' tool on the MCP server using server.tool, linking name, description, schema, and handler function.
    server.tool(
      rangeToolName,
      rangeDescription,
      rangeParametersSchemaShape,
      async ({
        startDate,
        endDate,
      }: HeartRateRangeParams): Promise<ToolResponseStructure> => {
        // Construct the endpoint dynamically
        const endpoint = `activities/heart/date/${startDate}/${endDate}.json`;
    
        // Make the request
        const heartRateData =
          await makeFitbitRequest<HeartRateTimeSeriesResponse>(
            endpoint,
            getAccessTokenFn,
            FITBIT_API_BASE
          );
    
        // Handle API call failure
        if (!heartRateData) {
          return {
            content: [
              {
                type: 'text',
                text: `Failed to retrieve heart rate data from Fitbit API for the date range '${startDate}' to '${endDate}'. Check token, permissions, date format, and ensure the range is 1 year or less.`,
              },
            ],
            isError: true,
          };
        }
    
        // Handle no data found
        const heartRateEntries = heartRateData['activities-heart'] || [];
        if (heartRateEntries.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `No heart rate data found for the date range '${startDate}' to '${endDate}'.`,
              },
            ],
          };
        }
    
        // Return successful response
        const rawJsonResponse = JSON.stringify(heartRateData, null, 2);
        return {
          content: [{ type: 'text', text: rawJsonResponse }],
        };
      }
    );
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 describes key traits: it's a read operation ('Get'), specifies the output format ('raw JSON response'), mentions an API constraint ('maximum range of 1 year'), and implies data retrieval from an external source ('Fitbit'). It does not cover aspects like authentication needs, rate limits, or error handling, but provides sufficient context for basic usage.

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 appropriately sized and front-loaded, with two sentences that efficiently convey purpose, parameters, and a key constraint. Every sentence earns its place: the first states the action and resource, the second specifies parameters and a critical behavioral note. There is no wasted verbiage.

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

Completeness4/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 annotations, no output schema), the description is largely complete. It covers the purpose, parameters, and a key constraint. However, it lacks details on the output structure (since no output schema exists) and does not mention potential errors or authentication requirements, leaving some gaps for a tool interacting with an external API.

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?

The schema description coverage is 100%, with both parameters fully documented in the input schema. The description adds minimal value beyond the schema: it reiterates the parameter names and format ('YYYY-MM-DD') but does not provide additional semantic context, such as date ordering or timezone handling. This meets the baseline of 3 since the schema does the heavy lifting.

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 verb 'Get' and the resource 'raw JSON response for heart rate data from Fitbit', specifying the data source and format. It distinguishes from sibling tools like 'get_heart_rate' by explicitly mentioning 'for a specific date range', indicating this tool is for ranged queries rather than single-day or other types of heart rate data retrieval.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: when heart rate data for a date range is needed. It does not explicitly state when not to use it or name alternatives, but the context implies it's for ranged queries, distinguishing it from non-range siblings. However, it lacks explicit exclusions or comparisons to similar tools like 'get_heart_rate'.

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