const fetch = require('node-fetch');
async function testAPI() {
console.log('Testing Debug MCP HTTP API...\n');
// Test 1: Health check
console.log('1. Testing /health endpoint...');
const health = await fetch('http://localhost:3000/health');
console.log(` Status: ${health.status}`);
console.log(` Response: ${await health.text()}\n`);
// Test 2: Send a debug log
console.log('2. Testing POST /api/log...');
const logResponse = await fetch('http://localhost:3000/api/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
timestamp: new Date().toISOString(),
level: 'info',
message: 'Test debug log from API test',
data: { test: true, value: 123 }
})
});
console.log(` Status: ${logResponse.status}`);
console.log(` Response: ${await logResponse.text()}\n`);
// Test 3: Read logs back
console.log('3. Testing GET /api/log...');
const getLogs = await fetch('http://localhost:3000/api/log');
console.log(` Status: ${getLogs.status}`);
const logsData = await getLogs.json();
console.log(` Log count: ${logsData.lineCount}\n`);
// Test 4: Get stats
console.log('4. Testing GET /api/stats...');
const stats = await fetch('http://localhost:3000/api/stats');
console.log(` Status: ${stats.status}`);
console.log(` Response: ${await stats.text()}\n`);
console.log('✅ All API tests completed!');
}
testAPI().catch(err => {
console.error('❌ Test failed:', err.message);
process.exit(1);
});