get_daily_macros
Retrieve daily macro and micronutrient breakdown from MyFitnessPal for nutrition tracking and analysis.
Instructions
Get comprehensive macro and micronutrient breakdown with all tracked nutrients.
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:258-329 (handler)The handler function for the 'get_daily_macros' tool. It retrieves daily totals and goals from MyFitnessPal, formats a comprehensive macronutrient and micronutrient breakdown, and returns it as a markdown summary using the text_response utility.@mcp.tool def get_daily_macros(date: Optional[str] = None): """ Get comprehensive macro and micronutrient breakdown with all tracked nutrients. 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) totals = day.totals goals = day.goals output = f"# Macros & Nutrients for {target_date.strftime('%B %d, %Y')}\n\n" # Macronutrients output += "## Macronutrients\n" def format_nutrient(name: str, display_name: str, unit: str = "g"): value = totals.get(name, 0) goal = goals.get(name, 0) if goal > 0: return f"- **{display_name}**: {value:.0f}{unit} / {goal:.0f}{unit} ({value/goal*100:.0f}%)\n" else: return f"- **{display_name}**: {value:.0f}{unit}\n" output += format_nutrient('calories', 'Calories', 'kcal') output += format_nutrient('carbohydrates', 'Carbohydrates') output += format_nutrient('protein', 'Protein') output += format_nutrient('fat', 'Fat') # Fat breakdown if available if 'saturated fat' in totals: output += f" - Saturated: {totals.get('saturated fat', 0):.1f}g\n" if 'polyunsaturated fat' in totals: output += f" - Polyunsaturated: {totals.get('polyunsaturated fat', 0):.1f}g\n" if 'monounsaturated fat' in totals: output += f" - Monounsaturated: {totals.get('monounsaturated fat', 0):.1f}g\n" if 'trans fat' in totals: output += f" - Trans: {totals.get('trans fat', 0):.1f}g\n" output += format_nutrient('fiber', 'Fiber') output += format_nutrient('sugar', 'Sugar') output += "\n" # Micronutrients output += "## Micronutrients\n" if 'sodium' in totals: output += format_nutrient('sodium', 'Sodium', 'mg') if 'potassium' in totals: output += format_nutrient('potassium', 'Potassium', 'mg') if 'cholesterol' in totals: output += format_nutrient('cholesterol', 'Cholesterol', 'mg') if 'vitamin a' in totals: output += format_nutrient('vitamin a', 'Vitamin A', '%') if 'vitamin c' in totals: output += format_nutrient('vitamin c', 'Vitamin C', '%') if 'calcium' in totals: output += format_nutrient('calcium', 'Calcium', '%') if 'iron' in totals: output += format_nutrient('iron', 'Iron', '%') return text_response(output) except Exception as e: return text_response(f"Error retrieving macros: {str(e)}")