Skip to main content
Glama

get-athlete-stats

Retrieve activity statistics for a specific Strava athlete using their ID. Fetches recent, year-to-date, and all-time performance data to analyze workouts and track fitness progress.

Instructions

Fetches the activity statistics (recent, YTD, all-time) for a specific athlete using their ID. Requires the athleteId obtained from the get-athlete-profile tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
athleteIdYesThe unique identifier of the athlete to fetch stats for. Obtain this ID first by calling the get-athlete-profile tool.

Implementation Reference

  • The get-athlete-stats tool definition and handler implementation. It uses the `fetchAthleteStats` helper to get statistics from the Strava API and then formats them for the user.
    export const getAthleteStatsTool = {
        name: "get-athlete-stats",
        description: "Fetches the activity statistics (recent, YTD, all-time) for a specific athlete using their ID. Requires the athleteId obtained from the get-athlete-profile tool.",
        inputSchema: GetAthleteStatsInputSchema,
        execute: async ({ athleteId }: GetAthleteStatsInput) => {
            const token = process.env.STRAVA_ACCESS_TOKEN;
    
            if (!token) {
                 console.error("Missing STRAVA_ACCESS_TOKEN environment variable.");
                 return {
                    content: [{ type: "text" as const, text: "Configuration error: Missing Strava access token." }],
                    isError: true
                };
            }
    
            try {
                console.error(`Fetching stats for athlete ${athleteId}...`);
                const stats = await fetchAthleteStats(token, athleteId);
                const formattedStats = formatStats(stats);
    
                console.error(`Successfully fetched stats for athlete ${athleteId}.`);
                return { content: [{ type: "text" as const, text: formattedStats }] };
            } catch (error) {
                const errorMessage = error instanceof Error ? error.message : String(error);
                console.error(`Error fetching stats for athlete ${athleteId}: ${errorMessage}`);
                const userFriendlyMessage = errorMessage.includes("Record Not Found") || errorMessage.includes("404")
                    ? `Athlete with ID ${athleteId} not found (when fetching stats).`
                    : `An unexpected error occurred while fetching stats for athlete ${athleteId}. Details: ${errorMessage}`;
                return {
                    content: [{ type: "text" as const, text: `❌ ${userFriendlyMessage}` }],
                    isError: true
                };
            }
        }
    };
  • Input validation schema for the get-athlete-stats tool.
    const GetAthleteStatsInputSchema = z.object({
        athleteId: z.number().int().positive().describe("The unique identifier of the athlete to fetch stats for. Obtain this ID first by calling the get-athlete-profile tool.")
    });
  • Formatting helpers to convert Strava API stats data into readable strings for the LLM.
    function formatStat(value: number | null | undefined, unit: 'km' | 'm' | 'hrs'): string {
        if (value === null || value === undefined) return 'N/A';
    
        let formattedValue: string;
        if (unit === 'km') {
            formattedValue = (value / 1000).toFixed(2);
        } else if (unit === 'm') {
            formattedValue = Math.round(value).toString();
        } else if (unit === 'hrs') {
            formattedValue = (value / 3600).toFixed(1);
        } else {
            formattedValue = value.toString();
        }
        return `${formattedValue} ${unit}`;
    }
    
    const activityTypes = [
        { key: "ride", label: "Rides" },
        { key: "run", label: "Runs" },
        { key: "swim", label: "Swims" },
    ] as const;
    
    type ActivityTotals = StravaStats["recent_ride_totals"];
    
    function getTotals(stats: StravaStats, prefix: "recent" | "ytd" | "all", type: "ride" | "run" | "swim"): ActivityTotals {
        const key = `${prefix}_${type}_totals` as keyof StravaStats;
        return stats[key] as ActivityTotals;
    }
    
    function formatStats(stats: StravaStats): string {
        const format = (label: string, total: number | null | undefined, unit: 'km' | 'm' | 'hrs', count?: number | null, time?: number | null) => {
            let line = `   - ${label}: ${formatStat(total, unit)}`;
            if (count !== undefined && count !== null) line += ` (${count} activities)`;
            if (time !== undefined && time !== null) line += ` / ${formatStat(time, 'hrs')} hours`;
            return line;
        };
    
        const periods = [
            { prefix: "recent", label: (type: string) => `*Recent ${type} (last 4 weeks):*` },
            { prefix: "ytd", label: (type: string) => `*Year-to-Date ${type}:*` },
            { prefix: "all", label: (type: string) => `*All-Time ${type}:*` },
        ] as const;
    
        let response = "📊 **Your Strava Stats:**\n";
    
        if (stats.biggest_ride_distance != null) {
            response += format("Biggest Ride Distance", stats.biggest_ride_distance, 'km') + '\n';
        }
        if (stats.biggest_climb_elevation_gain != null) {
            response += format("Biggest Climb Elevation Gain", stats.biggest_climb_elevation_gain, 'm') + '\n';
        }
    
        for (const { key, label } of activityTypes) {
            response += `\n**${label}:**\n`;
            for (const period of periods) {
                const totals = getTotals(stats, period.prefix, key);
                response += period.label(label) + '\n';
                response += format("Distance", totals.distance, 'km', totals.count, totals.moving_time) + '\n';
                response += format("Elevation Gain", totals.elevation_gain, 'm') + '\n';
            }
        }
    
        return response;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.1

TDQS

A4.3/5.0
Behavior3/5

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

No annotations are provided, so the description carries full burden. It mentions the prerequisite (athleteId requirement) which is useful context, but doesn't disclose other behavioral traits like rate limits, authentication needs, error conditions, or what the output format looks like (since no output schema exists).

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?

Two sentences with zero waste. The first sentence states purpose and scope, the second provides critical prerequisite information. Every word earns its place and the description is appropriately sized for a single-parameter tool.

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

Completeness3/5

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

For a read-only tool with 100% schema coverage but no annotations and no output schema, the description provides adequate purpose and usage guidance. However, it lacks information about return values (what the stats actually contain) and other behavioral context that would be helpful given the absence of structured output documentation.

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%, so the schema already documents the single parameter. The description adds value by explaining where to obtain the athleteId ('from the get-athlete-profile tool'), which provides practical guidance beyond the schema's technical specification.

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 states the specific action ('fetches') and resource ('activity statistics for a specific athlete'), specifying the types of statistics (recent, YTD, all-time). It distinguishes from siblings like 'get-athlete-profile' by focusing on stats rather than profile data.

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

Usage Guidelines5/5

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

Explicitly states when to use this tool ('for a specific athlete using their ID') and provides a prerequisite ('Requires the athleteId obtained from the get-athlete-profile tool'), clearly differentiating it from alternatives that don't require this ID or fetch different data types.

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