Skip to main content
Glama

get-route

Retrieve detailed information about a specific Strava route by providing its unique route ID. Part of the Strava MCP Server, this tool bridges the Strava API for streamlined data access.

Instructions

Fetches detailed information about a specific route using its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
routeIdYesThe unique identifier of the route to fetch.

Implementation Reference

  • The execute function implementing the core logic of the 'get-route' tool: extracts routeId, checks token, fetches route data via getRouteById helper, formats summary, handles errors gracefully.
    execute: async (input: GetRouteInput) => { const { routeId } = input; 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 route details for ID: ${routeId}...`); const route = await getRouteById(token, routeId); const summary = formatRouteSummary(route); // Call shared formatter without units console.error(`Successfully fetched route ${routeId}.`); return { content: [{ type: "text" as const, text: summary }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error fetching route ${routeId}: ${errorMessage}`); const userFriendlyMessage = errorMessage.includes("Record Not Found") || errorMessage.includes("404") ? `Route with ID ${routeId} not found.` : `An unexpected error occurred while fetching route ${routeId}. Details: ${errorMessage}`; return { content: [{ type: "text" as const, text: `โŒ ${userFriendlyMessage}` }], isError: true }; } }
  • Zod schema defining the input validation for the get-route tool, ensuring routeId is a non-empty string of digits.
    const GetRouteInputSchema = z.object({ routeId: z.string() .regex(/^\d+$/, "Route ID must contain only digits") .refine(val => val.length > 0, "Route ID cannot be empty") .describe("The unique identifier of the route to fetch.")});
  • src/server.ts:122-127 (registration)
    Registration of the get-route tool in the MCP server by calling server.tool with name, description, input schema shape, and execute handler.
    server.tool( getRouteTool.name, getRouteTool.description, getRouteTool.inputSchema?.shape ?? {}, getRouteTool.execute );
  • Supporting utility function that makes the actual Strava API call to retrieve route details by ID, with Zod validation and error handling including token refresh.
    export async function getRouteById(accessToken: string, routeId: string): Promise<StravaRoute> { const url = `routes/${routeId}`; try { const response = await stravaApi.get(url, { headers: { Authorization: `Bearer ${accessToken}` }, }); // Validate the response against the Zod schema const validatedRoute = RouteSchema.parse(response.data); return validatedRoute; } catch (error) { return await handleApiError<StravaRoute>(error, `fetching route ${routeId}`, async () => { // Use new token from environment after refresh const newToken = process.env.STRAVA_ACCESS_TOKEN!; return getRouteById(newToken, routeId); }); } }
  • Shared helper function that formats the Strava route data into a concise, readable text summary with metric units.
    export function formatRouteSummary(route: StravaRoute): string { const distanceKm = metersToKmString(route.distance); const elevation = formatElevation(route.elevation_gain); const date = new Date(route.created_at).toLocaleDateString(); const type = route.type === 1 ? 'Ride' : route.type === 2 ? 'Run' : 'Walk'; // Assuming 3 is Walk based on typical Strava usage let summary = `๐Ÿ“ Route: ${route.name} (#${route.id})\n`; summary += ` - Type: ${type}, Distance: ${distanceKm}, Elevation: ${elevation}\n`; summary += ` - Created: ${date}, Segments: ${route.segments?.length ?? 'N/A'}\n`; if (route.description) { summary += ` - Description: ${route.description.substring(0, 100)}${route.description.length > 100 ? '...' : ''}\n`; } return summary; }

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