Skip to main content
Glama

get_nutrition

Retrieve nutrition data from Fitbit for specific resources like calories, water, protein, carbs, fat, fiber, or sodium over defined time periods.

Instructions

Get the raw JSON response for nutrition data from Fitbit for a specified resource and period ending today or on a specific date. Requires 'resource' parameter (caloriesIn, water) and 'period' parameter such as '1d', '7d', '30d', '1w', '1m', '3m', '6m', '1y' and optionally accepts 'date' parameter.

Input Schema

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

Implementation Reference

  • The core handler function that executes the 'get_nutrition' tool logic. It constructs the Fitbit API endpoint based on the resource, period, and date parameters, fetches the data using makeFitbitRequest, handles errors and empty responses, and returns the raw JSON data.
    async ({
      resource,
      period,
      date = 'today',
    }: NutritionPeriodParams): Promise<ToolResponseStructure> => {
      // Construct the endpoint dynamically
      const endpoint = `foods/log/${resource}/date/${date}/${period}.json`;
    
      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}', date '${date}' and period '${period}'. Check token and permissions.`,
            },
          ],
          isError: true,
        };
      }
    
      // Handle no data found for the period
      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}', date '${date}' and period '${period}'.`,
            },
          ],
        };
      }
    
      // Return successful response with raw JSON
      const rawJsonResponse = JSON.stringify(nutritionData, null, 2);
      return {
        content: [{ type: 'text', text: rawJsonResponse }],
      };
    }
  • Zod schema defining the input parameters for the 'get_nutrition' tool: resource (enum of nutrition types), period (time range enum), and optional date.
    const periodParametersSchemaShape = {
      resource: z
        .enum([
          'caloriesIn',
          'water',
          'protein',
          'carbs',
          'fat',
          'fiber',
          'sodium',
        ])
        .describe('The nutrition resource to retrieve data for.'),
      period: z
        .enum(['1d', '7d', '30d', '1w', '1m', '3m', '6m', '1y'])
        .describe('The time period for which to retrieve nutrition 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 nutrition data (YYYY-MM-DD or 'today'). Defaults to 'today'."
        ),
    };
  • Local registration of the 'get_nutrition' tool within the registerNutritionTools function using server.tool() with name 'get_nutrition', description, schema, and inline handler.
    server.tool(
      periodToolName,
      periodDescription,
      periodParametersSchemaShape,
      async ({
        resource,
        period,
        date = 'today',
      }: NutritionPeriodParams): Promise<ToolResponseStructure> => {
        // Construct the endpoint dynamically
        const endpoint = `foods/log/${resource}/date/${date}/${period}.json`;
    
        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}', date '${date}' and period '${period}'. Check token and permissions.`,
              },
            ],
            isError: true,
          };
        }
    
        // Handle no data found for the period
        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}', date '${date}' and period '${period}'.`,
              },
            ],
          };
        }
    
        // Return successful response with raw JSON
        const rawJsonResponse = JSON.stringify(nutritionData, null, 2);
        return {
          content: [{ type: 'text', text: rawJsonResponse }],
        };
      }
    );
  • src/index.ts:82-82 (registration)
    Top-level call to registerNutritionTools in the main server setup, which includes registering the 'get_nutrition' tool.
    registerNutritionTools(server, getAccessToken);
Behavior2/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 mentions 'raw JSON response' and parameter requirements, but doesn't cover important traits like authentication needs, rate limits, error handling, or what the response structure looks like. For a data retrieval tool with external API calls, this is a significant gap in transparency.

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 cover the tool's purpose and parameters. It's front-loaded with the main purpose and avoids unnecessary details. However, the second sentence is somewhat dense with parameter listings, slightly affecting readability.

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

Completeness2/5

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

Given the complexity of interacting with an external API (Fitbit) and no annotations or output schema, the description is incomplete. It doesn't address authentication requirements, rate limits, error scenarios, or response format details. For a tool that likely requires OAuth and has API constraints, this leaves significant gaps 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 all parameters thoroughly. The description adds minimal value beyond the schema by mentioning that the period ends 'today or on a specific date' and listing some resource examples, but doesn't provide additional semantic context. This meets the baseline for 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 nutrition data from Fitbit for a specified resource and period.' It specifies the verb ('Get'), resource ('nutrition data'), and source ('Fitbit'), distinguishing it from siblings like get_food_log or get_nutrition_by_date_range. However, it doesn't explicitly differentiate from get_nutrition_by_date_range beyond mentioning 'period' vs 'date range'.

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 by specifying required parameters and optional ones, but doesn't explicitly state when to use this tool versus alternatives like get_nutrition_by_date_range. It mentions 'period' and 'date' parameters, which might hint at usage for time-based queries, but lacks clear guidance on tool selection among siblings.

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