Skip to main content
Glama
SkyBlob12

Strava MCP Server

by SkyBlob12

Calculer la charge d'entraînement (CTL/ATL/TSB)

strava_training_load

Calculate your chronic training load (CTL), acute fatigue (ATL), and training stress balance (TSB) from Strava data to assess fitness, fatigue, and freshness for optimized training.

Instructions

Calcule les métriques de forme, fatigue et fraîcheur via des moyennes exponentielles. CTL (fitness chronique, 42j) / ATL (fatigue aiguë, 7j) / TSB = CTL - ATL (fraîcheur). TSB > +10 = frais pour une course ; TSB < -20 = surcharge.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoJours d'historique (min 42 pour que CTL soit significatif)
hr_restNoFréquence cardiaque au repos (bpm)
hr_maxNoFréquence cardiaque maximale (bpm)
show_dailyNoAfficher les données jour par jour (sinon juste la synthèse)

Implementation Reference

  • Handler function for the 'strava_training_load' tool. It fetches Strava activities, computes training load points via computeTrainingLoad, and returns CTL/ATL/TSB metrics with an optional daily breakdown.
    async ({ days, hr_rest, hr_max, show_daily }) => {
      const afterEpoch = Math.floor(Date.now() / 1000) - days * 86400 - 86400;
      const activities = await listAllActivities(afterEpoch);
      const loadPoints = computeTrainingLoad(activities, days, hr_rest, hr_max);
    
      const latest = loadPoints[loadPoints.length - 1];
      const summary = {
        date: latest.date,
        CTL_fitness: latest.ctl,
        ATL_fatigue: latest.atl,
        TSB_fraicheur: latest.tsb,
        interpretation: interpretTSB(latest.tsb),
        evolution_7j: {
          CTL_avant: loadPoints[loadPoints.length - 8]?.ctl ?? null,
          CTL_maintenant: latest.ctl,
          tendance: latest.ctl > (loadPoints[loadPoints.length - 8]?.ctl ?? 0) ? "↑ progression" : "↓ récupération",
        },
      };
    
      const result: Record<string, unknown> = { synthese: summary };
    
      if (show_daily) {
        // Only last 30 days for readability
        result.detail_30j = loadPoints.slice(-30);
      }
    
      return {
        content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
      };
    }
  • Schema definition and registration of the 'strava_training_load' tool. Defines input parameters: days (42-365, default 90), hr_rest (30-80, default 50), hr_max (150-220, default 190), and show_daily (boolean, default false).
    {
      title: "Calculer la charge d'entraînement (CTL/ATL/TSB)",
      description:
        "Calcule les métriques de forme, fatigue et fraîcheur via des moyennes exponentielles. " +
        "CTL (fitness chronique, 42j) / ATL (fatigue aiguë, 7j) / TSB = CTL - ATL (fraîcheur). " +
        "TSB > +10 = frais pour une course ; TSB < -20 = surcharge.",
      inputSchema: z.object({
        days: z
          .number()
          .int()
          .min(42)
          .max(365)
          .default(90)
          .describe("Jours d'historique (min 42 pour que CTL soit significatif)"),
        hr_rest: z
          .number()
          .int()
          .min(30)
          .max(80)
          .default(50)
          .describe("Fréquence cardiaque au repos (bpm)"),
        hr_max: z
          .number()
          .int()
          .min(150)
          .max(220)
          .default(190)
          .describe("Fréquence cardiaque maximale (bpm)"),
        show_daily: z
          .boolean()
          .default(false)
          .describe("Afficher les données jour par jour (sinon juste la synthèse)"),
      }),
  • Registration of the 'strava_training_load' tool via server.registerTool() inside registerAnalysisTools(), which is called from src/index.ts line 16.
    server.registerTool(
      "strava_training_load",
      {
        title: "Calculer la charge d'entraînement (CTL/ATL/TSB)",
        description:
          "Calcule les métriques de forme, fatigue et fraîcheur via des moyennes exponentielles. " +
          "CTL (fitness chronique, 42j) / ATL (fatigue aiguë, 7j) / TSB = CTL - ATL (fraîcheur). " +
          "TSB > +10 = frais pour une course ; TSB < -20 = surcharge.",
        inputSchema: z.object({
          days: z
            .number()
            .int()
            .min(42)
            .max(365)
            .default(90)
            .describe("Jours d'historique (min 42 pour que CTL soit significatif)"),
          hr_rest: z
            .number()
            .int()
            .min(30)
            .max(80)
            .default(50)
            .describe("Fréquence cardiaque au repos (bpm)"),
          hr_max: z
            .number()
            .int()
            .min(150)
            .max(220)
            .default(190)
            .describe("Fréquence cardiaque maximale (bpm)"),
          show_daily: z
            .boolean()
            .default(false)
            .describe("Afficher les données jour par jour (sinon juste la synthèse)"),
        }),
      },
      async ({ days, hr_rest, hr_max, show_daily }) => {
        const afterEpoch = Math.floor(Date.now() / 1000) - days * 86400 - 86400;
        const activities = await listAllActivities(afterEpoch);
        const loadPoints = computeTrainingLoad(activities, days, hr_rest, hr_max);
    
        const latest = loadPoints[loadPoints.length - 1];
        const summary = {
          date: latest.date,
          CTL_fitness: latest.ctl,
          ATL_fatigue: latest.atl,
          TSB_fraicheur: latest.tsb,
          interpretation: interpretTSB(latest.tsb),
          evolution_7j: {
            CTL_avant: loadPoints[loadPoints.length - 8]?.ctl ?? null,
            CTL_maintenant: latest.ctl,
            tendance: latest.ctl > (loadPoints[loadPoints.length - 8]?.ctl ?? 0) ? "↑ progression" : "↓ récupération",
          },
        };
    
        const result: Record<string, unknown> = { synthese: summary };
    
        if (show_daily) {
          // Only last 30 days for readability
          result.detail_30j = loadPoints.slice(-30);
        }
    
        return {
          content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
        };
      }
    );
  • Core helper module: computeTRIMP calculates training impulse from heart rate data; computeTrainingLoad builds daily TRIMP map and applies exponential moving averages for CTL (42-day), ATL (7-day), and TSB; interpretTSB provides French-language text interpretation of the TSB score.
    import type { StravaActivity, TrainingLoadPoint } from "../types.js";
    
    const LAMBDA_CTL = 2 / 43; // 42-day EMA
    const LAMBDA_ATL = 2 / 8;  // 7-day EMA
    
    export function computeTRIMP(
      activity: StravaActivity,
      hrRest = 50,
      hrMax = 190
    ): number {
      const durationMin = activity.moving_time / 60;
    
      if (activity.average_heartrate && activity.average_heartrate > hrRest) {
        const hrRatio = (activity.average_heartrate - hrRest) / (hrMax - hrRest);
        const trimp = durationMin * hrRatio * 0.64 * Math.exp(1.92 * hrRatio);
        return Math.max(0, trimp);
      }
    
      // Fallback: distance-based proxy
      const distKm = activity.distance / 1000;
      return distKm * 5;
    }
    
    export function computeTrainingLoad(
      activities: StravaActivity[],
      days: number,
      hrRest = 50,
      hrMax = 190
    ): TrainingLoadPoint[] {
      // Build a day → TRIMP map
      const trimpByDay = new Map<string, number>();
      const RUN_TYPES = new Set(["Run", "VirtualRun", "TrailRun"]);
      const runs = activities.filter((a) => RUN_TYPES.has(a.type) && !a.trainer);
    
      for (const activity of runs) {
        const date = activity.start_date.slice(0, 10);
        const trimp = computeTRIMP(activity, hrRest, hrMax);
        trimpByDay.set(date, (trimpByDay.get(date) ?? 0) + trimp);
      }
    
      // Generate date range and apply EMA
      const result: TrainingLoadPoint[] = [];
      const endDate = new Date();
      const startDate = new Date();
      startDate.setDate(endDate.getDate() - days + 1);
    
      let ctl = 0;
      let atl = 0;
    
      const cursor = new Date(startDate);
      while (cursor <= endDate) {
        const dateStr = cursor.toISOString().slice(0, 10);
        const trimp = trimpByDay.get(dateStr) ?? 0;
    
        ctl = trimp * LAMBDA_CTL + (1 - LAMBDA_CTL) * ctl;
        atl = trimp * LAMBDA_ATL + (1 - LAMBDA_ATL) * atl;
    
        result.push({
          date: dateStr,
          trimp: Math.round(trimp * 10) / 10,
          ctl: Math.round(ctl * 10) / 10,
          atl: Math.round(atl * 10) / 10,
          tsb: Math.round((ctl - atl) * 10) / 10,
        });
    
        cursor.setDate(cursor.getDate() + 1);
      }
    
      return result;
    }
    
    export function interpretTSB(tsb: number): string {
      if (tsb > 25) return "Très frais (risque de désentraînement)";
      if (tsb > 10) return "Frais et reposé — idéal pour une course";
      if (tsb > 0) return "Légèrement fatigué — bonne forme d'entraînement";
      if (tsb > -10) return "Fatigué — charge d'entraînement normale";
      if (tsb > -20) return "Significativement fatigué — surveille la récupération";
      if (tsb > -30) return "Très fatigué — risque de surentraînement";
      return "Surcharge — repos nécessaire";
    }
Behavior3/5

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

With no annotations, the description should carry the full burden of disclosing behavior. It explains the calculation method and interpretation, but does not clarify whether the tool makes external API calls or is purely computational given parameters. No side effects or authorization needs are mentioned.

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 two sentences, front-loaded with the primary purpose, followed by concise interpretation thresholds. No superfluous words; every sentence adds value.

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

Completeness4/5

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

Given the tool's simplicity and lack of output schema, the description covers the key metrics and their practical use. It could optionally describe the return format (e.g., numeric values for CTL, ATL, TSB) but is otherwise complete for an agent to understand the tool's output.

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?

Schema description coverage is 100%, and the description adds meaningful context beyond field names, such as explaining why 'days' must be at least 42 for CTL significance and providing real-world interpretation of TSB thresholds. This enhances understanding of parameter significance.

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

Purpose5/5

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

The description clearly defines the tool as calculating training load metrics (CTL/ATL/TSB) via exponential averages, specifying each metric's time window and interpretation. This uniquely distinguishes it from sibling tools like strava_analyze_training or strava_vdot, which focus on other aspects.

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

Usage Guidelines3/5

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

The description provides interpretation thresholds (TSB > +10 fresh, TSB < -20 overload), implying usage for assessing training readiness. However, it does not explicitly state when to use this tool versus alternatives like strava_analyze_training, nor does it mention any prerequisites or exclusions.

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/SkyBlob12/McpStrava'

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