23 lines
1.0 KiB
JavaScript
23 lines
1.0 KiB
JavaScript
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();
|
|
}
|
|
});
|