Vérifier le statut d'authentification
strava_auth_statusCheck if valid Strava tokens exist and when they expire to confirm authentication status before accessing Strava data.
Instructions
Vérifie si des tokens Strava valides existent et quand ils expirent.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/auth/authTools.ts:77-109 (handler)The 'strava_auth_status' tool handler: registers the tool with the MCP server. Loads tokens from disk, checks if expired, and returns a status string indicating auth state (not authenticated, token expired, or token valid with expiry time). Input: empty object. Output: text content with authentication status.
server.registerTool( "strava_auth_status", { title: "Vérifier le statut d'authentification", description: "Vérifie si des tokens Strava valides existent et quand ils expirent.", inputSchema: z.object({}), }, async () => { const tokens = loadTokens(config.tokensFilePath); if (!tokens) { return { content: [ { type: "text", text: "Non authentifié. Lance strava_get_auth_url pour démarrer l'authentification.", }, ], }; } const expired = isTokenExpired(tokens); const expiresIn = Math.round(tokens.expires_at - Date.now() / 1000); const status = expired ? "Token expiré (sera renouvelé automatiquement à la prochaine requête)" : `Token valide (expire dans ${expiresIn}s)`; return { content: [ { type: "text", text: `Authentifié. Athlete ID : ${tokens.athlete_id}.\n${status}`, }, ], }; } - src/auth/authTools.ts:79-83 (schema)Input schema for strava_auth_status: defines the tool title ('Vérifier le statut d'authentification'), description, and an empty inputSchema (z.object({})) meaning no parameters required.
{ title: "Vérifier le statut d'authentification", description: "Vérifie si des tokens Strava valides existent et quand ils expirent.", inputSchema: z.object({}), }, - src/auth/authTools.ts:8-111 (registration)The registerAuthTools function registers strava_auth_status (and two other tools) on the MCP server. Called from src/index.ts line 14.
export function registerAuthTools(server: McpServer): void { server.registerTool( "strava_get_auth_url", { title: "Obtenir l'URL d'autorisation Strava", description: "Génère l'URL OAuth2 Strava. Ouvrir cette URL dans un navigateur, " + "autoriser l'application, puis copier le paramètre 'code' depuis " + "l'URL de redirection et le passer à strava_exchange_token.", inputSchema: z.object({}), }, async () => { if (!config.clientId) { return { content: [ { type: "text", text: "Erreur : STRAVA_CLIENT_ID non configuré. Copie .env.example en .env et renseigne tes credentials.", }, ], }; } const redirectUri = config.redirectUri; const portMatch = redirectUri.match(/:(\d+)\//); const port = portMatch ? parseInt(portMatch[1], 10) : 8080; startOAuthCallbackServer(port); const url = buildAuthorizationUrl(); return { content: [ { type: "text", text: `Ouvre cette URL dans ton navigateur :\n\n${url}\n\nUne fois que tu as autorisé l'application sur Strava, la page affichera "✓ Authentification réussie !" et les tokens seront sauvegardés automatiquement. Tu n'as rien d'autre à faire.`, }, ], }; } ); server.registerTool( "strava_exchange_token", { title: "Échanger le code d'autorisation contre des tokens", description: "Échange le code OAuth2 (depuis l'URL de redirection après autorisation dans le navigateur) " + "contre des tokens d'accès et de rafraîchissement. Les tokens sont sauvegardés localement.", inputSchema: z.object({ code: z.string().describe("Le code d'autorisation depuis l'URL de redirection Strava"), }), }, async ({ code }) => { try { const tokens = await exchangeCodeForTokens(code); return { content: [ { type: "text", text: `✓ Authentifié avec succès ! Athlete ID : ${tokens.athlete_id}.\nTokens sauvegardés dans ${config.tokensFilePath}.`, }, ], }; } catch (err: unknown) { const msg = err instanceof Error ? err.message : String(err); return { content: [{ type: "text", text: `Erreur lors de l'échange du token : ${msg}` }], }; } } ); server.registerTool( "strava_auth_status", { title: "Vérifier le statut d'authentification", description: "Vérifie si des tokens Strava valides existent et quand ils expirent.", inputSchema: z.object({}), }, async () => { const tokens = loadTokens(config.tokensFilePath); if (!tokens) { return { content: [ { type: "text", text: "Non authentifié. Lance strava_get_auth_url pour démarrer l'authentification.", }, ], }; } const expired = isTokenExpired(tokens); const expiresIn = Math.round(tokens.expires_at - Date.now() / 1000); const status = expired ? "Token expiré (sera renouvelé automatiquement à la prochaine requête)" : `Token valide (expire dans ${expiresIn}s)`; return { content: [ { type: "text", text: `Authentifié. Athlete ID : ${tokens.athlete_id}.\n${status}`, }, ], }; } ); } - src/auth/tokenStore.ts:4-11 (helper)loadTokens helper: reads tokens from a JSON file path, returns null if file doesn't exist or can't be parsed. Used by the strava_auth_status handler to load stored tokens.
export function loadTokens(filePath: string): StravaTokens | null { if (!existsSync(filePath)) return null; try { return JSON.parse(readFileSync(filePath, "utf-8")) as StravaTokens; } catch { return null; } } - src/auth/tokenStore.ts:18-20 (helper)isTokenExpired helper: checks if tokens.expires_at (minus 300s buffer) is before the current time. Used by the strava_auth_status handler to determine if the token is expired.
export function isTokenExpired(tokens: StravaTokens): boolean { return Date.now() / 1000 >= tokens.expires_at - 300; }