connect-strava
Connect your Strava account to enable activity tracking and fitness data analysis. Opens a browser window for secure authentication to link your account.
Instructions
Connect your Strava account to enable activity tracking. This will open a browser window for secure authentication. Use this when the user asks to connect, link, or authenticate their Strava account.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| force | No | Force re-authentication even if already connected |
Implementation Reference
- src/tools/connectStrava.ts:17-87 (handler)The definition and implementation of the 'connect-strava' MCP tool.
export const connectStravaTool = { name: 'connect-strava', description: 'Connect your Strava account to enable activity tracking. This will open a browser window for secure authentication. Use this when the user asks to connect, link, or authenticate their Strava account.', inputSchema: z.object({ force: z.boolean().optional().describe('Force re-authentication even if already connected'), }), execute: async (args: { force?: boolean }): Promise<{ content: Array<{ type: 'text'; text: string }> }> => { const { force = false } = args; try { // Check if already authenticated if (!force) { const config = await loadConfig(); if (hasValidTokens(config)) { // Try to verify the tokens work try { const token = config.accessToken!; const athlete = await getAuthenticatedAthlete(token); return { content: [{ type: 'text' as const, text: `✅ Already connected to Strava as ${athlete.firstname} ${athlete.lastname}.\n\nYou can ask me about your activities, stats, routes, and more!\n\nIf you want to connect a different account, use the force option.`, }], }; } catch { // Token might be expired, continue to re-auth } } } // Start the auth flow const authUrl = getAuthUrl(); // Open browser await openBrowser(authUrl); // Return immediately with instructions while server runs const serverPromise = startAuthServer(); // Wait for auth to complete const result = await serverPromise; if (result.success) { const greeting = result.athleteName ? `Welcome, ${result.athleteName}! 🎉` : 'Successfully connected! 🎉'; return { content: [{ type: 'text' as const, text: `✅ ${greeting}\n\nYour Strava account is now connected. You can ask me about:\n• Your recent activities\n• Training statistics\n• Routes and segments\n• And much more!\n\nTry asking: "Show me my recent activities" or "What are my stats for this year?"`, }], }; } else { return { content: [{ type: 'text' as const, text: `❌ ${result.message}\n\nPlease try again. If the issue persists, make sure:\n1. You have a Strava API application (create one at https://www.strava.com/settings/api)\n2. The Authorization Callback Domain is set to "localhost"\n3. You're using the correct Client ID and Client Secret`, }], }; } } catch (error: any) { return { content: [{ type: 'text' as const, text: `❌ Error connecting to Strava: ${error.message}\n\nPlease try again. If the browser didn't open, visit: ${getAuthUrl()}`, }], }; } }, };