#!/usr/bin/env node
import fetch from 'node-fetch';
const ILP_API_BASE = process.env.ILP_API_URL || 'http://localhost:8080/api/v1';
console.log(' Testing ILP MCP Server\n');
console.log(`API Base: ${ILP_API_BASE}\n`);
async function testAPIConnection() {
console.log('1️.Testing API connection...');
try {
const response = await fetch(`${ILP_API_BASE}/dronesWithCooling/false`);
if (!response.ok) {
throw new Error(`API returned ${response.status}`);
}
const drones = await response.json();
console.log(`Connected! Found ${drones.length} drones\n`);
return true;
} catch (error) {
console.log(`Failed: ${error.message}`);
console.log(` Make sure your ILP service is running at ${ILP_API_BASE}\n`);
return false;
}
}
async function testListDrones() {
console.log('2️.Testing list_available_drones...');
try {
const response = await fetch(`${ILP_API_BASE}/dronesWithCooling/false`);
const drones = await response.json();
console.log(` Success! Retrieved ${drones.length} drones`);
if (drones && drones.length > 0) {
console.log(` Drone structure: ${JSON.stringify(drones[0], null, 2).substring(0, 200)}...\n`);
} else {
console.log(` (No drones to display sample)\n`);
}
return true;
} catch (error) {
console.log(` Failed: ${error.message}\n`);
return false;
}
}
async function testPlanDelivery() {
console.log('3️.Testing plan_delivery...');
try {
const dispatch = {
id: 9999,
requirements: { capacity: 4.0, heating: true },
delivery: { lng: -3.188, lat: 55.945 }
};
const response = await fetch(`${ILP_API_BASE}/calcDeliveryPath`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify([dispatch])
});
const result = await response.json();
console.log(`Success! Planned delivery`);
console.log(` Cost: $${result.totalCost.toFixed(2)}`);
console.log(` Moves: ${result.totalMoves}`);
console.log(` Drone: ${result.dronePaths[0].droneId}\n`);
return true;
} catch (error) {
console.log(`Failed: ${error.message}\n`);
return false;
}
}
async function testGeoJSON() {
console.log('4️.Testing get_delivery_geojson...');
try {
const dispatch = {
id: 1,
requirements: { capacity: 4.0 },
delivery: { lng: -3.188, lat: 55.945 }
};
const response = await fetch(`${ILP_API_BASE}/calcDeliveryPathAsGeoJson`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify([dispatch])
});
const geojson = await response.json();
console.log(`Success! Generated GeoJSON`);
console.log(` Type: ${geojson.type}`);
console.log(` Features: ${geojson.features.length}\n`);
return true;
} catch (error) {
console.log(`Failed: ${error.message}\n`);
return false;
}
}
async function runTests() {
const results = [];
results.push(await testAPIConnection());
if (!results[0]) {
console.log(' Cannot proceed without API connection\n');
process.exit(1);
}
results.push(await testListDrones());
results.push(await testPlanDelivery());
results.push(await testGeoJSON());
console.log('═'.repeat(50));
const passed = results.filter(r => r).length;
const total = results.length;
if (passed === total) {
console.log(`All tests passed! (${passed}/${total})`);
console.log(' MCP Server is ready to use!\n');
console.log('Next steps:');
console.log('1. Make server.js executable: chmod +x server.js');
console.log('2. Link globally: npm link');
console.log('3. Configure Claude Desktop (see README.md)');
} else {
console.log(`Some tests failed (${passed}/${total})`);
}
console.log('═'.repeat(50));
}
runTests().catch(error => {
console.error('Test runner error:', error);
process.exit(1);
});