mcp-server-strava

by rbctmz
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Allows analysis of Strava workouts and provides training recommendations based on Strava data using the Model Context Protocol SDK

Strava API integration with Model Context Protocol (MCP) SDK

Integration for training analysis and recommendations based on Strava data using the Model Context Protocol SDK.

🚀 Features

  • Analysis of workouts from Strava
  • Training Recommendations
  • Automatic token update
  • Rate limiting for API requests

📋 Requirements

⚙️ Installation

# Клонируем репозиторий git clone https://github.com/rbctmz/mcp-server-strava.git cd mcp-server-strava # Установка через uv (рекомендуется) curl -LsSf https://astral.sh/uv/install.sh | sh uv pip install . # Установка в режиме разработки uv pip install -e ".[dev]"

Installing MCP SDK

uv add "mcp[cli]"

🔧 Setting

Setting up Strava API

  1. Go to the API settings page
  2. Create an application:
    • Application Name: MCP Strava Integration
    • Category: Training Analysis
    • Website: http://localhost
    • Authorization Callback Domain: localhost

Setting up the environment

  1. Create a file with environment variables:
    cp .env-template .env
  2. Get access tokens:
    python scripts/auth.py
  3. Check the setting:
    mcp dev src/server.py curl -X GET "http://localhost:8000/activities"

📚 API and examples

Resources and Tools

TypeNameDescription
Resourcestrava://activitiesList of activities
Resourcestrava://activities/{id}Activity details
Resourcestrava://athlete/zonesTraining zones
Resourcestrava://athlete/clubsAthlete's clubs
Resourcestrava://gear/{gear_id}Equipment Information
Toolanalyze_activity(activity_id)Training Analysis
Toolanalyze_training_load(activities)Load analysis
Toolget_activity_recommendations()Recommendations

Examples of use

from mcp import ClientSession # Получение активностей async with ClientSession() as session: activities = await session.read_resource("strava://activities") activity = await session.read_resource("strava://activities/12345678") # Анализ тренировки result = analyze_activity(activity_id="12345678") """ { "type": "Run", "distance": 5000, "moving_time": 1800, "analysis": { "pace": 5.5, # мин/км "effort": "Средняя" } } """ # Анализ нагрузки summary = analyze_training_load(activities) """ { "activities_count": 10, "total_distance": 50.5, # км "total_time": 5.2, # часы "heart_rate_zones": { "easy": 4, # ЧСС < 120 "medium": 4, # ЧСС 120-150 "hard": 2 # ЧСС > 150 } } """ # Получение тренировочных зон async with ClientSession() as session: zones = await session.read_resource("strava://athlete/zones") """ { "heart_rate": { "custom_zones": true, "zones": [ {"min": 0, "max": 120, "name": "Z1 - Recovery"}, {"min": 120, "max": 150, "name": "Z2 - Endurance"}, {"min": 150, "max": 170, "name": "Z3 - Tempo"}, {"min": 170, "max": 185, "name": "Z4 - Threshold"}, {"min": 185, "max": -1, "name": "Z5 - Anaerobic"} ] }, "power": { "zones": [ {"min": 0, "max": 180}, {"min": 181, "max": 250}, {"min": 251, "max": 300}, {"min": 301, "max": 350}, {"min": 351, "max": -1} ] } } """

🛠 Development

CI/CD and Security

Checks in GitHub Actions

TypeToolDescription
LintingruffCode formatting and analysis
TestspytestUnit and integration tests
Coatingpytest-covCode Coverage Report

Security and Secrets

  1. Token protection:
    • .env to .gitignore
    • GitHub Secrets for CI/CD
    • Rate limiting: 100 requests/15 min
  2. Setting up secrets:
    # В GitHub: Settings → Secrets → Actions STRAVA_CLIENT_ID=<client_id> STRAVA_CLIENT_SECRET=<client_secret> STRAVA_REFRESH_TOKEN=<refresh_token>

Contributing

  1. Fork the repository
  2. Install dependencies: uv pip install -e ".[dev]"
  3. Create a branch: git checkout -b feature/name
  4. Check the changes:
    ruff format . ruff check . pytest --cov=src
  5. Create a Pull Request

📫 Support

📄 License

MIT

ID: 35t2pc2ntw