#!/usr/bin/env node
/**
* Simple test script to verify MCP tools are working
*/
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const SCRIPTS_DIR = join(__dirname, '..', 'scripts');
console.log('π§ͺ Testing Garmin Health MCP Server Tools\n');
// Check environment
if (!process.env.GARMIN_EMAIL || !process.env.GARMIN_PASSWORD) {
console.error('β GARMIN_EMAIL and GARMIN_PASSWORD must be set');
console.error(' Create a .env file or set environment variables');
process.exit(1);
}
console.log('β Environment variables set');
console.log(` Email: ${process.env.GARMIN_EMAIL}\n`);
// Test 1: Check Python is available
try {
const pythonVersion = execSync('python3 --version', { encoding: 'utf-8' }).trim();
console.log(`β Python: ${pythonVersion}`);
} catch (error) {
console.error('β Python 3 not found');
process.exit(1);
}
// Test 2: Check Python dependencies
try {
execSync('python3 -c "import garminconnect"', { encoding: 'utf-8' });
console.log('β garminconnect library installed');
} catch (error) {
console.error('β garminconnect not installed');
console.error(' Run: pip3 install garminconnect fitparse gpxpy');
process.exit(1);
}
// Test 3: Check scripts exist
const requiredScripts = ['garmin_auth.py', 'garmin_data.py', 'garmin_chart.py'];
for (const script of requiredScripts) {
const scriptPath = join(SCRIPTS_DIR, script);
try {
const fs = await import('fs');
if (!fs.existsSync(scriptPath)) {
throw new Error('not found');
}
console.log(`β Script found: ${script}`);
} catch (error) {
console.error(`β Script missing: ${script}`);
process.exit(1);
}
}
// Test 4: Try fetching user profile (requires auth)
console.log('\nπ Testing Garmin authentication...');
try {
const result = execSync(`python3 "${join(SCRIPTS_DIR, 'garmin_data.py')}" profile`, {
encoding: 'utf-8',
env: {
...process.env,
GARMIN_EMAIL: process.env.GARMIN_EMAIL,
GARMIN_PASSWORD: process.env.GARMIN_PASSWORD,
},
});
const profile = JSON.parse(result);
console.log('β Authentication successful');
console.log(` User: ${profile.displayName || profile.email || 'Unknown'}`);
console.log('\nβ
All tests passed! MCP server is ready to use.');
} catch (error) {
console.error('\nβ Authentication test failed');
console.error(' Run: npm run auth');
console.error(` Error: ${error.message}`);
process.exit(1);
}