card #98: update havre/test/http.test.js

This commit is contained in:
time committed 2026-10-19 16:15:06 +00:00
1 parent 086a028879
commit 8f934a8f8e
1 file changed
+22
+22
View File
@@ -0,0 +1,22 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { createHttpServer } from "../src/http.js";
test("health check and MCP over streamable HTTP", async () => {
const http = createHttpServer().listen(0);
await new Promise((r) => http.once("listening", r));
const base = `http://127.0.0.1:${http.address().port}`;
const client = new Client({ name: "test", version: "0.0.0" });
try {
assert.equal((await fetch(`${base}/health`)).status, 200);
assert.equal((await fetch(`${base}/nope`)).status, 404);
await client.connect(new StreamableHTTPClientTransport(new URL(`${base}/mcp`)));
assert.equal(client.getServerVersion().name, "havre");
assert.equal((await client.callTool({ name: "havre_ping", arguments: { message: "hi" } })).content[0].text, "hi");
} finally {
await client.close();
http.close();
}
});