Skip to main content

Add your description here

Project description

Strava MCP Server

CI/CD Pipeline codecov

A Model Context Protocol (MCP) server for interacting with the Strava API.

Features

This MCP server provides tools to access data from the Strava API:

  • Get user's activities
  • Get a specific activity's details
  • Get the segments of an activity
  • Get the leaderboard of a segment

Installation

Prerequisites

  • Python 3.13 or later
  • Strava API credentials (client ID and client secret)

Setup

  1. Clone the repository:
git clone <repository-url>
cd strava
  1. Install dependencies with uv:
uv install
  1. Set up environment variables with your Strava API credentials:

Create a Strava app at https://www.strava.com/settings/api and obtain your client ID and client secret.

You can set environment variables directly:

export STRAVA_CLIENT_ID=your_client_id  # from https://www.strava.com/settings/api
export STRAVA_CLIENT_SECRET=your_client_secret  # from https://www.strava.com/settings/api

Alternatively, you can create a .env file in the root directory with these variables:

STRAVA_CLIENT_ID=your_client_id
STRAVA_CLIENT_SECRET=your_client_secret

The application will automatically load variables from the .env file if it exists.

Authentication

The server includes an automatic OAuth flow using a separate local web server:

  1. The first time you make a request to the Strava API, the system checks if you have a refresh token.
  2. If no refresh token is found, it automatically starts a standalone OAuth server and opens your browser to the Strava authorization page.
  3. After authorizing the application in your browser, you'll be redirected to a local callback page.
  4. The server automatically obtains and stores the refresh token for future use.

You can also get a refresh token manually by running:

python get_token.py

Or set the refresh token directly if you already have one:

export STRAVA_REFRESH_TOKEN=your_refresh_token

You can also add the refresh token to your .env file:

STRAVA_REFRESH_TOKEN=your_refresh_token

This approach eliminates the need to manually go through the authorization flow and copy/paste tokens. The OAuth flow uses your STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET environment variables.

Usage

Running the Server

To run the server:

python main.py

Development Mode

You can run the server in development mode with the MCP CLI:

mcp dev main.py

Installing in Claude Desktop

To install the server in Claude Desktop:

mcp install --env-file ~/.ssh/env-strava.sh main.py

Where ~/.ssh/strava.sh contains your Strava credentials:

export STRAVA_CLIENT_ID=your_client_id
export STRAVA_CLIENT_SECRET=your_client_secret

Note that this will actually copy your credentials to your Claude Desktop configuration (/Users/<username>/Library/Application Support/Claude/claude_desktop_config.json).

Alternatively, you can add the following to your Claude Desktop configuration:

"strava": {
    "command": "bash",
    "args": [
        "-c",
        "source ~/.ssh/strava.sh && uv --directory /Users/yorrickjansen/work/mcp/strava run main.py"
    ]
}

Where ~/.ssh/strava.sh contains your Strava credentials:

export STRAVA_CLIENT_ID=your_client_id
export STRAVA_CLIENT_SECRET=your_client_secret

This option is more secure as it doesn't expose your credentials in your configuration file.

Tools

Get User Activities

Retrieves a list of activities for the authenticated user.

Parameters:

  • before (optional): Epoch timestamp to filter activities before a certain time
  • after (optional): Epoch timestamp to filter activities after a certain time
  • page (optional): Page number (default: 1)
  • per_page (optional): Number of items per page (default: 30)

Get Activity

Gets detailed information about a specific activity.

Parameters:

  • activity_id: The ID of the activity
  • include_all_efforts (optional): Whether to include all segment efforts (default: false)

Get Activity Segments

Retrieves the segments from a specific activity.

Parameters:

  • activity_id: The ID of the activity

Get Segment Leaderboard

Gets the leaderboard for a specific segment.

Parameters:

  • segment_id: The ID of the segment
  • gender (optional): Filter by gender ('M' or 'F')
  • age_group (optional): Filter by age group
  • weight_class (optional): Filter by weight class
  • following (optional): Filter by friends of the authenticated athlete
  • club_id (optional): Filter by club
  • date_range (optional): Filter by date range
  • context_entries (optional): Number of context entries
  • page (optional): Page number (default: 1)
  • per_page (optional): Number of items per page (default: 30)

Development

Project Structure

  • strava_mcp/: Main package directory
    • __init__.py: Package initialization
    • config.py: Configuration settings using pydantic-settings
    • models.py: Pydantic models for Strava API entities
    • api.py: Low-level API client for Strava
    • auth.py: Strava OAuth authentication implementation
    • oauth_server.py: Standalone OAuth server implementation
    • service.py: Service layer for business logic
    • server.py: MCP server implementation
  • tests/: Unit tests
  • main.py: Entry point to run the server
  • get_token.py: Utility script to get a refresh token manually

Running Tests

To run tests:

pytest

License

MIT License

Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strava_mcp-0.1.0.tar.gz (119.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strava_mcp-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file strava_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: strava_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 119.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for strava_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9263d965e969f0025d08e02dbf78936cc47bfe5123b2f5ca79b6a8f8f38384f4
MD5 96bc42c651f5bb061ee2eb04e0c237fe
BLAKE2b-256 4c79acbab839b4f84ab7a352589c544448e9fa2f893984297e874a6b72b795bc

See more details on using hashes here.

File details

Details for the file strava_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: strava_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for strava_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc9ffb27145931686d0b9e5999e5166d812e4dbef317d8131c7129d59595052a
MD5 a31428052b414c07a24ea50a4f0c881a
BLAKE2b-256 1a551cb391e9e501ab7a0dfa38970e5f93e96975ee411afe558642a7b8c8f501

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page