Skip to main content
Glama
tomekkorbak

Strava MCP Server

by tomekkorbak

get_activity_by_id

Retrieve detailed information about a specific Strava activity using its unique ID to access performance metrics, route data, and workout statistics.

Instructions

Get detailed information about a specific activity. Args: activity_id: ID of the activity to retrieve Returns: Dictionary containing activity details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activity_idYes

Implementation Reference

  • The primary handler for the 'get_activity_by_id' MCP tool. It is registered via the @mcp.tool() decorator, which also infers the input schema from the function signature and docstring. The function retrieves the activity using the StravaClient instance.
    @mcp.tool() def get_activity_by_id(activity_id: int) -> dict[str, Any]: """ Get detailed information about a specific activity. Args: activity_id: ID of the activity to retrieve Returns: Dictionary containing activity details """ if strava_client is None: return { "error": "Strava client not initialized. Please provide refresh token, client ID, and client secret." # noqa: E501 } try: activity = strava_client.get_activity(activity_id) return {"data": activity} except Exception as e: return {"error": str(e)}
  • Supporting method in the StravaClient class that performs the actual Strava API request for a specific activity ID and applies field filtering via _filter_activity.
    def get_activity(self, activity_id: int) -> dict: """ Get detailed information about a specific activity. Args: activity_id: ID of the activity to retrieve Returns: Activity details """ activity = self._make_request(f"activities/{activity_id}") return self._filter_activity(activity)
  • Helper method that filters and renames fields in the raw Strava activity data to include units and selected keys only.
    def _filter_activity(self, activity: dict) -> dict: """Filter activity to only include specific keys and rename with units.""" # Define field mappings with units field_mappings = { "calories": "calories", "distance": "distance_metres", "elapsed_time": "elapsed_time_seconds", "elev_high": "elev_high_metres", "elev_low": "elev_low_metres", "end_latlng": "end_latlng", "average_speed": "average_speed_mps", # metres per second "max_speed": "max_speed_mps", # metres per second "moving_time": "moving_time_seconds", "sport_type": "sport_type", "start_date": "start_date", "start_latlng": "start_latlng", "total_elevation_gain": "total_elevation_gain_metres", "name": "name", # Keep name for display purposes } # Create a new dictionary with renamed fields filtered_activity = {} for old_key, new_key in field_mappings.items(): if old_key in activity: filtered_activity[new_key] = activity[old_key] return filtered_activity

Latest Blog Posts

MCP directory API

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