Skip to main content
Glama
jonathaneemmett

TrainingPeaks MCP Server

README.md
# TrainingPeaks MCP Server

MCP server for TrainingPeaks. Reads workouts, fitness metrics (CTL/ATL/TSB), and health data. Creates, updates, and deletes planned workouts. Built with Python/FastMCP with browser-based auth and auto-refresh. Designed for AI-powered training plan management and automated adjustment based on performance, fatigue, and injury.

## Setup

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
```

## Usage

```bash
python -m training_peaks_mcp
```

On first run, a browser window opens with the TrainingPeaks login page. Enter your credentials — they're sent to localhost only, saved locally to `~/.config/training-peaks-mcp/credentials.json`, and auto-refresh when expired.

### CLI Options

```bash
python -m training_peaks_mcp              # Start the MCP server
python -m training_peaks_mcp --auth       # Re-authenticate
python -m training_peaks_mcp --auth-status # Check auth status
python -m training_peaks_mcp --auth-clear  # Remove stored credentials
```

## Tools

### Auth
| Tool | Description |
|------|-------------|
| `authenticate` | Login with username/password via MCP |

### Read
| Tool | Description |
|------|-------------|
| `get_profile` | Athlete profile (ID, name, account type) |
| `get_workouts` | Workouts by date range (filter: all/planned/completed) |
| `get_workout` | Single workout with full details and structure |
| `get_fitness` | CTL/ATL/TSB from the Performance Management Chart |
| `get_metrics` | Health metrics (weight, HRV, sleep, SpO2, steps) |
| `get_training_zones` | Power, heart rate, and speed/pace zones |
| `get_nutrition` | Nutrition data by date range |

### Write
| Tool | Description |
|------|-------------|
| `create_workout` | Create a planned workout |
| `update_workout` | Update an existing workout |
| `delete_workout` | Delete a workout |
| `log_metrics` | Log health metrics (weight, HRV, sleep, injury, etc.) |
| `add_workout_comment` | Add a comment to a workout |

## Authentication

Three methods, checked in order:

1. **Stored credentials** — saved automatically after first login, auto-refreshes on expiry
2. **Browser login** — opens on first run if no credentials exist
3. **Environment variable** — set `TP_AUTH_COOKIE` to override (for CI/containers)

Credentials are stored at `~/.config/training-peaks-mcp/credentials.json` with `0600` permissions.

## Architecture

```
src/training_peaks_mcp/
├── __init__.py
├── __main__.py      # CLI entry point
├── auth.py          # Login flow, credential storage, browser auth page
├── client.py        # Async HTTP client for tpapi.trainingpeaks.com
└── server.py        # FastMCP tool definitions
```

The server uses the TrainingPeaks internal API (`tpapi.trainingpeaks.com`). Auth cookies are exchanged for short-lived bearer tokens via `/users/v3/token`.

## Supported Sports

Swim, Bike, Run, Brick, Crosstrain, Race, DayOff, MtnBike, Strength, Custom, XCSki, Rowing, Walk, Other

## License

MIT