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
| Name | Required | Description | Default |
|---|---|---|---|
| activity_id | Yes |
Implementation Reference
- src/strava_mcp_server/server.py:269-289 (handler)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