Skip to main content
Glama
rbctmz

mcp-server-strava

analyze_activity

Analyzes Strava activity data to extract performance metrics and insights. Provide an activity ID to receive detailed analysis results.

Instructions

Анализ активности из Strava

Args:
    activity_id: ID активности (строка или число)
Returns:
    dict: Результаты анализа активности

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activity_idYes

Implementation Reference

  • Main MCP tool handler: analyzes Strava activity by ID, computes pace and effort using helpers, returns structured dict with stats and analysis.
    @mcp.tool()
    def analyze_activity(activity_id: Union[str, int]) -> dict:
        """Анализ активности из Strava
    
        Args:
            activity_id: ID активности (строка или число)
        Returns:
            dict: Результаты анализа активности
        """
        activity_id = str(activity_id)
    
        try:
            activity = get_activity(activity_id)
            
            # Calculate pace and zones
            pace = _calculate_pace(activity)
            effort = _calculate_effort(activity)
            
            return {
                "type": activity.get("type"),
                "distance": activity.get("distance"),
                "moving_time": activity.get("moving_time"),
                "average_heartrate": activity.get("average_heartrate"),
                "analysis": {
                    "pace": pace,
                    "effort": effort,
                    "stats": {
                        "elapsed_time": activity.get("elapsed_time"),
                        "elevation_gain": activity.get("total_elevation_gain"),
                        "calories": activity.get("calories"),
                    }
                },
            }
        except Exception as e:
            logger.error(f"Ошибка анализа активности {activity_id}: {e}")
            return {
                "error": f"Не удалось проанализировать активность: {str(e)}",
                "activity_id": activity_id
            }
  • Calculates activity pace: minutes per km for running, km/h for cycling.
    def _calculate_pace(activity: dict) -> float:
        """Расчет темпа активности"""
        try:
            if activity.get("type") == "Run":
                # Для бега: мин/км
                return (activity.get("moving_time", 0) / 60) / (activity.get("distance", 0) / 1000)
            elif activity.get("type") == "Ride":
                # Для велосипеда: км/ч
                return (activity.get("distance", 0) / 1000) / (activity.get("moving_time", 0) / 3600)
            return 0
        except (TypeError, ZeroDivisionError):
            return 0
  • Estimates training effort level ('Легкая', 'Средняя', 'Высокая') based on average heart rate zones.
    def _calculate_effort(activity: dict) -> str:
        """Оценка нагрузки"""
        if "average_heartrate" not in activity:
            return "Неизвестно"
    
        hr = activity["average_heartrate"]
        if hr < 120:
            return "Легкая"
        if hr < 150:
            return "Средняя"
        return "Высокая"
  • src/server.py:336-336 (registration)
    MCP tool decorator that registers the analyze_activity function as a tool.
    @mcp.tool()
  • Docstring providing tool description, input parameter (activity_id: str|int), and output (dict with analysis). Serves as schema for MCP.
    """Анализ активности из Strava
    
    Args:
        activity_id: ID активности (строка или число)
    Returns:
        dict: Результаты анализа активности
    """

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