get_workout_info
Retrieve detailed workout information for a specific date, including exercises, sets, reps, and weights from JEFit workout data.
Instructions
Get detailed workout information for a specific date.
Args: date: Date in YYYY-MM-DD format
Returns: Markdown-formatted workout details including exercises, sets, reps, and weights
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes |
Implementation Reference
- server.py:121-184 (handler)Handler function for the 'get_workout_info' tool. It validates the date input, fetches raw workout data using the helper function, enriches it with exercise details from a preloaded database, formats the output as structured Markdown, and returns it as a ToolResult. The @mcp.tool decorator handles registration.@mcp.tool def get_workout_info(date: str) -> ToolResult: """ Get detailed workout information for a specific date. Args: date: Date in YYYY-MM-DD format Returns: Markdown-formatted workout details including exercises, sets, reps, and weights """ # Validate date format try: datetime.strptime(date, "%Y-%m-%d") except ValueError as e: raise ValueError(f"Invalid date format. Use YYYY-MM-DD format: {e}") # Get workout data from API workout_data = get_workout_for_date(date) # Build markdown output output_lines = [] output_lines.append(f"# Workout for {date}\n") if 'data' not in workout_data or not workout_data['data']: output_lines.append("No workout found for this date.") markdown_text = "\n".join(output_lines) return ToolResult(content=[TextContent(type="text", text=markdown_text)]) for session in workout_data['data']: session_date = datetime.fromtimestamp(session['date']).strftime('%Y-%m-%d %H:%M:%S') duration_minutes = session['total_time'] // 60 duration_seconds = session['total_time'] % 60 total_weight = session['total_weight'] output_lines.append(f"**Started:** {session_date}") output_lines.append(f"**Duration:** {duration_minutes}m {duration_seconds}s") output_lines.append(f"**Weight Lifted:** {total_weight} lbs\n") output_lines.append("## Exercises\n") for i, log in enumerate(session['logs'], 1): exercise_id = log['exercise_id'] exercise = EXERCISE_DB.get(exercise_id, {}) name = exercise.get('name', f'Unknown Exercise ({exercise_id})') muscle_groups = ', '.join(exercise.get('body_parts', ['Unknown'])) equipment = ', '.join(exercise.get('equipment', ['Unknown'])) output_lines.append(f"### {i}. {name}") output_lines.append(f"- **Muscle Groups:** {muscle_groups}") output_lines.append(f"- **Equipment:** {equipment}") output_lines.append("") # Add sets information for j, s in enumerate(log['log_sets'], 1): weight = s.get('weight', 0) reps = s.get('reps', 0) output_lines.append(f" - Set {j}: {weight} lbs × {reps} reps") output_lines.append("") # Blank line between exercises markdown_text = "\n".join(output_lines) return ToolResult(content=[TextContent(type="text", text=markdown_text)])
- workout_info.py:97-111 (helper)Core helper function that makes the API request to JEFit to retrieve raw workout session data for a specific date. Converts date to Unix timestamp and uses authenticated headers.def get_workout_for_date(date_str): """Get workout logs for a specific date""" date_unix = int(time.mktime(time.strptime(date_str, "%Y-%m-%d"))) # Get Access Token and User ID access_token = get_access_token() user_id = get_user_id(access_token) url = f"https://www.jefit.com/api/v2/users/{user_id}/sessions?startDate={date_unix}" headers = { 'content-type': 'application/json', 'Cookie': f'jefitAccessToken={access_token}' } response = requests.get(url, headers=headers) return response.json()
- workout_info.py:61-96 (helper)Helper function that loads or fetches and caches the JEFit exercise database (names, muscle groups, equipment) used to enrich workout logs with human-readable exercise information.def load_exercise_db(): """Load exercise database from JSON cache, creating it if necessary""" db_path = Path('data/exercises_db.json') # Create data directory if it doesn't exist db_path.parent.mkdir(exist_ok=True) # If database doesn't exist, fetch and create it if not db_path.exists(): print("Exercise database not found. Fetching from JEFit...") try: exercises = fetch_exercise_database() if not exercises: print("⚠️ No exercises found. Check your authentication.") return {} # Save to JSON with open(db_path, 'w') as f: json.dump(exercises, f, indent=2) print(f"✓ Created exercise database with {len(exercises)} exercises") return exercises except Exception as e: print(f"⚠️ Failed to fetch exercise database: {e}") return {} # Load existing database try: with open(db_path, 'r') as f: return json.load(f) except Exception as e: print(f"⚠️ Error loading exercise database: {e}") return {}