92 lines
2.1 KiB
TypeScript
92 lines
2.1 KiB
TypeScript
import { spawn } from "child_process";
|
|
|
|
async function test() {
|
|
console.log("Starting MCP server...");
|
|
const mcp = spawn("bun", ["index.ts"], {
|
|
cwd: "/home/ti/git/homaroma/apps/mcp-server",
|
|
env: { ...process.env, MCP_BACKEND_URL: "http://localhost:3051/api" }
|
|
});
|
|
|
|
mcp.stderr.on("data", (data) => {
|
|
console.error(`[MCP STDERR] ${data}`);
|
|
});
|
|
|
|
let responseData = "";
|
|
mcp.stdout.on("data", (data) => {
|
|
responseData += data.toString();
|
|
});
|
|
|
|
const send = (msg: any) => {
|
|
mcp.stdin.write(JSON.stringify(msg) + "\n");
|
|
};
|
|
|
|
const waitResponse = async (ms: number) => {
|
|
await new Promise(resolve => setTimeout(resolve, ms));
|
|
const lines = responseData.trim().split("\n");
|
|
const lastLine = lines[lines.length - 1] ?? "";
|
|
try {
|
|
return JSON.parse(lastLine);
|
|
} catch (e) {
|
|
console.log("Failed to parse JSON line:", lastLine);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
// 1. Send initialize
|
|
console.log("Sending initialize request...");
|
|
send({
|
|
jsonrpc: "2.0",
|
|
id: 1,
|
|
method: "initialize",
|
|
params: {
|
|
protocolVersion: "2024-11-05",
|
|
capabilities: {},
|
|
clientInfo: { name: "test-client", version: "1.0.0" }
|
|
}
|
|
});
|
|
|
|
await waitResponse(1000);
|
|
|
|
// 2. Send initialized notification
|
|
console.log("Sending initialized notification...");
|
|
send({
|
|
jsonrpc: "2.0",
|
|
method: "notifications/initialized"
|
|
});
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
// 3. Try calling upsert_menu with invalid rootImage (number)
|
|
console.log("\nSending tools/call for upsert_menu with invalid rootImage (number)...");
|
|
responseData = "";
|
|
send({
|
|
jsonrpc: "2.0",
|
|
id: 3,
|
|
method: "tools/call",
|
|
params: {
|
|
name: "upsert_menu",
|
|
arguments: {
|
|
name: "mcp-test-invalid-root",
|
|
rootImage: 99999,
|
|
items: [
|
|
{
|
|
label: "MCP Item",
|
|
url: "/item",
|
|
order: 1
|
|
}
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
await waitResponse(2000);
|
|
console.log("upsert_menu invalid rootImage response:", responseData);
|
|
|
|
mcp.kill();
|
|
}
|
|
|
|
test().catch(err => {
|
|
console.error("MCP Challenger Test failed:", err);
|
|
process.exit(1);
|
|
});
|