Skip to main content
Glama

authenticate_garmin

Authenticate with Garmin Connect to enable workout creation and device synchronization through the Garmin Workouts MCP server.

Instructions

Authenticate with Garmin Connect (opens browser)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration of the 'authenticate_garmin' tool in the ListTools response, including name, description, and input schema (empty object).
    {
      name: "authenticate_garmin",
      description: "Authenticate with Garmin Connect (opens browser)",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • MCP server tool handler for 'authenticate_garmin' that invokes GarminAuth.authenticate() and formats success/error responses.
    case "authenticate_garmin": {
      try {
        console.error("🔐 Starting Garmin authentication...");
        const authData = await garminAuth.authenticate();
        if (authData) {
          const expiresAt = new Date(authData.expiresAt);
          return {
            content: [
              {
                type: "text",
                text: `✅ Successfully authenticated with Garmin Connect! You can now create workouts.\nToken expires: ${expiresAt.toLocaleString()}`,
              },
            ],
          };
        } else {
          return {
            content: [
              {
                type: "text",
                text: "❌ Authentication failed. Please ensure you can access Garmin Connect in your browser.",
              },
            ],
          };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `❌ Authentication error: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Core GarminAuth.authenticate() method implementing the authentication logic: launches headless=false Puppeteer browser, navigates to Garmin Connect, waits for manual login, intercepts Authorization Bearer token, extracts cookies, parses JWT expiration, stores auth data.
    async authenticate(): Promise<AuthData | null> {
      console.error("🚀 Starting Garmin authentication...");
      
      const browser = await puppeteer.launch({
        headless: false,
        args: [
          "--no-sandbox",
          "--disable-setuid-sandbox",
          "--disable-blink-features=AutomationControlled",
          "--disable-features=VizDisplayCompositor",
        ],
      });
    
      let authData: AuthData | null = null;
    
      try {
        const page = await browser.newPage();
        
        await page.setUserAgent(
          "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
        );
    
        await page.evaluateOnNewDocument(() => {
          delete (navigator as any).webdriver;
          (window as any).chrome = {
            runtime: {},
            loadTimes: function () {},
            csi: function () {},
            app: {},
          };
        });
    
        await page.setViewport({ width: 1366, height: 768 });
    
        let authToken = "";
        let cookies = "";
    
        // Set up request interception to capture auth token
        await page.setRequestInterception(true);
    
        page.on("request", (request) => {
          const authHeader = request.headers()["authorization"];
          if (authHeader && authHeader.startsWith("Bearer ") && !authToken) {
            authToken = authHeader;
            console.error("🎯 Captured auth token!");
          }
          request.continue();
        });
    
        console.error("🔐 Opening Garmin Connect login...");
        console.error("👉 Please login manually in the browser");
    
        // Go directly to workouts page (will redirect to login if needed)
        await page.goto("https://connect.garmin.com/modern/workouts", {
          waitUntil: "networkidle2",
        });
    
        console.error("⏳ Waiting for login completion...");
        console.error("💡 The page should redirect to login, then back to workouts");
    
        // Wait for the workouts page to load properly (means we're logged in)
        await page.waitForFunction(
          () => {
            return (
              window.location.href.includes("/modern/workouts") &&
              !window.location.href.includes("sso.garmin.com") &&
              document.querySelector('select[name="select-workout"]') !== null
            );
          },
          { timeout: 300000 } // 5 minutes for manual login
        );
    
        // Extract cookies
        const pageCookies = await page.cookies();
        cookies = pageCookies.map((c) => `${c.name}=${c.value}`).join("; ");
    
        // Make sure we have an auth token by triggering a request
        if (!authToken) {
          console.error("🔄 Triggering request to capture auth token...");
          await page.reload();
          await new Promise((resolve) => setTimeout(resolve, 3000));
        }
    
        if (authToken && cookies) {
          console.error("✅ Authentication successful!");
          
          // Parse token expiration
          const tokenPayload = this.parseJWT(authToken);
          
          authData = {
            authToken,
            cookies,
            expiresAt: tokenPayload.exp * 1000, // Convert to milliseconds
            issuedAt: tokenPayload.iat * 1000,
          };
    
          // Store auth data
          this.storeAuth(authData);
        } else {
          console.error("❌ Could not extract authentication data");
        }
      } catch (error) {
        console.error("❌ Authentication failed:", error);
      } finally {
        await browser.close();
      }
    
      return authData;
    }
  • Type definition for AuthData used in authentication storage and validation.
    interface AuthData {
      authToken: string;
      cookies: string;
      expiresAt: number;
      issuedAt: number;
    }
  • Instantiation of GarminAuth class used across tools for shared authentication state.
    const garminAuth = new GarminAuth();
Behavior2/5

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

With no annotations, the description carries full burden. It discloses that authentication opens a browser, which is useful behavioral context. However, it omits critical details like whether this is a one-time setup, if it stores tokens, error handling, or rate limits. For an auth tool, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core action ('Authenticate with Garmin Connect') and adds a key behavioral detail ('opens browser') without waste. It's appropriately sized for a simple tool with no parameters.

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

Completeness2/5

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

Given the complexity of authentication (often involving tokens, permissions, or errors) and no annotations or output schema, the description is incomplete. It lacks details on what happens after authentication, success/failure responses, or how it integrates with sibling tools. For an auth tool, this leaves significant gaps.

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?

There are 0 parameters, and schema description coverage is 100%, so no parameter documentation is needed. The description doesn't add param info, but with no params, a baseline of 4 is appropriate as it doesn't need to compensate for gaps.

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

Purpose4/5

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

The description clearly states the action ('Authenticate with') and target ('Garmin Connect'), specifying it opens a browser. It distinguishes from siblings like 'check_garmin_auth' (verification) and 'create_garmin_workout' (creation), though it doesn't explicitly contrast them. The purpose is specific but could be more differentiated.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing credentials), when authentication is required, or how it relates to sibling tools like 'check_garmin_auth'. The description implies usage for initial auth but lacks explicit context or exclusions.

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/charlesfrisbee/garmin-workouts-mcp'

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