We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tomekkorbak/strava-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
server.cpython-312.pyc•14.2 KiB
�
���g`- � �� � d Z ddlZddlZddlmZmZmZ ddlmZmZ ddl Z ddl
mZ ddlm
Z
e
� G d� d� Zd ed
efd�Zded
efd
�Zded
efd�Z ed� Zej* j- d� Zej* j- d� Zej* j- d� Zdaererer
eeee� aej7 � d ded
eeef fd�� Zej7 � d!dededed
eeef fd�� Zej7 � ded
eeef fd�� Zej7 � d"deded
eeef fd�� Z ej7 � d
eeef fd�� Z!d#d�Z"e#dk( r e"� yy)$zt
MCP server for Strava API integration.
This server exposes methods to query the Strava API for athlete activities.
� N)�date�datetime� timedelta)�Any�Optional)�FastMCP)�load_dotenvc � � e Zd ZdZdZdededefd�Zdd �Zdd
�Zddede e
defd
�Zdde
de e
de e
defd�Zde
de
fd�Zde
de
fd�Zdedefd�Zde
fd�Zdd�Zy)�StravaClientz+Client for interacting with the Strava API.zhttps://www.strava.com/api/v3�
refresh_token� client_id�
client_secretc � � || _ || _ || _ d| _ d| _ t j d�� | _ y)z�
Initialize the Strava API client.
Args:
refresh_token: Refresh token for Strava API
client_id: Client ID for Strava API
client_secret: Client secret for Strava API
Nr g >@)�timeout)r r
r �access_token�
expires_at�httpx�Client�client)�selfr r
r s �H/Users/tomek/workspace/strava-mcp-server/src/strava_mcp_server/server.py�__init__zStravaClient.__init__ s: � � +���"���*��� �������l�l�4�0��� �returnNc � � t t j � � }| j r|| j k\ r| j � yy)z=Ensure we have a valid access token, refreshing if necessary.N)�int�timer r �_refresh_token)r �current_times r �_ensure_valid_tokenz StravaClient._ensure_valid_token) s: � ��4�9�9�;�'�� � � �L�D�O�O�$C����!� %Dr c �V � d}| j | j | j dd�}| j j ||�� }|j
dk7 r'd|j
� d|j � �}t |� �|j � }|d | _ |d | _
t d
� y)z1Refresh the access token using the refresh token.z"https://www.strava.com/oauth/tokenr )r
r r �
grant_type)�data�� �Error �: r r zToken refreshed successfullyN)r
r r r �post�status_code�text� Exception�jsonr r �print)r �refresh_url�payload�response� error_msg�
token_datas r r zStravaClient._refresh_token1 s� � �:�����!�/�/�!�/�/�)�
�� �;�;�#�#�K�g�#�>�����3�&� ��!5�!5� 6�b�����H�I��I�&�&��]�]�_�
�&�~�6���$�\�2���
�,�-r �endpoint�paramsc �. � | j � | j � d|� �}dd| j � �i}| j j |||�� }|j
dk7 r'd|j
� d|j � �}t |� �|j � S )z0Make an authenticated request to the Strava API.�/�
AuthorizationzBearer )�headersr3 r$ r% r&