Skip to main content
Glama
SkyBlob12

Strava MCP Server

by SkyBlob12

Échanger le code d'autorisation contre des tokens

strava_exchange_token

Exchange OAuth2 authorization codes from Strava's redirect URL for access and refresh tokens, saving them locally to enable authenticated API requests.

Instructions

É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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesLe code d'autorisation depuis l'URL de redirection Strava

Implementation Reference

  • Registration of the 'strava_exchange_token' tool via server.registerTool. Defines the input schema (code string) and the handler which calls exchangeCodeForTokens.
    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}` }],
          };
        }
      }
    );
  • The handler function for strava_exchange_token. Receives { code }, calls exchangeCodeForTokens(code), and returns a success or error message.
    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}` }],
        };
      }
    }
  • Input schema for strava_exchange_token: expects a single 'code' string parameter (the OAuth authorization code from the redirect URL).
    {
      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"),
      }),
  • The core OAuth helper function 'exchangeCodeForTokens' that posts the authorization code to Strava's token endpoint, saves tokens, and returns them.
    export async function exchangeCodeForTokens(code: string): Promise<StravaTokens> {
      const { data } = await axios.post(STRAVA_TOKEN_URL, {
        client_id: config.clientId,
        client_secret: config.clientSecret,
        code,
        grant_type: "authorization_code",
      });
      const tokens: StravaTokens = {
        access_token: data.access_token,
        refresh_token: data.refresh_token,
        expires_at: data.expires_at,
        athlete_id: data.athlete?.id ?? 0,
      };
      saveTokens(config.tokensFilePath, tokens);
      return tokens;
    }
  • Dependencies imported by oauth.ts: axios for HTTP, config for Strava credentials, tokenStore for saving tokens, and the StravaTokens type.
    import axios from "axios";
    import { STRAVA_AUTH_URL, STRAVA_TOKEN_URL, STRAVA_SCOPES, config } from "../config.js";
    import { loadTokens, saveTokens } from "./tokenStore.js";
    import type { StravaTokens } from "../types.js";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It discloses side effect (tokens saved locally) but lacks details on idempotency, error handling, or overwrite behavior. Incomplete for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no fluff, front-loaded. Could be slightly more structured but very concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for simple tool with one parameter and no output schema; explains process and side effect. Lacks error handling or prerequisite details, but overall sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers parameter `code` 100%, and description adds context (where code comes from: redirect URL after authorization), enhancing meaning beyond schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (exchange authorization code) and resource (tokens), specifying access and refresh tokens. It distinguishes from siblings like strava_get_auth_url which provides the code.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage after browser authorization but does not explicitly mention prerequisites (e.g., need code from strava_get_auth_url) or when not to use. No alternatives listed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/SkyBlob12/McpStrava'

If you have feedback or need assistance with the MCP directory API, please join our Discord server