check-session
Confirm that your Garmin Connect session is still valid after logging in. This verification step ensures authentication and continued data access.
Instructions
Check if the saved Garmin Connect session is still valid. MUST be called after garmin-login to verify authentication worked.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:106-131 (handler)The handler function for the 'check-session' tool. It checks if a saved Garmin Connect session exists, and if so, tests it by calling the userprofile API. On success returns {status:'ok', profile}. On failure resets the shared client and returns an error.
server.tool( "check-session", "Check if the saved Garmin Connect session is still valid. MUST be called after garmin-login to verify authentication worked.", {}, async () => { if (!sessionExists()) { return errorResult( "No session file found. Call the garmin-login tool for instructions." ); } try { const client = getClient(); const profile = await client.get( "userprofile-service/userprofile/user-settings/" ); return jsonResult({ status: "ok", profile }); } catch (e) { const msg = e instanceof Error ? e.message : String(e); // Reset the singleton so the next attempt re-reads the session file await resetSharedClient(); return errorResult( `Session invalid or expired: ${msg}\nCall the garmin-login tool to re-authenticate.` ); } } ); - src/index.ts:7-41 (registration)Registration via registerTools(server) which calls the registration function in tools.ts that registers all tools including 'check-session' via server.tool().
async function startMcpServer(): Promise<void> { const server = new McpServer({ name: "garmin-connect-mcp", version: "0.1.0", }); registerTools(server); registerResources(server); const transport = new StdioServerTransport(); await server.connect(transport); console.error("garmin-connect-mcp server running on stdio"); } async function main(): Promise<void> { const command = process.argv[2]; if (command === "login") { const { runLogin } = await import("./auth.js"); await runLogin(); } else { await startMcpServer(); } } main().catch((err) => { console.error("Fatal error:", err); process.exit(1); }); - src/tools.ts:32-39 (helper)getClient() helper called inside check-session handler; uses sessionExists() to check for session file and returns the shared client via getSharedClient().
function getClient() { if (!sessionExists()) { throw new Error( "No Garmin session found. The user needs to run: npx garmin-connect-mcp login" ); } return getSharedClient(); } - src/garmin-client.ts:27-29 (helper)sessionExists() helper that checks if the session.json file exists on disk. Used by the check-session handler to determine if there is a saved session.
export function sessionExists(): boolean { return existsSync(SESSION_FILE); }