Skip to main content
Glama
README.md
# garmin-mcp

An [MCP](https://modelcontextprotocol.io) server that gives AI assistants **read-only** access to your **Garmin Connect**
health, wellness, fitness, and activity data using Garmin's official
[Personal API](https://developer.garmin.com/gc-developer-program/personal/personal-api) via Garmin's own Python client
([`garmin-connect-personal-api-python`](https://github.com/garmin/connect-personal-api-python)).

Run it locally over `stdio`, or host it remotely on [Fly.io](https://fly.io/) over stateless Streamable HTTP protected
by an API key.

## Tools

Every tool is read-only (`readOnlyHint=True`). All date parameters use `YYYY-MM-DD` in `GARMIN_TIMEZONE` and default
to local today. Daily range arrays are sorted **newest-first** and automatically chunked into 28-day windows.

### Composite & Analytics

| Tool | Purpose |
| --- | --- |
| `garmin_status` | Local config, timezone, token/cache state, and units reference (no Garmin call by default) |
| `garmin_get_health_summary` | One-day composite snapshot (summary, sleep, HRV, Body Battery, SpO2, activities) with partial errors |
| `garmin_get_recovery` | Focused recovery check (sleep, HRV & baseline, resting HR, Body Battery, stress) |
| `garmin_get_resting_heart_rate` | Daily resting HR trend + min/max/avg over a date range |
| `garmin_get_fitness_profile` | Profile settings, HR zones, fitness age, latest VO2 Max, and latest weight & goals |
| `garmin_get_full_snapshot` | Today's summary + trailing multi-day wellness trends + recent activities + fitness profile |
| `garmin_get_trends` | Server-side weekly or monthly rollups (up to 366 days) keeping LLM context compact |
| `garmin_get_activity_stats` | Aggregated activity totals, sport breakdown, and weekly/monthly volume |

### Daily Wellness & Summaries

| Tool | Garmin Endpoint |
| --- | --- |
| `garmin_get_daily_summaries` | Daily summaries (steps, distance, calories, RHR, stress, Body Battery, intensity minutes) |
| `garmin_get_steps` | Daily step statistics |
| `garmin_get_stress` | Daily stress statistics (0–100) |
| `garmin_get_hydration` | Daily hydration statistics (ml) |
| `garmin_get_sleep` | Single-night sleep stages, scores, SpO2, respiration (`include_intraday=false` by default) |
| `garmin_get_sleep_summaries` | Daily sleep summaries across a date range |
| `garmin_get_body_battery` | Daily Body Battery reports (`include_intraday=false` by default) |
| `garmin_get_heart_rate` | Single-day heart rate (`include_intraday=false` by default) |
| `garmin_get_hrv` | Single-night HRV summary & baseline (`include_readings=false` by default) |
| `garmin_get_hrv_summaries` | Daily HRV summaries across a date range |
| `garmin_get_spo2` | Daily SpO2 (%) and altitude acclimation |

### Biometrics, Nutrition, Profile & Activities

| Tool | Garmin Endpoint |
| --- | --- |
| `garmin_get_vo2_max` | Daily VO2 Max (optional `sport` filter) |
| `garmin_get_fitness_age` | Garmin Fitness Age and contributing factors |
| `garmin_get_heart_rate_zones` | Configured heart rate zones across sports |
| `garmin_get_profile_settings` | User profile settings (units, timezone, sleep schedule) |
| `garmin_get_weight` | Weight and body composition measurements |
| `garmin_get_weight_goals` | Effective weight goals over a date range |
| `garmin_get_food_logs` | Daily nutrition food logs |
| `garmin_get_wellness_activities` | Wellness activity summaries over a date range |
| `garmin_get_activity_types` | Parent/child activity type keys (cached 48 hours) |
| `garmin_search_activities` | Search and paginate activities by date range and sport |
| `garmin_get_activity` | Full summary/details for a single `activity_id` |
| `garmin_get_activity_workouts` | Structured workouts attached to an activity |
| `garmin_download_activity_file` | Original ZIP (`.FIT`) metadata + optional bounded base64 (`include_base64=false` by default) |

### Opt-in Sensitive Tools

Off by default. Set `GARMIN_ENABLE_MENSTRUAL_CYCLE=true` to register:
- `garmin_get_menstrual_cycle_summary`
- `garmin_get_menstrual_cycle_day_view`

### MCP Prompts

- `recovery_check` — Assess today's recovery vs 7-day baseline
- `weekly_training_review` — Review the past 7 days of volume and wellness
- `activity_analysis` — Deep dive on one activity with HR zones and recovery context
- `monthly_trends_review` — Multi-month rollups via `garmin_get_trends` and `garmin_get_activity_stats`

### What Garmin's Personal API does not provide

Training Status / Training Load, Training Readiness, Race Predictions, Personal Records, and all write operations
(sending workouts/courses, editing activities) are not exposed on Garmin's official Personal API.

### Units & conventions

- Raw distances are in **meters**, durations in **seconds**, weights in **grams**, hydration in **milliliters**,
  heart rate in **bpm**, HRV in **ms**, SpO2 in **%**, stress & Body Battery on **0–100**.
- Explicit normalized fields carry suffixes (`_km`, `_kg`, `_hours`, `_minutes`).
- **Gotcha:** `recoveryTime` in raw Garmin payloads is in **minutes**, not hours.
- Daily arrays are returned **newest-first**.

## Requirements

- Python 3.12+ and [uv](https://docs.astral.sh/uv/)
- A Garmin Connect Personal API key from <https://connect.garmin.com/app/settings/personalApiToken>
  (pick 365-day expiry for least hassle; copy it immediately — Garmin displays it once).

## Run locally

```bash
git clone https://github.com/mcdscot/garmin-mcp.git
cd garmin-mcp
uv run garmin-mcp setup    # prompts for your Personal API key and stores it in the OS keychain
uv run garmin-mcp check    # exchanges the key for a bearer token and verifies profile access
```

Alternatively, export `GARMIN_PERSONAL_API_KEY` or save the key to `~/.config/garmin/connect-personal-api-key`
(`chmod 600`).

Add it to an MCP client over `stdio`:

```bash
claude mcp add --scope user garmin -- uv run --directory /path/to/garmin-mcp garmin-mcp
```

## Host it remotely

`garmin-mcp serve-http` serves stateless Streamable HTTP on `0.0.0.0:$PORT` (default `8080`) at both `/` and `/mcp`,
protected by `$MCP_API_KEY`. `GET /healthz` is open for health checks.

Clients authenticate with either header:

```
Authorization: Bearer <key>
X-API-Key: <key>
```

### Deploy to Fly.io

```bash
cp fly.example.toml fly.toml              # set app name, region (e.g. lhr), GARMIN_TIMEZONE
fly apps create garmin-mcp
python3 -c "import secrets; print('grmcp_' + secrets.token_urlsafe(32))"   # keep safe
fly secrets set GARMIN_PERSONAL_API_KEY=<garmin-key> MCP_API_KEY=<api-key>
fly deploy
```

For a custom domain (e.g. `garmin.mcp.scot`):

```bash
fly certs add garmin.mcp.scot
```

If DNS is on Cloudflare, set the record to **DNS only (grey cloud)** so Fly can issue and renew the TLS certificate.
No persistent volume is required: the 24-hour bearer token lives on the ephemeral filesystem and is re-exchanged
automatically on startup and on any `401`.

## Configuration

| Variable | Purpose |
| --- | --- |
| `GARMIN_PERSONAL_API_KEY` | Garmin Personal API key (highest precedence) |
| `GARMIN_PERSONAL_API_KEY_FILE` | Explicit path to a key file (overrides default file and keychain) |
| `GARMIN_BEARER_TOKEN_CACHE_FILE` | Override bearer-token cache file path |
| `GARMIN_TIMEZONE` | IANA time zone for local dates (e.g. `Europe/London`); defaults to machine zone |
| `GARMIN_ENABLE_MENSTRUAL_CYCLE` | `true` enables menstrual-cycle tools; default `false` |
| `GARMIN_CACHE_TTL_SECONDS` | In-memory response cache TTL in seconds; default `900` (`300` cap for today) |
| `GARMIN_MAX_CONCURRENCY` | Max concurrent requests to Garmin; default `2` (clamped 1–6) |
| `MCP_API_KEY` | Required by `serve-http`; at least 32 characters |
| `PORT` | Port for `serve-http`; default `8080` |

## Hardening & Security

- **Official auth only.** Uses Garmin's Personal API key → 24-hour JWT exchange via `PersonalApiAuthenticator`.
  Re-exchanges on startup and automatically refreshes + retries once on `401`. Never touches passwords or SSO.
- **Rate-limit protection.** Caps upstream concurrency to 2, honours `Retry-After` on `429` with up to 2 retries,
  chunks long ranges in 28-day windows, and deduplicates concurrent identical calls via an in-memory single-flight cache.
- **Strict inputs & safe logs.** Unknown tool arguments are rejected (`extra="forbid"`). One structured JSON audit
  line per call is written to `stderr` (`tool`, `ok`, `duration_ms`, `error_kind`, `garmin_status`, `partial_errors`) —
  never logging keys, tokens, arguments, or returned health data.
- **Keep secrets out of git.** `fly.toml`, `.env*`, and key/token files are git-ignored.

## Development

```bash
# Offline unit tests (no credentials or network required)
uv run pytest

# Lint
uv run ruff check .

# Opt-in live smoke tests (requires a valid Garmin Personal API key)
GARMIN_LIVE_TESTS=1 uv run pytest -m live -v
```

## License

[MIT](LICENSE)

TDQS

B3.2/5.0

Scored across 32 tools

Disambiguation3/5

Most metric tools are clearly scoped (get_sleep vs get_sleep_summaries vs get_hrv vs get_hrv_summaries), but the overview family overlaps heavily: garmin_get_health_summary, garmin_get_recovery, garmin_get_full_snapshot, garmin_get_trends, and garmin_get_daily_summaries all return composite wellness data covering sleep, HRV, Body Battery, and stress. An agent asked for a daily briefing has five plausible entry points and must read long descriptions to choose correctly.

Naming Consistency4/5

Nearly all tools follow a predictable garmin_verb_noun pattern (garmin_get_*, garmin_search_activities, garmin_download_activity_file) with namespacing that makes ownership obvious. Minor deviations: garmin_status has no verb, and the singular-vs-_summaries suffix convention is a subtlety rather than a break in style.

Tool Count2/5

32 tools exceeds a comfortable set for a read-only health dashboard, especially since many are near-duplicate per-metric endpoint wrappers (get_steps, get_stress, get_hydration, get_body_battery, get_spo2, get_vo2_max, get_weight_goals) that share identical range/chunking semantics and could be consolidated behind a metric parameter. The surface is defensible for the domain but heavy for what an agent can realistically pick between.

Completeness4/5

Coverage of Garmin's health and activity domain is strong: sleep, HRV, stress, Body Battery, SpO2, VO2 Max, weight, nutrition, workouts, activity search/detail/FIT download, plus profile, zones, and status. Gaps are mostly write operations (no logging weight, food, or setting goals) and no workout/course creation, which are reasonable omissions for an intentionally read-oriented server.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues