const { spawn } = require('child_process');
const path = require('path');
const serverPath = path.join(__dirname, 'src', 'index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'inherit'] // pipe stdin/stdout, inherit stderr
});
server.stdout.on('data', (data) => {
console.log(`[Server Output]: ${data.toString()}`);
});
server.on('exit', (code, signal) => {
console.log(`[Server Exit] Code: ${code}, Signal: ${signal}`);
process.exit(code || 1);
});
const send = (msg) => {
const json = JSON.stringify(msg);
console.log(`[Sending]: ${json}`);
server.stdin.write(json + '\n');
};
// JSON-RPC sequence
// 1. Initialize
send({
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
});
setTimeout(() => {
// 2. Call tool
send({
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "list_cells",
arguments: {
notebook_path: path.join(__dirname, 'test.ipynb')
}
}
});
}, 1000);
setTimeout(() => {
// End
server.kill();
}, 5000);