Skip to main content
Glama

get_activity_by_id

Retrieve detailed activity information from Strava by providing a specific activity ID. Returns metrics like type, distance, time, and other performance data for analysis.

Instructions

Get activity details from Strava

Args: activity_id (Union[str, int]): Activity ID to fetch Returns: Dict: Activity details including type, distance, time and other metrics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activity_idYes

Implementation Reference

  • The main MCP tool handler for 'get_activity_by_id'. Decorated with @mcp.tool() for registration. Fetches activity details via helper function, adds metadata, and handles errors.
    @mcp.tool() # Убираем name параметр async def get_activity_by_id(activity_id: Union[str, int]) -> Dict: """Get activity details from Strava Args: activity_id (Union[str, int]): Activity ID to fetch Returns: Dict: Activity details including type, distance, time and other metrics """ try: activity_id = str(activity_id) activity = get_activity(activity_id) return { "status": "success", "data": activity, "metadata": { "activity_id": activity_id, "timestamp": datetime.now().isoformat() } } except Exception as e: logger.error(f"Error getting activity {activity_id}: {e}") return { "status": "error", "error": str(e), "activity_id": activity_id }
  • Helper resource function that performs the actual Strava API call to fetch activity details, with caching and error handling. Called by the main tool handler.
    @resource_error_handler @mcp.resource("strava://activities/{activity_id}") def get_activity(activity_id: str) -> dict: """Получить детали конкретной активности""" cache_key = f"activity_{activity_id}" # Проверяем кэш cached = strava_cache.get(cache_key) if cached: logger.debug(f"Возвращаем активность {activity_id} из кэша") return cached try: access_token = strava_auth.get_access_token() response = strava_auth.make_request( "GET", f"/activities/{activity_id}", headers={"Authorization": f"Bearer {access_token}"}, ) activity = response.json() # Сохраняем в кэш strava_cache.set(cache_key, activity) logger.info(f"Получена и закэширована активность {activity_id}: {activity.get('type')}") return activity except Exception as e: logger.error(f"Ошибка получения активности {activity_id}: {e}") if isinstance(e, requests.exceptions.RequestException): raise StravaApiError(f"Ошибка API Strava: {str(e)}") raise RuntimeError(f"Не удалось получить активность: {str(e)}")
  • src/server.py:306-306 (registration)
    The @mcp.tool() decorator registers the get_activity_by_id function as an MCP tool.
    @mcp.tool() # Убираем name параметр

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

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