Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Priority chain for retrieval: `COROS_ACCESS_TOKEN` env var → system keyring
All source modules live in the `coros_mcp/` package:

- **`coros_mcp/server.py`**: FastMCP tool definitions. Each `@mcp.tool()` function validates auth, delegates to `coros_api`, and returns a dict. This is the only file that imports from `fastmcp`. `_run_with_auth()` retries once after re-login — for non-idempotent writes (create/schedule) only on auth errors (`retry_all=False`), to avoid duplicate server-side writes.
- **`coros_mcp/coros_api.py`**: All HTTP logic. Contains two sets of endpoints (Training Hub + mobile), the AES encryption for mobile auth, auto-refresh logic, and response parsers. API errors raise `CorosAPIError` (carries the raw Coros result code). The `fetch_daily_records()` function merges two endpoints: `/analyse/dayDetail/query` (long range, no VO2max) + `/analyse/query` (last 28 days, has VO2max/fitness fields).
- **`coros_mcp/coros_api.py`**: All HTTP logic. Contains two sets of endpoints (Training Hub + mobile), the AES encryption for mobile auth, auto-refresh logic, and response parsers. API errors raise `CorosAPIError` (carries the raw Coros result code). The `targetType`/`targetValue` wire encoding differs between the endurance and strength namespaces — the table above `_parse_workout` is the single source of truth, and each namespace has its own parser (`_parse_workout` / `_parse_strength_workout`, dispatched in `fetch_workout_templates`). The `fetch_daily_records()` function merges two endpoints: `/analyse/dayDetail/query` (long range, no VO2max) + `/analyse/query` (last 28 days, has VO2max/fitness fields).
- **`coros_mcp/models.py`**: Pydantic v2 models: `StoredAuth`, `DailyRecord`, `SleepRecord`/`SleepPhases`, `HRVRecord`, `ActivitySummary`.
- **`coros_mcp/cli.py`**: CLI entry point registered as `coros-mcp` script. Delegates to `coros_api.login()` / `login_mobile()` and `cache.sync.sync_all()`.
- **`coros_mcp/cache/`**: SQLite-backed local data store. `store.py` — raw read/write; `sync.py` — smart fetch logic (resolve gaps, backfill, chunk), `_resolve_fetch_range()` decides what to hit the API for, `_fetch_chunked()` splits long uncached ranges into 12-week API calls; `utils.py` — timezone helpers.
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,21 @@ List reusable workout templates saved in the Coros library.

Returns: `workouts` (list), `count`

Each entry includes: `id`, `name`, `sport_type`, `sport_name`, `estimated_time_seconds`, `exercise_count`, `exercises` (list of steps with `name`, `intensity_low`, `intensity_high`, `sets`, and exactly one duration key: `duration_seconds`, `distance_meters`, or `duration_open`)
Every entry includes: `id`, `name`, `sport_type`, `sport_name`, `estimated_time_seconds`, `exercise_count`, `exercises`.

The shape of `exercises` depends on the namespace — endurance and strength templates speak different step vocabularies:

| | Endurance (run/bike) | Strength (`sport_type` 4) |
|---|---|---|
| Always | `name`, `sets` | `name`, `sets`, `origin_id`, `overview`, `rest_seconds` |
| Target | exactly one of `duration_seconds`, `distance_meters`, `duration_open` | one of `reps` or `duration_seconds` (e.g. a plank) |
| Load | `intensity_low`, `intensity_high` | one of `weight_kg`, `weight_lbs`, `bodyweight`, or `effort_target` (the app's 1–10 RPE scale, used instead of a weight) |

Strength entries also carry program-level `sets` (circuit rounds) and `total_duration_seconds`.

The load and structural keys (`origin_id`, `overview`, `sets`, `rest_seconds`, `weight_kg`, `weight_lbs`) are deliberately the same names [`save_strength_workout_template`](#save_strength_workout_template) takes as *input*. The **target** keys are not yet: that tool takes `target_type`/`target_value` where this returns `reps`/`duration_seconds`, and it has no input for `bodyweight` or `effort_target`. Reading a template, editing it and writing it back therefore still needs a manual mapping (`reps` → `target_type=3`); teaching the write tools these names is tracked separately.

Anything unrecognized is reported raw rather than guessed at: `target_type_raw`/`target_value_raw` for an unknown `targetType`, `rest_type_raw`/`rest_value_raw` for an unknown rest encoding, and `intensity_value_raw`/`intensity_display_unit_raw` for an unknown weight unit. `effort_target` is read-only — the write side has no input for it at all.

### `save_workout_template`

Expand Down
Loading
Loading