const { spawn } = require('child_process');
const payload = {
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'file_reader',
arguments: {
path: 'C:\\MCP server\\README.md'
}
}
};
const child = spawn('node', ['dist/mcp/server.js'], { stdio: ['pipe', 'pipe', 'inherit'] });
child.stdout.on('data', (data) => {
// Server may output multiple JSON lines; print them
const lines = data.toString().split(/\r?\n/).filter(Boolean);
for (const line of lines) {
try {
const parsed = JSON.parse(line);
console.log('Server response:', JSON.stringify(parsed, null, 2));
} catch (e) {
console.log('Non-JSON output:', line);
}
}
});
child.on('close', (code) => {
// console.log(`Child exited with ${code}`);
});
// Send request and close stdin
child.stdin.write(JSON.stringify(payload) + '\n');
setTimeout(() => child.stdin.end(), 200);
// Give server a moment then kill child
setTimeout(() => child.kill(), 2000);