Skip to main content
Glama

get-activity-details

Retrieve comprehensive details of a specific Strava activity using its unique ID. Enables precise access to activity data for analysis or integration purposes.

Instructions

Fetches detailed information about a specific activity using its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activityIdYesThe unique identifier of the activity to fetch details for.

Implementation Reference

  • The main handler function that fetches the activity details from Strava using the provided activity ID, formats them, and returns the formatted text or an error.
    execute: async ({ activityId }: GetActivityDetailsInput) => { 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 details for activity ID: ${activityId}...`); // Removed getAuthenticatedAthlete call const activity = await fetchActivityById(token, activityId); const activityDetailsText = formatActivityDetails(activity); // Use metric formatter console.error(`Successfully fetched details for activity: ${activity.name}`); return { content: [{ type: "text" as const, text: activityDetailsText }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error fetching activity ${activityId}: ${errorMessage}`); // Removed call to handleApiError const userFriendlyMessage = errorMessage.includes("Record Not Found") || errorMessage.includes("404") ? `Activity with ID ${activityId} not found.` : `An unexpected error occurred while fetching activity details for ID ${activityId}. Details: ${errorMessage}`; return { content: [{ type: "text" as const, text: `❌ ${userFriendlyMessage}` }], isError: true }; } }
  • Zod input schema defining the required activityId parameter.
    const GetActivityDetailsInputSchema = z.object({ activityId: z.number().int().positive().describe("The unique identifier of the activity to fetch details for.") });
  • src/server.ts:62-67 (registration)
    Registration of the get-activity-details tool on the MCP server using the tool object.
    server.tool( getActivityDetailsTool.name, getActivityDetailsTool.description, getActivityDetailsTool.inputSchema?.shape ?? {}, getActivityDetailsTool.execute );
  • Helper function that formats the raw Strava activity data into a human-readable string with metrics in km, m, km/h, etc.
    function formatActivityDetails(activity: StravaDetailedActivity): string { const date = new Date(activity.start_date_local).toLocaleString(); const movingTime = formatDuration(activity.moving_time); const elapsedTime = formatDuration(activity.elapsed_time); const distance = formatDistance(activity.distance); const elevation = formatElevation(activity.total_elevation_gain); const avgSpeed = formatSpeed(activity.average_speed); const maxSpeed = formatSpeed(activity.max_speed); const avgPace = formatPace(activity.average_speed); // Calculate pace from speed let details = `🏃 **${activity.name}** (ID: ${activity.id})\n`; details += ` - Type: ${activity.type} (${activity.sport_type})\n`; details += ` - Date: ${date}\n`; details += ` - Moving Time: ${movingTime}, Elapsed Time: ${elapsedTime}\n`; if (activity.distance !== undefined) details += ` - Distance: ${distance}\n`; if (activity.total_elevation_gain !== undefined) details += ` - Elevation Gain: ${elevation}\n`; if (activity.average_speed !== undefined) { details += ` - Average Speed: ${avgSpeed}`; if (activity.type === 'Run') details += ` (Pace: ${avgPace})`; details += '\n'; } if (activity.max_speed !== undefined) details += ` - Max Speed: ${maxSpeed}\n`; if (activity.average_cadence !== undefined && activity.average_cadence !== null) details += ` - Avg Cadence: ${activity.average_cadence.toFixed(1)}\n`; if (activity.average_watts !== undefined && activity.average_watts !== null) details += ` - Avg Watts: ${activity.average_watts.toFixed(1)}\n`; if (activity.average_heartrate !== undefined && activity.average_heartrate !== null) details += ` - Avg Heart Rate: ${activity.average_heartrate.toFixed(1)} bpm\n`; if (activity.max_heartrate !== undefined && activity.max_heartrate !== null) details += ` - Max Heart Rate: ${activity.max_heartrate.toFixed(0)} bpm\n`; if (activity.calories !== undefined) details += ` - Calories: ${activity.calories.toFixed(0)}\n`; if (activity.description) details += ` - Description: ${activity.description}\n`; if (activity.gear) details += ` - Gear: ${activity.gear.name}\n`; return details; }

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/r-huijts/strava-mcp'

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