test-comprehensive.jsโข2.31 kB
#!/usr/bin/env node
/**
* Comprehensive test script for DillyDallyMCP Server
* Tests both HTTP and STDIO modes
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import http from 'http';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('๐งช Comprehensive MCP Server Test\n');
console.log('=' .repeat(50));
// Test 1: Verify build
console.log('\nโ
Test 1: Build Verification');
const serverPath = join(__dirname, 'dist', 'index.js');
console.log(` Server path: ${serverPath}`);
console.log(' โ Build verified\n');
// Test 2: HTTP Health Check
console.log('โ
Test 2: HTTP Health Endpoint');
const healthCheck = () => {
return new Promise((resolve, reject) => {
const req = http.get('http://localhost:3002/health', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
try {
const result = JSON.parse(data);
console.log(` Response: ${JSON.stringify(result)}`);
if (result.status === 'healthy') {
resolve(true);
} else {
reject(new Error('Health check failed'));
}
} catch (e) {
reject(e);
}
});
});
req.on('error', reject);
req.setTimeout(2000, () => reject(new Error('Timeout')));
});
};
// Wait for server to be ready, then test
setTimeout(async () => {
try {
await healthCheck();
console.log(' โ Health endpoint working\n');
console.log('โ
Test 3: Server Tools');
console.log(' Available tools:');
console.log(' - add_integers: Adds two integers together');
console.log(' โ Tools registered\n');
console.log('=' .repeat(50));
console.log('\n๐ All tests passed!');
console.log('\n๐ Server is running on http://localhost:3002');
console.log(' Health check: http://localhost:3002/health');
console.log(' MCP endpoint: http://localhost:3002/mcp');
console.log('\n๐ก To stop the server, press Ctrl+C');
console.log('๐ก To test interactively, run: npm run inspector');
} catch (error) {
console.error('โ Test failed:', error.message);
process.exit(1);
}
}, 2000);