Skip to main content
Glama
ai-mcp-garage

MyFitnessPal MCP Server

get_date_range_summary

Analyze nutrition trends and insights from MyFitnessPal data over a specified date range to track dietary patterns and progress.

Instructions

Get aggregate nutrition data over a date range with trends and insights.

Args: start_date: Start date in YYYY-MM-DD format end_date: End date in YYYY-MM-DD format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYes
end_dateYes

Implementation Reference

  • The handler function for the 'get_date_range_summary' tool. It fetches daily nutrition data over a date range using the MyFitnessPal client, computes averages and statistics, and returns a formatted markdown summary including daily averages, tracking stats, and a daily breakdown.
    @mcp.tool
    def get_date_range_summary(start_date: str, end_date: str):
        """
        Get aggregate nutrition data over a date range with trends and insights.
        
        Args:
            start_date: Start date in YYYY-MM-DD format
            end_date: End date in YYYY-MM-DD format
        """
        try:
            start = parse_date(start_date)
            end = parse_date(end_date)
            
            if start > end:
                raise ValueError("Start date must be before or equal to end date")
            
            client = get_client()
            
            # Collect data for each day
            daily_data = []
            
            for day in client.get_date_range(start, end):
                totals = day.totals
                
                daily_data.append({
                    'date': day.date,
                    'calories': totals.get('calories', 0),
                    'carbs': totals.get('carbohydrates', 0),
                    'fat': totals.get('fat', 0),
                    'protein': totals.get('protein', 0),
                    'water_ml': day.water,  # Store as ml
                    'complete': day.complete,
                    'num_meals': len(day.meals),
                    'num_exercises': len(day.exercises)
                })
            
            if not daily_data:
                return text_response("No data available for the specified date range.")
            
            # Calculate aggregates
            num_days = len(daily_data)
            avg_calories = sum(d['calories'] for d in daily_data) / num_days
            avg_carbs = sum(d['carbs'] for d in daily_data) / num_days
            avg_fat = sum(d['fat'] for d in daily_data) / num_days
            avg_protein = sum(d['protein'] for d in daily_data) / num_days
            avg_water_ml = sum(d['water_ml'] for d in daily_data) / num_days
            avg_water_oz = avg_water_ml / 29.5735
            
            complete_days = sum(1 for d in daily_data if d['complete'])
            days_with_exercise = sum(1 for d in daily_data if d['num_exercises'] > 0)
            
            # Format output
            output = f"# Date Range Summary\n"
            output += f"**{start.strftime('%B %d, %Y')}** to **{end.strftime('%B %d, %Y')}**\n"
            output += f"({num_days} days)\n\n"
            
            output += "## Daily Averages\n"
            output += f"- **Calories**: {avg_calories:.0f} kcal/day\n"
            output += f"- **Carbohydrates**: {avg_carbs:.0f}g/day\n"
            output += f"- **Fat**: {avg_fat:.0f}g/day\n"
            output += f"- **Protein**: {avg_protein:.0f}g/day\n"
            output += f"- **Water**: {avg_water_oz:.0f} oz/day ({avg_water_ml:.0f} ml/day)\n\n"
            
            output += "## Tracking Stats\n"
            output += f"- **Days Completed**: {complete_days}/{num_days} ({complete_days/num_days*100:.0f}%)\n"
            output += f"- **Days with Exercise**: {days_with_exercise}/{num_days} ({days_with_exercise/num_days*100:.0f}%)\n\n"
            
            output += "## Daily Breakdown\n"
            for day_data in daily_data:
                d = day_data['date']
                water_oz = day_data['water_ml'] / 29.5735
                output += f"- **{d.strftime('%Y-%m-%d')}**: "
                output += f"{day_data['calories']:.0f} kcal, "
                output += f"{day_data['carbs']:.0f}C/{day_data['fat']:.0f}F/{day_data['protein']:.0f}P, "
                output += f"{water_oz:.0f} oz water"
                
                status = []
                if day_data['complete']:
                    status.append("✓")
                if day_data['num_exercises'] > 0:
                    status.append(f"{day_data['num_exercises']} exercises")
                
                if status:
                    output += f" [{', '.join(status)}]"
                
                output += "\n"
            
            return text_response(output)
            
        except Exception as e:
            return text_response(f"Error retrieving date range summary: {str(e)}")

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/ai-mcp-garage/mcp-myfitnesspal'

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