Files
time/havre/test/server.test.js
T
time 89070f46a4
time/worker-run cd havre && npm ci >/dev/null 2>&1; cd node_modules/@modelcontextprotocol/sdk && sed -n 20,60p dist/
ci / test (push) Successful in 42s
sync / sync (push) Successful in 5s
Scaffold the Havre MCP server (walking skeleton) (#195)
Co-authored-by: Time <time@users.noreply.teahub.xyz>
2026-10-19 16:14:10 +00:00

22 lines
1.2 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
// Real process over stdio: the same handshake an MCP host does.
test("handshake, tool list and havre_ping over stdio", async () => {
const client = new Client({ name: "test", version: "0.0.0" });
await client.connect(new StdioClientTransport({ command: process.execPath, args: [fileURLToPath(new URL("../src/index.js", import.meta.url))] }));
try {
assert.equal(client.getServerVersion().name, "havre");
assert.deepEqual((await client.listTools()).tools.map((t) => t.name), ["havre_ping"]);
assert.equal((await client.callTool({ name: "havre_ping", arguments: {} })).content[0].text, "pong");
assert.equal((await client.callTool({ name: "havre_ping", arguments: { message: "hi" } })).content[0].text, "hi");
const bad = await client.callTool({ name: "havre_ping", arguments: { message: 5 } });
assert.equal(bad.isError, true, "bad input is refused");
} finally {
await client.close();
}
});