Skip to main content
Glama

get-recent-activities

Retrieve recent Strava activities to analyze workouts and track fitness progress. Fetches activity stats, heart rate data, and segment insights for performance monitoring.

Instructions

Fetches the most recent activities for the authenticated athlete.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
perPageNoNumber of activities to retrieve (default: 30)

Implementation Reference

  • The 'execute' function within the 'getRecentActivities' object contains the logic to fetch recent activities, handle authentication, and format the output.
    execute: async ({ perPage }: GetRecentActivitiesInput) => {
      const token = process.env.STRAVA_ACCESS_TOKEN;
    
      // --- DEBUGGING: Print the token being used --- 
      console.error(`[DEBUG] Using STRAVA_ACCESS_TOKEN: ${token?.substring(0, 5)}...${token?.slice(-5)}`);
      // ---------------------------------------------
    
      if (!token || token === 'YOUR_STRAVA_ACCESS_TOKEN_HERE') {
        console.error("Missing or placeholder STRAVA_ACCESS_TOKEN in .env");
        // Use literal type for content item
        return {
          content: [{ type: "text" as const, text: "❌ Configuration Error: STRAVA_ACCESS_TOKEN is missing or not set in the .env file." }],
          isError: true,
        };
      }
    
      try {
        console.error(`Fetching ${perPage} recent activities...`);
        const athlete = await getAuthenticatedAthlete(token);
        const activities = await fetchActivities(token, perPage);
        console.error(`Successfully fetched ${activities?.length ?? 0} activities.`);
    
        if (!activities || activities.length === 0) {
           return {
             content: [{ type: "text" as const, text: " MNo recent activities found." }]
            };
        }
    
        const distanceFactor = athlete.measurement_preference === 'feet' ? 0.000621371 : 0.001;
        const distanceUnit = athlete.measurement_preference === 'feet' ? 'mi' : 'km';
    
        // Map to content items with literal type
        const contentItems = activities.map(activity => {
          const dateStr = activity.start_date ? new Date(activity.start_date).toLocaleDateString() : 'N/A';
          const distanceStr = activity.distance ? `${(activity.distance * distanceFactor).toFixed(2)} ${distanceUnit}` : 'N/A';
          // Ensure each item conforms to { type: "text", text: string }
          const item: { type: "text", text: string } = {
             type: "text" as const,
             text: `🏃 ${activity.name} (ID: ${activity.id ?? 'N/A'}) — ${distanceStr} on ${dateStr}`
            };
          return item;
        });
    
        // Return the basic McpResponse structure
        return { content: contentItems };
    
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
        console.error("Error in get-recent-activities tool:", errorMessage);
        return {
          content: [{ type: "text" as const, text: `❌ API Error: ${errorMessage}` }],
          isError: true,
        };
      }
    }
  • Zod schema definition for validating the 'perPage' input parameter.
    const GetRecentActivitiesInputSchema = z.object({
      perPage: z.number().int().positive().optional().default(30).describe("Number of activities to retrieve (default: 30)"),
    });
  • Tool definition including name, description, input schema, and execution handler.
    export const getRecentActivities = {
        name: "get-recent-activities",
        description: "Fetches the most recent activities for the authenticated athlete.",
        inputSchema: GetRecentActivitiesInputSchema,

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.1

TDQS

A3.5/5.0
Behavior3/5

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

With no annotations, the description carries the full burden. It clearly indicates a read operation ('Fetches'), which implies non-destructive behavior, but it does not disclose pagination behavior, rate limits, or what 'most recent' means in terms of time range. The verb provides basic transparency but not rich details.

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 sentence with no filler or redundancy. It is front-loaded with the verb and resource, making it easy to parse and understand quickly.

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?

The tool is simple with one optional parameter and no output schema, so the description is largely adequate. However, it does not clarify how this differs from the sibling tool get-all-activities, which could lead to incorrect selection. Additionally, no behavioral edge cases are mentioned, leaving some context missing.

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

Parameters3/5

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

The input schema covers the sole parameter (perPage) with a description and default value, yielding 100% schema coverage. The tool description does not mention the parameter, but the schema already explains it, so the baseline of 3 applies.

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 uses a specific verb 'Fetches' and a clear resource: 'most recent activities' for the authenticated athlete. The scope ('most recent') helps distinguish it from siblings like get-all-activities and get-activity-details.

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?

No guidance is provided on when to use this tool versus alternatives such as get-all-activities or get-activity-details. The description simply states what it does without giving context on when it is the preferred choice.

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