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();

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