30 lines
1.3 KiB
JavaScript
30 lines
1.3 KiB
JavaScript
// In-process round-trip test for server.mjs: import the real createServer()
|
|
// and drive its actual tool handlers over InMemoryTransport (no process
|
|
// spawn, no stdio pipes — the sandbox denies those).
|
|
import { Client } from "file:///C:/Users/12914/.dsh/profiles/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js";
|
|
import { InMemoryTransport } from "file:///C:/Users/12914/.dsh/profiles/node_modules/@modelcontextprotocol/sdk/dist/esm/inMemory.js";
|
|
import { createServer } from "./server.mjs";
|
|
|
|
const server = createServer();
|
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
const client = new Client({ name: "smoke", version: "0.0.1" });
|
|
await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]);
|
|
|
|
const tools = await client.listTools();
|
|
const names = tools.tools.map((t) => t.name).sort();
|
|
if (JSON.stringify(names) !== JSON.stringify(["echo"])) {
|
|
console.error("FAIL: unexpected tool list", names);
|
|
process.exit(1);
|
|
}
|
|
|
|
const result = await client.callTool({ name: "echo", arguments: { message: "ping" } });
|
|
const text = result.content?.[0]?.text;
|
|
if (text !== "echo: ping") {
|
|
console.error("FAIL: unexpected echo result", JSON.stringify(result));
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(JSON.stringify({ tools: names, echo: text }));
|
|
await client.close();
|
|
process.exit(0);
|