#!/usr/bin/env node /** * Quick test script to verify NUT UPS MCP functionality */ import { NUTClient } from './dist/client.js'; import { config } from 'dotenv'; // Load environment variables config(); const NUT_HOST = process.env.NUT_HOST || 'localhost'; const NUT_PORT = parseInt(process.env.NUT_PORT || '3493'); const NUT_USERNAME = process.env.NUT_USERNAME; const NUT_PASSWORD = process.env.NUT_PASSWORD; async function testNUTConnection() { console.log('šŸ”Œ Connecting to NUT server...'); console.log(` Host: ${NUT_HOST}:${NUT_PORT}`); console.log(` User: ${NUT_USERNAME || '(no auth)'}\n`); const client = new NUTClient(NUT_HOST, NUT_PORT, NUT_USERNAME, NUT_PASSWORD); try { // Connect await client.connect(); console.log('āœ… Connected successfully!\n'); // List UPS devices console.log('šŸ“‹ Listing UPS devices...'); const devices = await client.listUPS(); console.log(`Found ${devices.length} UPS device(s):\n`); devices.forEach(d => { console.log(` • ${d.name}: ${d.description}`); }); console.log(''); if (devices.length > 0) { const upsName = devices[0].name; console.log(`šŸ“Š Getting complete status for: ${upsName}\n`); // Get all variables const vars = await client.getUPSVars(upsName); // Group variables by category const battery = vars.filter(v => v.name.startsWith('battery.')); const input = vars.filter(v => v.name.startsWith('input.')); const output = vars.filter(v => v.name.startsWith('output.')); const ups = vars.filter(v => v.name.startsWith('ups.')); const device = vars.filter(v => v.name.startsWith('device.')); console.log('šŸ”‹ BATTERY STATUS:'); battery.forEach(v => console.log(` ${v.name}: ${v.value}`)); console.log('\n⚔ INPUT:'); input.forEach(v => console.log(` ${v.name}: ${v.value}`)); console.log('\nšŸ”Œ OUTPUT:'); output.forEach(v => console.log(` ${v.name}: ${v.value}`)); console.log('\nšŸ–„ļø UPS:'); ups.forEach(v => console.log(` ${v.name}: ${v.value}`)); console.log('\nšŸ”§ DEVICE:'); device.forEach(v => console.log(` ${v.name}: ${v.value}`)); // Show other variables const other = vars.filter(v => !v.name.startsWith('battery.') && !v.name.startsWith('input.') && !v.name.startsWith('output.') && !v.name.startsWith('ups.') && !v.name.startsWith('device.') ); if (other.length > 0) { console.log('\nšŸ“ OTHER:'); other.forEach(v => console.log(` ${v.name}: ${v.value}`)); } } client.disconnect(); console.log('\nāœ… Test completed successfully!'); } catch (error) { console.error('\nāŒ Error:', error.message); client.disconnect(); process.exit(1); } } testNUTConnection();