get-route
Fetch detailed information about a specific Strava route using its unique ID to access route data for planning or analysis.
Instructions
Fetches detailed information about a specific route using its ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| routeId | Yes | The unique identifier of the route to fetch. |
Implementation Reference
- src/tools/getRoute.ts:19-49 (handler)Handler function for the 'get-route' tool. Validates input, retrieves Strava access token, calls getRouteById helper, formats the summary using formatRouteSummary, and returns text content or error response.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 }; } }
- src/tools/getRoute.ts:6-10 (schema)Zod input schema for the get-route tool, validating routeId as 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:123-128 (registration)Registration of the 'get-route' tool on the MCP server using server.tool() with name, description, input schema shape, and execute handler.server.tool( getRouteTool.name, getRouteTool.description, getRouteTool.inputSchema?.shape ?? {}, getRouteTool.execute );
- src/stravaClient.ts:1067-1083 (helper)Core helper function that performs the Strava API GET request to /routes/{routeId}, validates the response with RouteSchema Zod schema, and handles errors including automatic 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); }); } }