#!/usr/bin/env node
import { spawn } from 'child_process';
console.log('π§ === TESTING MCP PROTOCOL HANDSHAKE ===\n');
// First test: initialize protocol
const initPayload = {
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
};
console.log('π Testing MCP initialize handshake...');
console.log('π¨ Init payload:', JSON.stringify(initPayload, null, 2));
const serverProcess = spawn('node', ['build/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
let responseData = '';
let serverReady = false;
serverProcess.stdout.on('data', (data) => {
const chunk = data.toString();
responseData += chunk;
console.log('π€ Response chunk:', chunk.trim());
});
serverProcess.stderr.on('data', (data) => {
const logMessage = data.toString();
console.log('π’ Server log:', logMessage.trim());
// Wait for server ready message
if (logMessage.includes('π') && logMessage.includes('running on stdio')) {
serverReady = true;
console.log('\nβ
Server ready, sending initialize...');
setTimeout(() => {
const payload = JSON.stringify(initPayload) + '\n';
console.log('π¨ Sending payload of length:', payload.length);
serverProcess.stdin.write(payload);
// Wait for response
setTimeout(() => {
console.log('\nπ === RESPONSE ANALYSIS ===');
console.log('π€ Total response length:', responseData.length);
if (responseData.trim()) {
console.log('π€ Raw response:\n' + responseData);
// Try parsing each line as JSON
const lines = responseData.split('\n').filter(line => line.trim());
console.log('π Response lines count:', lines.length);
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line) {
try {
const parsed = JSON.parse(line);
console.log(`β
Line ${i + 1} is valid JSON:`, JSON.stringify(parsed, null, 2));
} catch (e) {
console.log(`β Line ${i + 1} is not JSON:`, line);
}
}
}
} else {
console.log('β No response received on stdout');
}
serverProcess.kill();
}, 3000);
}, 1000);
}
});
serverProcess.on('exit', (code) => {
console.log('\nπ Test completed with exit code:', code);
});