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);

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