Add your description here
Project description
Strava MCP Server
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
- Clone the repository:
git clone <repository-url>
cd strava
- Install dependencies with uv:
uv install
- 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:
- The first time you make a request to the Strava API, the system checks if you have a refresh token.
- If no refresh token is found, it automatically starts a standalone OAuth server and opens your browser to the Strava authorization page.
- After authorizing the application in your browser, you'll be redirected to a local callback page.
- 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 timeafter(optional): Epoch timestamp to filter activities after a certain timepage(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 activityinclude_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 segmentgender(optional): Filter by gender ('M' or 'F')age_group(optional): Filter by age groupweight_class(optional): Filter by weight classfollowing(optional): Filter by friends of the authenticated athleteclub_id(optional): Filter by clubdate_range(optional): Filter by date rangecontext_entries(optional): Number of context entriespage(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 initializationconfig.py: Configuration settings using pydantic-settingsmodels.py: Pydantic models for Strava API entitiesapi.py: Low-level API client for Stravaauth.py: Strava OAuth authentication implementationoauth_server.py: Standalone OAuth server implementationservice.py: Service layer for business logicserver.py: MCP server implementation
tests/: Unit testsmain.py: Entry point to run the serverget_token.py: Utility script to get a refresh token manually
Running Tests
To run tests:
pytest
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9263d965e969f0025d08e02dbf78936cc47bfe5123b2f5ca79b6a8f8f38384f4
|
|
| MD5 |
96bc42c651f5bb061ee2eb04e0c237fe
|
|
| BLAKE2b-256 |
4c79acbab839b4f84ab7a352589c544448e9fa2f893984297e874a6b72b795bc
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc9ffb27145931686d0b9e5999e5166d812e4dbef317d8131c7129d59595052a
|
|
| MD5 |
a31428052b414c07a24ea50a4f0c881a
|
|
| BLAKE2b-256 |
1a551cb391e9e501ab7a0dfa38970e5f93e96975ee411afe558642a7b8c8f501
|