test-server.mjs•1.49 kB
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Test the MCP server
function testMCPServer() {
console.log('Testing MCP Server...');
const serverPath = join(__dirname, '../dist/index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
// Test initialize request
const initRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
server.stdout.on('data', (data) => {
try {
const response = JSON.parse(data.toString());
console.log('Server response:', JSON.stringify(response, null, 2));
} catch (e) {
console.log('Raw output:', data.toString());
}
});
server.stderr.on('data', (data) => {
console.log('Server stderr:', data.toString());
});
server.on('close', (code) => {
console.log(`Server exited with code ${code}`);
});
// Clean up after 3 seconds
setTimeout(() => {
server.kill();
}, 3000);
}
testMCPServer();