
    uli                        U d Z ddlmZ ddlmZ  ed          Zdaedz  ed<   defd	Zej	        de
fd
            Zej	        ddedee
         fd            Zej	        ddedee
         fd            Zej	        ddedee
         fd            Zej	        ddedee
         fd            Zd Zedk    r e             dS dS )z1FastMCP server for WHOOP health data integration.    )FastMCP   )WhoopClientwhoopN_clientreturnc                  :    t           t                      a t           S )zGet or create WHOOP client.)r   r        l/Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/src/whoop_mcp/server.py
get_clientr      s     --Nr   c                  n    t                      } |                                 }|                                S )a  
    Get today's complete WHOOP health data including recovery, sleep, and strain.

    Returns a dictionary with:
    - recovery: Recovery score (0-100%), HRV, resting heart rate, SpO2, skin temp, zone (green/yellow/red)
    - sleep: Total hours, efficiency %, performance %, stage breakdown, disturbances
    - strain: Day strain (0-21), calories, average and max heart rate

    Use this for daily check-ins to compare subjective feel vs objective metrics.
    )r   get_today_data
model_dump)clientdatas     r   r   r      s.     \\F  ""D??r      daysc                     t          t          | d          d          } t                      }|                    |           }d |D             S )a0  
    Get recovery scores for the specified number of days.

    Args:
        days: Number of days to retrieve (default 7, max 30)

    Returns a list of daily recovery data with:
    - date: ISO date string
    - score: Recovery score 0-100%
    - hrv: Heart rate variability in milliseconds
    - rhr: Resting heart rate in BPM
    - spo2: Blood oxygen percentage (WHOOP 4.0+)
    - skin_temp: Skin temperature in Celsius (WHOOP 4.0+)
    - zone: green (67-100), yellow (34-66), or red (0-33)

    Use for trend analysis and pattern detection over time.
    r      c                 6    g | ]}|                                 S r
   r   .0ds     r   
<listcomp>z get_recovery.<locals>.<listcomp>=        )))qALLNN)))r   )minmaxr   get_recovery_historyr   r   r   s      r   get_recoveryr"   '   sK    & s4||R  D\\F&&t,,D))D))))r   c                     t          t          | d          d          } t                      }|                    |           }d |D             S )a;  
    Get sleep data for the specified number of days.

    Args:
        days: Number of days to retrieve (default 7, max 30)

    Returns a list of nightly sleep data with:
    - date: ISO date string
    - total_hours: Total sleep duration
    - efficiency: Sleep efficiency percentage
    - performance: Sleep performance percentage
    - light_hours: Light sleep duration
    - deep_hours: Deep/slow-wave sleep duration
    - rem_hours: REM sleep duration
    - disturbances: Number of sleep disturbances

    Use for sleep pattern analysis and quality tracking.
    r   r   c                 6    g | ]}|                                 S r
   r   r   s     r   r   zget_sleep.<locals>.<listcomp>W   r   r   )r   r   r   get_sleep_historyr!   s      r   	get_sleepr&   @   sK    ( s4||R  D\\F##D))D))D))))r   c                     t          t          | d          d          } t                      }|                    |           }d |D             S )ae  
    Get strain scores for the specified number of days.

    Args:
        days: Number of days to retrieve (default 7, max 30)

    Returns a list of daily strain data with:
    - date: ISO date string
    - day_strain: Daily strain score (0-21 scale, based on Borg scale)
    - calories: Energy expenditure in kilojoules
    - avg_hr: Average heart rate
    - max_hr: Maximum heart rate

    Use for training load analysis and recovery planning.

    Strain scale reference:
    - 0-9: Light activity
    - 10-13: Moderate activity
    - 14-17: High strain (e.g., surfing, MTB)
    - 18-21: All-out effort
    r   r   c                 6    g | ]}|                                 S r
   r   r   s     r   r   zget_strain.<locals>.<listcomp>t   r   r   )r   r   r   get_strain_historyr!   s      r   
get_strainr*   Z   sK    . s4||R  D\\F$$T**D))D))))r   c                     t          t          | d          d          } t                      }|                    |           }d |D             S )a  
    Get workouts/activities for the specified number of days.

    Args:
        days: Number of days to retrieve (default 7, max 30)

    Returns a list of workout data with:
    - id: Unique workout ID
    - date: Date of workout (YYYY-MM-DD)
    - time: Start time (HH:MM)
    - sport_name: Activity name (e.g., "Surfing", "Mountain Biking", "Running")
    - sport_id: WHOOP numeric sport ID
    - duration_minutes: Workout duration in minutes
    - strain: Workout strain score (0-21)
    - avg_hr: Average heart rate during workout
    - max_hr: Maximum heart rate during workout
    - calories: Energy expenditure in kilojoules

    Use this to track activities like surfing, mountain biking, training, etc.
    Workouts are automatically logged when you use the WHOOP app or strap.
    r   r   c                 6    g | ]}|                                 S r
   r   r   s     r   r   z get_workouts.<locals>.<listcomp>   r   r   )r   r   r   get_workout_historyr!   s      r   get_workoutsr.   w   sK    . s4||R  D\\F%%d++D))D))))r   c                  8    t                                            dS )zRun the MCP server.N)mcprunr
   r   r   mainr2      s    GGIIIIIr   __main__)r   )__doc__fastmcpr   r   r   r0   r   __annotations__r   tooldictr   intlistr"   r&   r*   r.   r2   __name__r
   r   r   <module>r<      s   7 7 7             gg #t	 " " "K         
  * *s *4: * * * 
*0 * *C *T
 * * * 
*2 * *S *d * * * 
*8 * *s *4: * * * 
*8  
 zDFFFFF r   