Skip to main content
Glama
rbctmz

mcp-server-strava

get_activity_recommendations

Generate personalized training recommendations by analyzing recent Strava activities to optimize workout planning and performance.

Instructions

Получить рекомендации по тренировкам на основе анализа последних активностей

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler for the 'get_activity_recommendations' tool. This function fetches recent activities from Strava, analyzes training load and intensity distribution, and generates personalized training recommendations. It is registered as an MCP tool via the @mcp.tool() decorator.
    @mcp.tool()
    def get_activity_recommendations() -> Dict:
        """Получить рекомендации по тренировкам на основе анализа последних активностей"""
        try:
            # Get recent activities with proper error handling
            try:
                activities = get_recent_activities()
            except StravaApiError as e:
                return {
                    "status": "error",
                    "error": str(e),
                    "recommendations": ["Проверьте подключение к Strava"]
                }
    
            if not activities:
                return {
                    "status": "warning",
                    "error": "Нет активностей за последние 30 дней",
                    "recommendations": ["Начните записывать тренировки"]
                }
    
            # Analyze training load
            analysis = analyze_training_load(activities)
            
            recommendations = []
    
            # Анализ разнообразия тренировок
            activity_types = analysis["activities_by_type"]
            total_activities = analysis["activities_count"]
    
            # Анализ интенсивности по зонам
            zones = analysis["heart_rate_zones"]
            total_zone_activities = sum(zones.values())
            if total_zone_activities > 0:
                easy_percent = (zones["easy"] / total_zone_activities) * 100
                medium_percent = (zones["medium"] / total_zone_activities) * 100
                hard_percent = (zones["hard"] / total_zone_activities) * 100
    
                # Проверка распределения интенсивности
                if easy_percent < 70:
                    recommendations.append(
                        f"Слишком мало легких тренировок ({easy_percent:.0f}%). "
                        "Рекомендуется:\n"
                        "- Добавить восстановительные тренировки\n"
                        "- Больше базовых тренировок в низких пульсовых зонах\n"
                        "- Использовать контроль пульса во время тренировок"
                    )
    
                if medium_percent > 40:
                    recommendations.append(
                        f"Большой процент тренировок в средней зоне ({medium_percent:.0f}%). "
                        "Рекомендуется:\n"
                        "- Четко разделять легкие и интенсивные тренировки\n"
                        "- Избегать тренировок в 'серой зоне'"
                    )
    
            # Анализ объемов по видам спорта
            if "Run" in activity_types:
                run_volume = sum(a.get("distance", 0) for a in activities if a.get("type") == "Run") / 1000
                if run_volume < 20:
                    recommendations.append(
                        f"Беговой объем ({run_volume:.1f} км) ниже оптимального.\n"
                        "Рекомендации по увеличению:\n"
                        "- Добавить 1-2 км к длинной пробежке еженедельно\n"
                        "- Включить легкие восстановительные пробежки\n"
                        "- Постепенно довести объем до 30-40 км в неделю"
                    )
    
            # Анализ общего объема
            weekly_distance = analysis["total_distance"]
            weekly_hours = analysis["total_time"]
    
            if weekly_hours < 5:
                recommendations.append(
                    f"Общий объем ({weekly_hours:.1f} ч) можно увеличить.\n"
                    "Рекомендации:\n"
                    "- Постепенно добавлять по 30 минут в неделю\n"
                    "- Включить кросс-тренировки для разнообразия\n"
                    "- Следить за самочувствием при увеличении нагрузок"
                )
    
            # Рекомендации по восстановлению
            if total_zone_activities > 5:
                recommendations.append(
                    "Рекомендации по восстановлению:\n"
                    "- Обеспечить 7-8 часов сна\n"
                    "- Планировать легкие дни после интенсивных тренировок\n"
                    "- Следить за питанием и гидратацией"
                )
    
            # Если всё сбалансировано
            if not recommendations:
                recommendations.append(
                    "Тренировки хорошо сбалансированы!\n"
                    "Рекомендации по поддержанию формы:\n"
                    "- Продолжать текущий план тренировок\n"
                    "- Вести дневник тренировок\n"
                    "- Регулярно анализировать прогресс"
                )
    
            # Форматируем вывод для лучшей читаемости
            result = {
                "analysis": {
                    "activities": {
                        "total": analysis["activities_count"],
                        "distance": f"{analysis['total_distance']:.1f} км",
                        "time": f"{analysis['total_time']:.1f} ч",
                        "distribution": {
                            activity: {
                                "count": count,
                                "percent": f"{(count / total_activities * 100):.0f}%",
                            }
                            for activity, count in activity_types.items()
                        },
                    },
                    "intensity": {
                        "zones": {
                            "easy": f"{easy_percent:.0f}%" if total_zone_activities > 0 else "0%",
                            "medium": f"{medium_percent:.0f}%" if total_zone_activities > 0 else "0%",
                            "hard": f"{hard_percent:.0f}%" if total_zone_activities > 0 else "0%",
                        },
                        "status": "Сбалансировано" if 60 <= easy_percent <= 80 else "Требует корректировки",
                    },
                },
                "recommendations": [
                    {"category": recommendation.split("\n")[0], "details": recommendation.split("\n")[1:]}
                    for recommendation in recommendations
                ],
                "summary": {
                    "status": "✅ Тренировки сбалансированы"
                    if not recommendations
                    else "⚠️ Есть рекомендации",
                    "weekly": {
                        "activities": total_activities,
                        "distance": f"{weekly_distance:.1f} км",
                        "time": f"{weekly_hours:.1f} ч",
                    },
                },
            }
            return result
    
        except StravaApiError as e:
            logger.error(f"Ошибка API Strava: {e}")
            return {
                "status": "error",
                "error": str(e),
                "recommendations": ["Проверьте подключение к Strava"]
            }
        except Exception as e:
            logger.error(f"Непредвиденная ошибка: {e}")
            return {
                "status": "error",
                "error": "Внутренняя ошибка сервера",
                "details": str(e)
            }
  • src/server.py:449-449 (registration)
    The @mcp.tool() decorator registers the get_activity_recommendations function as an MCP tool.
    @mcp.tool()
  • Helper function analyze_training_load that calculates summary statistics for activities, used internally by the recommendations handler.
    @mcp.tool()
    def analyze_training_load(activities: List[Dict]) -> Dict:
        """Анализ тренировочной нагрузки"""
        if not activities:
            return {
                "error": "Нет активностей для анализа",
                "activities_count": 0
            }
        summary = {
            "activities_count": len(activities),
            "total_distance": 0,
            "total_time": 0,
            "activities_by_type": {},
            "heart_rate_zones": {
                "easy": 0,  # ЧСС < 120
                "medium": 0,  # ЧСС 120-150
                "hard": 0,  # ЧСС > 150
            },
        }
    
        for activity in activities:
            activity_type = activity.get("type")
    
            # Обновляем счетчик типа активности
            if activity_type not in summary["activities_by_type"]:
                summary["activities_by_type"][activity_type] = 0
            summary["activities_by_type"][activity_type] += 1
    
            # Суммируем дистанцию и время
            summary["total_distance"] += activity.get("distance", 0)
            summary["total_time"] += activity.get("moving_time", 0)
    
            # Анализируем зоны ЧСС
            hr = activity.get("average_heartrate", 0)
            if hr:
                if hr < 120:
                    summary["heart_rate_zones"]["easy"] += 1
                elif hr < 150:
                    summary["heart_rate_zones"]["medium"] += 1
                else:
                    summary["heart_rate_zones"]["hard"] += 1
    
        # Конвертируем единицы измерения
        summary["total_distance"] = round(summary["total_distance"] / 1000, 2)  # в километры
        summary["total_time"] = round(summary["total_time"] / 3600, 2)  # в часы
    
        return summary
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool gets recommendations based on analysis of recent activities, but doesn't describe how it works (e.g., what data it accesses, whether it's read-only or modifies data, response format, or any limitations like rate limits). This is a significant gap for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence in Russian: 'Получить рекомендации по тренировкам на основе анализа последних активностей'. It's front-loaded with the core purpose and has zero waste, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a simple input schema with 0 parameters, the description is incomplete. It states what the tool does but lacks crucial behavioral context (e.g., how it analyzes activities, what data it returns, any side effects). For a recommendation tool, this leaves the agent with insufficient information to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameters need documentation. The description doesn't add parameter details, which is appropriate here. Baseline is 4 for zero parameters, as there's nothing to compensate for, and the description doesn't introduce unnecessary complexity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Получить рекомендации по тренировкам на основе анализа последних активностей' (Get training recommendations based on analysis of recent activities). It specifies both the action (get recommendations) and the resource (training recommendations), and distinguishes it from siblings like analyze_activity or get_activity_by_id by focusing on recommendations rather than analysis or retrieval. However, it doesn't explicitly differentiate from analyze_training_load, which might be related, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no explicit guidance on when to use this tool versus alternatives. It implies usage for getting recommendations based on recent activities, but doesn't specify prerequisites, when not to use it, or name alternatives like analyze_training_load for comparison. This leaves the agent with minimal context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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