#!/usr/bin/env node
/**
* Authentication CLI for Garmin Health MCP Server
* Wraps the Python auth script for easy setup
*/
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const SCRIPTS_DIR = join(__dirname, '..', 'scripts');
function runAuth() {
const authScript = join(SCRIPTS_DIR, 'garmin_auth.py');
if (!fs.existsSync(authScript)) {
console.error('β Error: garmin_auth.py script not found');
console.error(` Expected at: ${authScript}`);
process.exit(1);
}
// Check for credentials in environment
const email = process.env.GARMIN_EMAIL;
const password = process.env.GARMIN_PASSWORD;
if (!email || !password) {
console.error('β Error: GARMIN_EMAIL and GARMIN_PASSWORD environment variables must be set');
console.error('');
console.error('Set them in your shell:');
console.error(' export GARMIN_EMAIL="your-email@example.com"');
console.error(' export GARMIN_PASSWORD="your-password"');
console.error('');
console.error('Or create a .env file in this directory:');
console.error(' GARMIN_EMAIL=your-email@example.com');
console.error(' GARMIN_PASSWORD=your-password');
process.exit(1);
}
console.log('π Authenticating with Garmin Connect...');
console.log(`π§ Email: ${email}`);
console.log('');
try {
execSync(`python3 "${authScript}" login`, {
stdio: 'inherit',
env: {
...process.env,
GARMIN_EMAIL: email,
GARMIN_PASSWORD: password,
},
});
console.log('');
console.log('β
Authentication successful!');
console.log(' Session tokens saved - ready to use with Claude Desktop');
} catch (error) {
console.error('');
console.error('β Authentication failed');
console.error(' Check your credentials and try again');
process.exit(1);
}
}
// Check if .env file exists and load it
const envPath = join(__dirname, '..', '.env');
if (fs.existsSync(envPath)) {
const envContent = fs.readFileSync(envPath, 'utf-8');
envContent.split('\n').forEach(line => {
const match = line.match(/^([^=]+)=(.+)$/);
if (match) {
const [, key, value] = match;
process.env[key.trim()] = value.trim().replace(/^["']|["']$/g, '');
}
});
}
runAuth();