Skip to main content
Glama

get_nutrition_day

Retrieve detailed daily nutrition data including meals and food items to support fitness tracking and dietary analysis.

Instructions

Get a complete nutrition day with meals and items.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYes

Implementation Reference

  • The tool 'get_nutrition_day' is defined using the '@app.tool()' decorator. It fetches nutrition data for a specific date from the SQLite database, including meals and their constituent items, calculates the nutritional totals for the meals and the day, and returns the structured data.
    @app.tool()
    def get_nutrition_day(date: str) -> dict[str, Any | None]:
        """Get a complete nutrition day with meals and items."""
        date = _ensure_date(date)
        conn = get_connection()
        cursor = conn.cursor()
    
        cursor.execute("SELECT * FROM nutrition_days WHERE date = ?", (date,))
        day_row = cursor.fetchone()
        if not day_row:
            conn.close()
            return {"day": None}
    
        day = _row_to_dict(day_row)
        cursor.execute("SELECT * FROM meals WHERE day_id = ? ORDER BY order_index", (day["id"],))
    
        meals = []
        for meal_row in cursor.fetchall():
            meal = _row_to_dict(meal_row)
            cursor.execute("SELECT * FROM meal_items WHERE meal_id = ?", (meal["id"],))
            items = [_row_to_dict(r) for r in cursor.fetchall()]
    
            # Compute totals
            totals = {
                "calories": sum(i["calories"] for i in items),
                "protein_g": sum(i["protein_g"] for i in items),
                "carbs_g": sum(i["carbs_g"] for i in items),
                "fats_g": sum(i["fats_g"] for i in items),
                "fiber_g": sum(i["fiber_g"] for i in items),
            }
            meal["items"] = items
            meal["totals"] = totals
            meals.append(meal)
    
        # Compute day totals
        day["totals"] = {
            "calories": sum(m["totals"]["calories"] for m in meals),
            "protein_g": sum(m["totals"]["protein_g"] for m in meals),
            "carbs_g": sum(m["totals"]["carbs_g"] for m in meals),
            "fats_g": sum(m["totals"]["fats_g"] for m in meals),
            "fiber_g": sum(m["totals"]["fiber_g"] for m in meals),
        }
        day["meals"] = meals
        conn.close()
        return {"day": day}

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/JohnZolton/MCP-logger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server