get_daily_meals
Retrieve your daily meal breakdown with foods, servings, and calorie information for any date to track nutrition and monitor eating habits.
Instructions
Get detailed meal-by-meal breakdown with all foods, servings, and calories.
Args: date: Date in YYYY-MM-DD format (defaults to today)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No |
Implementation Reference
- server.py:140-192 (handler)Core handler function for the 'get_daily_meals' tool. Decorated with @mcp.tool for automatic registration. Parses date, fetches day data from MyFitnessPal client, iterates through meals and food entries to generate a detailed markdown report of all logged meals, foods, servings, calories, and macros.@mcp.tool def get_daily_meals(date: Optional[str] = None): """ Get detailed meal-by-meal breakdown with all foods, servings, and calories. Args: date: Date in YYYY-MM-DD format (defaults to today) """ try: target_date = parse_date(date) client = get_client() # Fetch day data day = client.get_day(target_date) output = f"# Meals for {target_date.strftime('%B %d, %Y')}\n\n" if not day.meals: output += "No meals logged for this day.\n" else: for meal in day.meals: meal_totals = meal.totals meal_calories = meal_totals.get('calories', 0) output += f"## {meal.name}\n" output += f"**Total**: {meal_calories:.0f} kcal" # Show meal macros meal_carbs = meal_totals.get('carbohydrates', 0) meal_fat = meal_totals.get('fat', 0) meal_protein = meal_totals.get('protein', 0) output += f" ({meal_carbs:.0f}C / {meal_fat:.0f}F / {meal_protein:.0f}P)\n\n" if meal.entries: for entry in meal.entries: nutrition = entry.nutrition_information output += f"- **{entry.name}**\n" output += f" - Serving: {entry.quantity} {entry.unit}\n" output += f" - Calories: {nutrition.get('calories', 0):.0f} kcal\n" output += f" - Macros: " output += f"{nutrition.get('carbohydrates', 0):.0f}C / " output += f"{nutrition.get('fat', 0):.0f}F / " output += f"{nutrition.get('protein', 0):.0f}P\n" output += "\n" else: output += "No foods logged in this meal.\n\n" return text_response(output) except Exception as e: return text_response(f"Error retrieving meals: {str(e)}")
- server.py:47-56 (helper)Helper function used by get_daily_meals to parse the optional date parameter into a date object, defaulting to today.def parse_date(date_str: Optional[str]) -> date: """Parse date string or return today""" if not date_str: return date.today() try: return datetime.strptime(date_str, '%Y-%m-%d').date() except ValueError: raise ValueError(f"Invalid date format: {date_str}. Use YYYY-MM-DD")
- server.py:37-45 (helper)Lazy-initializes and returns the shared MyFitnessPalClient instance used by get_daily_meals to fetch data.def get_client() -> MyFitnessPalClient: """Get or create MyFitnessPal client instance""" global _client if _client is None: _client = MyFitnessPalClient() return _client
- server.py:140-140 (registration)The @mcp.tool decorator registers the get_daily_meals function as an MCP tool.@mcp.tool