Skip to main content
Glama

get_activity

Retrieve detailed information about a specific Strava activity, including segment efforts if specified, using an activity ID. Simplifies access to fitness data via the Strava MCP Server.

Instructions

Get details of a specific activity.

Args: ctx: The MCP request context activity_id: The ID of the activity include_all_efforts: Whether to include all segment efforts

Returns: The activity details

Input Schema

NameRequiredDescriptionDefault
activity_idYes
include_all_effortsNo

Input Schema (JSON Schema)

{ "properties": { "activity_id": { "title": "Activity Id", "type": "integer" }, "include_all_efforts": { "default": false, "title": "Include All Efforts", "type": "boolean" } }, "required": [ "activity_id" ], "title": "get_activityArguments", "type": "object" }

Implementation Reference

  • The MCP tool handler and registration for 'get_activity'. This function executes the tool logic by retrieving the StravaService from context and calling its get_activity method, returning the activity as a dict.
    @mcp.tool() async def get_activity( ctx: Context, activity_id: int, include_all_efforts: bool = False, ) -> dict: """Get details of a specific activity. Args: ctx: The MCP request context activity_id: The ID of the activity include_all_efforts: Whether to include all segment efforts Returns: The activity details """ try: # Safely access service from context if not ctx.request_context.lifespan_context: raise ValueError("Lifespan context not available") # Cast service to StravaService to satisfy type checker service = cast(StravaService, ctx.request_context.lifespan_context.get("service")) if not service: raise ValueError("Service not available in context") activity = await service.get_activity(activity_id, include_all_efforts) return activity.model_dump() except Exception as e: logger.error(f"Error in get_activity tool: {str(e)}") raise
  • Pydantic model DetailedActivity used for output validation and serialization of the activity details returned by the get_activity tool.
    class DetailedActivity(Activity): """Detailed version of a Strava activity.""" description: str | None = Field(None, description="The description of the activity") athlete: dict = Field(..., description="The athlete who performed the activity") calories: float | None = Field(None, description="Calories burned during activity") segment_efforts: list[dict] | None = Field(None, description="List of segment efforts") splits_metric: list[dict] | None = Field(None, description="Splits in metric units") splits_standard: list[dict] | None = Field(None, description="Splits in standard units") best_efforts: list[dict] | None = Field(None, description="List of best efforts") photos: dict | None = Field(None, description="Photos associated with activity") gear: dict | None = Field(None, description="Gear used during activity") device_name: str | None = Field(None, description="Name of device used to record activity")
  • StravaService helper method that wraps the API call to get_activity, adding logging.
    async def get_activity(self, activity_id: int, include_all_efforts: bool = False) -> DetailedActivity: """Get a specific activity. Args: activity_id: The ID of the activity include_all_efforts: Whether to include all segment efforts Returns: The activity details """ try: logger.info(f"Getting activity {activity_id}") activity = await self.api.get_activity(activity_id, include_all_efforts) logger.info(f"Retrieved activity: {activity.name}") return activity except Exception as e: logger.error(f"Error getting activity {activity_id}: {str(e)}") raise
  • StravaAPI core method that performs the HTTP GET request to Strava's /activities/{activity_id} endpoint and parses the response into DetailedActivity model.
    async def get_activity(self, activity_id: int, include_all_efforts: bool = False) -> DetailedActivity: """Get a specific activity. Args: activity_id: The ID of the activity include_all_efforts: Whether to include all segment efforts Returns: The activity details """ params = {} if include_all_efforts: params["include_all_efforts"] = "true" response = await self._request("GET", f"/activities/{activity_id}", params=params) data = response.json() return DetailedActivity(**data)

Other Tools

Related Tools

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/yorrickjansen/strava-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server