export-route-gpx
Export specific Strava routes in GPX format to a local directory using the route ID for offline access or other applications.
Instructions
Exports a specific Strava route in GPX format and saves it to a pre-configured local directory.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| routeId | Yes | The ID of the Strava route to export. |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"routeId": {
"description": "The ID of the Strava route to export.",
"type": "string"
}
},
"required": [
"routeId"
],
"type": "object"
}
Implementation Reference
- src/tools/exportRouteGpx.ts:21-80 (handler)The execute function implementing the tool logic: checks env vars, ensures export dir, fetches GPX data via helper, writes file, handles errors with structured responses.execute: async ({ routeId }: ExportRouteGpxInput) => { const token = process.env.STRAVA_ACCESS_TOKEN; if (!token) { // Strict return structure return { content: [{ type: "text" as const, text: "❌ Error: Missing STRAVA_ACCESS_TOKEN in .env file." }], isError: true }; } const exportDir = process.env.ROUTE_EXPORT_PATH; if (!exportDir) { // Strict return structure return { content: [{ type: "text" as const, text: "❌ Error: Missing ROUTE_EXPORT_PATH in .env file. Please configure the directory for saving exports." }], isError: true }; } try { // Ensure the directory exists, create if not if (!fs.existsSync(exportDir)) { console.error(`Export directory ${exportDir} not found, creating it...`); fs.mkdirSync(exportDir, { recursive: true }); } else { // Check if it's a directory and writable (existing logic) const stats = fs.statSync(exportDir); if (!stats.isDirectory()) { // Strict return structure return { content: [{ type: "text" as const, text: `❌ Error: ROUTE_EXPORT_PATH (${exportDir}) is not a valid directory.` }], isError: true }; } fs.accessSync(exportDir, fs.constants.W_OK); } const gpxData = await fetchGpxData(token, routeId); const filename = `route-${routeId}.gpx`; const fullPath = path.join(exportDir, filename); fs.writeFileSync(fullPath, gpxData); // Strict return structure return { content: [{ type: "text" as const, text: `✅ Route ${routeId} exported successfully as GPX to: ${fullPath}` }], }; } catch (err: any) { console.error(`Error in export-route-gpx tool for route ${routeId}:`, err); // Strict return structure let userMessage = `❌ Error exporting route ${routeId} as GPX: ${err.message}`; if (err.code === 'EACCES') { userMessage = `❌ Error: No write permission for ROUTE_EXPORT_PATH directory (${exportDir}).`; } return { content: [{ type: "text" as const, text: userMessage }], isError: true }; } },
- src/tools/exportRouteGpx.ts:9-11 (schema)Zod input schema validating the routeId parameter.const ExportRouteGpxInputSchema = z.object({ routeId: z.string().describe("The ID of the Strava route to export."), });
- src/server.ts:128-133 (registration)MCP server registration of the export-route-gpx tool using server.tool() with name, description, schema, and execute handler.server.tool( exportRouteGpx.name, exportRouteGpx.description, exportRouteGpx.inputSchema?.shape ?? {}, exportRouteGpx.execute );