import { spawn } from "child_process";
import path from "path";
const serverPath = path.join(__dirname, "dist", "src", "server.js");
const serverProcess = spawn("node", [serverPath], {
stdio: ["pipe", "pipe", "inherit"]
});
const requests = [
{
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: {
name: "test-client",
version: "1.0.0"
}
}
},
{
jsonrpc: "2.0",
id: 2,
method: "tools/list",
params: {}
}
];
let buffer = "";
serverProcess.stdout.on("data", (data) => {
buffer += data.toString();
const lines = buffer.split("\n");
buffer = lines.pop() || "";
for (const line of lines) {
if (!line.trim()) continue;
try {
const response = JSON.parse(line);
console.log("Received response:", JSON.stringify(response, null, 2));
if (response.id === 2) {
console.log("Verification complete: Tools listed successfully.");
serverProcess.kill();
process.exit(0);
}
} catch (e) {
console.error("Error parsing JSON:", e);
}
}
});
// Send requests
requests.forEach((req) => {
const msg = JSON.stringify(req) + "\n";
serverProcess.stdin.write(msg);
});
setTimeout(() => {
console.error("Timeout waiting for response");
serverProcess.kill();
process.exit(1);
}, 5000);