Skip to main content
Glama

get_nutrition_by_date_range

Retrieve nutrition data like calories, water, protein, carbs, fat, fiber, or sodium from Fitbit for a specific date range to analyze dietary patterns and track nutritional intake over time.

Instructions

Get the raw JSON response for nutrition data from Fitbit for a specific resource and date range. Requires 'resource' parameter (caloriesIn, water), 'startDate' and 'endDate' parameters in 'YYYY-MM-DD' format. Note: The API enforces a maximum range of 1,095 days.

Input Schema

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

Implementation Reference

  • The core handler function for the 'get_nutrition_by_date_range' tool. It constructs the Fitbit API endpoint for the specified nutrition resource and date range, fetches the data using makeFitbitRequest, handles errors and empty results, and returns the raw JSON response.
    async ({
      resource,
      startDate,
      endDate,
    }: NutritionRangeParams): Promise<ToolResponseStructure> => {
      // Construct the endpoint dynamically
      const endpoint = `foods/log/${resource}/date/${startDate}/${endDate}.json`;
    
      // Make the request
      const nutritionData =
        await makeFitbitRequest<NutritionTimeSeriesResponse>(
          endpoint,
          getAccessTokenFn,
          FITBIT_API_BASE
        );
    
      // Handle API call failure
      if (!nutritionData) {
        return {
          content: [
            {
              type: 'text',
              text: `Failed to retrieve nutrition data from Fitbit API for resource '${resource}' and the date range '${startDate}' to '${endDate}'. Check token, permissions, date format, and ensure the range is 1,095 days or less.`,
            },
          ],
          isError: true,
        };
      }
    
      // Handle no data found
      const resourceKey = `foods-log-${resource}`;
      const nutritionEntries = nutritionData[resourceKey] || [];
      if (nutritionEntries.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: `No nutrition data found for resource '${resource}' and the date range '${startDate}' to '${endDate}'.`,
            },
          ],
        };
      }
    
      // Return successful response
      const rawJsonResponse = JSON.stringify(nutritionData, null, 2);
      return {
        content: [{ type: 'text', text: rawJsonResponse }],
      };
    }
  • Zod input schema for the tool parameters: resource (enum of nutrition types), startDate and endDate (YYYY-MM-DD format strings).
    const rangeParametersSchemaShape = {
      resource: z
        .enum([
          'caloriesIn',
          'water',
          'protein',
          'carbs',
          'fat',
          'fiber',
          'sodium',
        ])
        .describe('The nutrition resource to retrieve data for.'),
      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 nutrition 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 nutrition data (YYYY-MM-DD).'
        ),
    };
  • The server.tool registration call for 'get_nutrition_by_date_range', including name, description, schema reference, and inline handler function. This occurs within the registerNutritionTools function.
    server.tool(
      rangeToolName,
      rangeDescription,
      rangeParametersSchemaShape,
      async ({
        resource,
        startDate,
        endDate,
      }: NutritionRangeParams): Promise<ToolResponseStructure> => {
        // Construct the endpoint dynamically
        const endpoint = `foods/log/${resource}/date/${startDate}/${endDate}.json`;
    
        // Make the request
        const nutritionData =
          await makeFitbitRequest<NutritionTimeSeriesResponse>(
            endpoint,
            getAccessTokenFn,
            FITBIT_API_BASE
          );
    
        // Handle API call failure
        if (!nutritionData) {
          return {
            content: [
              {
                type: 'text',
                text: `Failed to retrieve nutrition data from Fitbit API for resource '${resource}' and the date range '${startDate}' to '${endDate}'. Check token, permissions, date format, and ensure the range is 1,095 days or less.`,
              },
            ],
            isError: true,
          };
        }
    
        // Handle no data found
        const resourceKey = `foods-log-${resource}`;
        const nutritionEntries = nutritionData[resourceKey] || [];
        if (nutritionEntries.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `No nutrition data found for resource '${resource}' and the date range '${startDate}' to '${endDate}'.`,
              },
            ],
          };
        }
    
        // Return successful response
        const rawJsonResponse = JSON.stringify(nutritionData, null, 2);
        return {
          content: [{ type: 'text', text: rawJsonResponse }],
        };
      }
    );
  • src/index.ts:82-82 (registration)
    Invocation of registerNutritionTools in the main index.ts, which registers the nutrition tools including get_nutrition_by_date_range.
    registerNutritionTools(server, getAccessToken);
  • TypeScript type definition for the NutritionRangeParams used in the tool handler and schema.
    type NutritionRangeParams = {
      resource:
        | 'caloriesIn'
        | 'water'
        | 'protein'
        | 'carbs'
        | 'fat'
        | 'fiber'
        | 'sodium';
      startDate: string;
      endDate: string;
    };
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it returns 'raw JSON response' (format disclosure), requires specific parameters, mentions date format requirements, and importantly reveals API constraints ('maximum range of 1,095 days'). However, it doesn't mention authentication needs or rate limits.

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?

Two sentences, zero waste. First sentence states purpose and core parameters. Second sentence adds critical constraint about date range limits. Every element serves a clear purpose with efficient phrasing.

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?

For a read operation with no annotations, 100% schema coverage, and no output schema, the description does well by covering purpose, parameters, format, and constraints. The main gap is lack of output format details beyond 'raw JSON response' - more specificity about response structure would help, but it's reasonably complete given the context.

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%, providing good documentation for all parameters. The description adds minimal value beyond the schema by listing two example resources ('caloriesIn, water') from the enum and confirming date format requirements, but doesn't provide additional semantic context about parameter interactions or usage patterns.

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 action ('Get the raw JSON response for nutrition data'), resource ('from Fitbit'), and scope ('for a specific resource and date range'). It distinguishes from sibling tools like 'get_nutrition' (which likely has different parameters) by specifying the date range requirement.

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 ('for a specific resource and date range'), but doesn't explicitly state when not to use it or name alternatives among sibling tools. It implies usage for date-range queries but lacks explicit exclusions.

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