get_activity_details_tool
Retrieve comprehensive workout data for a specific Strava activity using its ID, including metrics, route details, and performance statistics.
Instructions
Get detailed information for a specific activity.
Args: activity_id: The ID of the activity to retrieve
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| activity_id | Yes |
Implementation Reference
- server.py:94-104 (handler)The get_activity_details_tool is registered as an MCP tool using the @mcp.tool() decorator. It takes an activity_id parameter, gets a Strava client, calls get_activity_details service function, and returns the result as a dict.
@mcp.tool() def get_activity_details_tool(activity_id: int) -> dict: """ Get detailed information for a specific activity. Args: activity_id: The ID of the activity to retrieve """ client = get_client() details = get_activity_details(client, activity_id) return details.to_dict() - The get_activity_details function implements the core logic for fetching activity details from Strava API. It retrieves the activity using client.get_activity(), extracts relevant fields (including safe handling of moving_time and elapsed_time), and returns an ActivityDetails dataclass.
def get_activity_details(client: Client, activity_id: int) -> ActivityDetails: """Get detailed information for a specific activity.""" activity = client.get_activity(activity_id) moving_time = ( getattr(activity.moving_time, "seconds", 0) if activity.moving_time else 0 ) elapsed_time = ( getattr(activity.elapsed_time, "seconds", 0) if activity.elapsed_time else 0 ) return ActivityDetails( id=activity.id or 0, name=activity.name or "", description=activity.description, type=str(activity.type), distance=float(activity.distance) if activity.distance else 0.0, moving_time=moving_time, elapsed_time=elapsed_time, total_elevation_gain=float(activity.total_elevation_gain) if activity.total_elevation_gain else 0.0, average_speed=float(activity.average_speed) if activity.average_speed else 0.0, max_speed=float(activity.max_speed) if activity.max_speed else 0.0, calories=activity.calories, device_name=activity.device_name, ) - strava_mcp/models.py:60-79 (schema)The ActivityDetails dataclass defines the schema for activity detail responses, including id, name, description, type, distance, moving_time, elapsed_time, elevation_gain, speeds, calories, and device_name fields. It includes a to_dict() method for serialization.
@dataclass class ActivityDetails: """Detailed information about a Strava activity.""" id: int name: str description: Optional[str] type: str distance: float moving_time: int elapsed_time: int total_elevation_gain: float average_speed: float max_speed: float calories: Optional[float] device_name: Optional[str] def to_dict(self) -> dict: """Convert to dictionary for serialization.""" return asdict(self)