add_exercise
Add exercises to workouts in the MCP Logger fitness tracking system. Specify workout ID, exercise name, optional category, and notes for comprehensive workout logging.
Instructions
Add an exercise to an existing workout.
Args: workout_id: ID of the workout to add exercise to name: Name of the exercise category: Optional category (e.g., 'Squat', 'Push', 'Pull') notes: Optional notes about the exercise
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workout_id | Yes | ||
| name | Yes | ||
| category | No | ||
| notes | No |
Implementation Reference
- src/main.py:166-194 (handler)The `add_exercise` tool is implemented in `src/main.py` using a FastMCP decorator. It takes a `workout_id`, `name`, and optional `category` and `notes`, and inserts a new exercise record into the database with an auto-incrementing `order_index`.
def add_exercise( workout_id: int, name: str, category: Optional[str] = None, notes: Optional[str] = None, ) -> dict[str, int]: """Add an exercise to an existing workout. Args: workout_id: ID of the workout to add exercise to name: Name of the exercise category: Optional category (e.g., 'Squat', 'Push', 'Pull') notes: Optional notes about the exercise """ conn = get_connection() cursor = conn.cursor() # Get current max order_index cursor.execute("SELECT COALESCE(MAX(order_index), 0) FROM exercises WHERE workout_id = ?", (workout_id,)) max_order = cursor.fetchone()[0] cursor.execute( "INSERT INTO exercises (workout_id, order_index, name, category, notes) VALUES (?, ?, ?, ?, ?)", (workout_id, max_order + 1, name, category, notes), ) exercise_id = cursor.lastrowid conn.commit() conn.close() return {"exercise_id": exercise_id}