Skip to main content
Glama

get_heart_rate

Retrieve heart rate data from Fitbit for specified time periods to analyze cardiovascular activity and monitor fitness trends.

Instructions

Get the raw JSON response for heart rate data from Fitbit for a specified period ending today or on a specific date. Requires a 'period' parameter such as '1d', '7d', '30d', '1w', '1m' and optionally accepts 'date' parameter.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodYesThe time period for which to retrieve heart rate data.
dateNoThe date for which to retrieve heart rate data (YYYY-MM-DD or 'today'). Defaults to 'today'.

Implementation Reference

  • The handler function that executes the 'get_heart_rate' tool logic. It makes a request to the Fitbit API for heart rate data over a specified period ending on a given date (default 'today'), handles errors and empty responses, and returns the raw JSON data as text.
    async ({
      period,
      date = 'today',
    }: HeartRatePeriodParams): Promise<ToolResponseStructure> => {
      // Construct the endpoint dynamically
      const endpoint = `activities/heart/date/${date}/${period}.json`;
    
      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 date '${date}' and period '${period}'. Check token and permissions.`,
            },
          ],
          isError: true,
        };
      }
    
      // Handle no data found for the period
      const heartRateEntries = heartRateData['activities-heart'] || [];
      if (heartRateEntries.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: `No heart rate data found for date '${date}' and period '${period}'.`,
            },
          ],
        };
      }
    
      // Return successful response with raw JSON
      const rawJsonResponse = JSON.stringify(heartRateData, null, 2);
      return {
        content: [{ type: 'text', text: rawJsonResponse }],
      };
    }
  • Input schema (Zod) for the 'get_heart_rate' tool parameters: 'period' (required enum) and 'date' (optional string).
    const periodParametersSchemaShape = {
      period: z
        .enum(['1d', '7d', '30d', '1w', '1m'])
        .describe('The time period for which to retrieve heart rate data.'),
      date: z
        .string()
        .regex(
          /^\d{4}-\d{2}-\d{2}$|^today$/,
          "Date must be in YYYY-MM-DD format or 'today'."
        )
        .optional()
        .describe(
          "The date for which to retrieve heart rate data (YYYY-MM-DD or 'today'). Defaults to 'today'."
        ),
    };
  • Registration of the 'get_heart_rate' tool on the MCP server using server.tool(name, description, schema, handler). The handler is defined inline.
    server.tool(
      periodToolName,
      periodDescription,
      periodParametersSchemaShape,
      async ({
        period,
        date = 'today',
      }: HeartRatePeriodParams): Promise<ToolResponseStructure> => {
        // Construct the endpoint dynamically
        const endpoint = `activities/heart/date/${date}/${period}.json`;
    
        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 date '${date}' and period '${period}'. Check token and permissions.`,
              },
            ],
            isError: true,
          };
        }
    
        // Handle no data found for the period
        const heartRateEntries = heartRateData['activities-heart'] || [];
        if (heartRateEntries.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `No heart rate data found for date '${date}' and period '${period}'.`,
              },
            ],
          };
        }
    
        // Return successful response with raw JSON
        const rawJsonResponse = JSON.stringify(heartRateData, null, 2);
        return {
          content: [{ type: 'text', text: rawJsonResponse }],
        };
      }
    );
  • src/index.ts:81-81 (registration)
    Call to registerHeartRateTools in the main index.ts, which registers the 'get_heart_rate' tool (and related) on the MCP server instance.
    registerHeartRateTools(server, getAccessToken);
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the tool 'requires a period parameter' and 'optionally accepts date parameter,' which adds some behavioral context, but doesn't disclose critical traits like authentication needs, rate limits, error handling, or what 'raw JSON response' entails. For a data retrieval tool with no annotations, this leaves significant gaps in behavioral understanding.

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

Conciseness4/5

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

The description is appropriately concise with two sentences that efficiently state the purpose and parameters. It's front-loaded with the main function, though it could be slightly more structured by separating usage notes from parameter details. No wasted words, but minor room for improvement in clarity.

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 no annotations and no output schema, the description is incomplete for a data retrieval tool. It covers the basic purpose and parameters but lacks details on authentication, error cases, response format, or how it differs from siblings. It's minimally adequate but has clear gaps in providing full context for an AI agent to use it 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 thoroughly. The description adds minimal value beyond the schema by mentioning the parameters are required/optional and giving examples of period values, but doesn't provide additional semantic context like how 'period' interacts with 'date' or what the data format looks like. Baseline 3 is appropriate given high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get the raw JSON response for heart rate data from Fitbit for a specified period.' It specifies the resource (heart rate data) and source (Fitbit), but doesn't explicitly differentiate it from sibling tools like 'get_heart_rate_by_date_range' beyond mentioning the 'period' parameter approach.

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 when to use this tool by specifying it retrieves data 'for a specified period ending today or on a specific date,' but doesn't explicitly state when to choose this over alternatives like 'get_heart_rate_by_date_range' or other sibling tools. It mentions the required 'period' parameter but lacks explicit comparison or exclusion guidance.

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