get_workouts
Retrieve workout data from the MCP Logger fitness tracking server using filters like date range, workout type, tags, or exercise names to analyze exercise history.
Instructions
Query workouts with various filters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | No | ||
| to_date | No | ||
| workout_type | No | ||
| tag | No | ||
| exercise_name_contains | No | ||
| limit | No | ||
| offset | No |
Implementation Reference
- src/main.py:250-290 (handler)Implementation of the get_workouts tool, which queries the workouts table with various filters and hydrates the results with related exercise and set data.
def get_workouts( from_date: Optional[str] = None, to_date: Optional[str] = None, workout_type: Optional[str] = None, tag: Optional[str] = None, exercise_name_contains: Optional[str] = None, limit: int = 20, offset: int = 0, ) -> dict[str, list[dict[str, Any]]]: """Query workouts with various filters.""" conn = get_connection() cursor = conn.cursor() filters: list[str] = [] params: list[Any] = [] if from_date: filters.append("date_time >= ?") params.append(f"{_ensure_date(from_date)}T00:00:00") if to_date: filters.append("date_time <= ?") params.append(f"{_ensure_date(to_date)}T23:59:59") if workout_type: filters.append("workout_type = ?") params.append(workout_type) if tag: filters.append("tags LIKE ?") params.append(f'%"{tag}"%') base = "SELECT * FROM workouts" if filters: base += " WHERE " + " AND ".join(filters) base += " ORDER BY date_time DESC LIMIT ? OFFSET ?" params.extend([limit, offset]) cursor.execute(base, params) rows = cursor.fetchall() workouts = [_hydrate_workout(conn, _row_to_dict(row)) for row in rows] conn.close() return {"workouts": workouts}