Skip to main content
Glama

get_nutrition_days_summary

Retrieve nutrition summaries for a specified date range to track dietary intake and monitor nutritional patterns over time.

Instructions

Get nutrition summaries for a date range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_dateNo
to_dateNo
limitNo
offsetNo

Implementation Reference

  • Implementation of the get_nutrition_days_summary tool. Queries the nutrition_days table and calculates totals for related meals/meal_items.
    def get_nutrition_days_summary(
        from_date: Optional[str] = None,
        to_date: Optional[str] = None,
        limit: int = 31,
        offset: int = 0,
    ) -> dict[str, list[dict[str, Any]]]:
        """Get nutrition summaries for a date range."""
        conn = get_connection()
        cursor = conn.cursor()
    
        filters = []
        params = []
        if from_date:
            filters.append("date >= ?")
            params.append(_ensure_date(from_date))
        if to_date:
            filters.append("date <= ?")
            params.append(_ensure_date(to_date))
    
        base = "SELECT * FROM nutrition_days"
        if filters:
            base += " WHERE " + " AND ".join(filters)
        base += " ORDER BY date DESC LIMIT ? OFFSET ?"
        params.extend([limit, offset])
    
        cursor.execute(base, params)
        days = []
        for row in cursor.fetchall():
            day = _row_to_dict(row)
            cursor.execute("SELECT * FROM meals WHERE day_id = ?", (day["id"],))
            meals = cursor.fetchall()
            items = []
            for m in meals:
                cursor.execute("SELECT * FROM meal_items WHERE meal_id = ?", (m["id"],))
                items.extend(cursor.fetchall())
            day["totals"] = {
                "calories": sum(i["calories"] for i in items) if items else 0,
                "protein_g": sum(i["protein_g"] for i in items) if items else 0,
                "carbs_g": sum(i["carbs_g"] for i in items) if items else 0,
                "fats_g": sum(i["fats_g"] for i in items) if items else 0,
                "fiber_g": sum(i["fiber_g"] for i in items) if items else 0,
            }
            days.append(day)
    
        conn.close()
        return {"days": days}

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