Files
reverse-engineering-anything/tests/boundary/process/mcpHttpShutdown.test.ts
T
Edgar ArakelyanandClaude Fable 5.1 46dd8f0e2b feat(mcp): serve the MCP server over streamable HTTP
Add rea mcp --http [--host] [--port]: the same server rea speaks over stdio,
served over MCP Streamable HTTP on a loopback listener by default, using the
SDK's web-standard transport already in the pinned @modelcontextprotocol/server
behind a small node:http bridge. One client and one session at a time; DELETE
ends the session without running provider teardown, a new client's initialize
replaces a session left open, foreign Host headers are refused on loopback
binds, and shutdown is signals-only. Stdio stays the default and registered
transport; server.json and client registrations are unchanged.

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 21:05:10 -07:00

40 lines
1.4 KiB
TypeScript

import { once } from "node:events";
import { describe, expect } from "vitest";
import { MCP_SHUTDOWN_FAILED } from "../../../src/main/messages.js";
import { rawHttpRequest } from "../../support/http/rawRequest.js";
import { startMcpHttpProcess } from "../../support/mcp/streamableHttpProcess.js";
import { processTest } from "../../support/process/processFixture.js";
const SHUTDOWN_TIMEOUT_MS = 90_000;
const shutdownSignals: readonly (readonly [NodeJS.Signals, number])[] =
process.platform === "win32"
? [["SIGINT", 130]]
: [
["SIGTERM", 143],
["SIGINT", 130],
];
describe("rea mcp --http shutdown", () => {
for (const [signal, status] of shutdownSignals)
processTest(
`releases the listener and exits ${String(status)} on ${signal}`,
async ({ processes }) => {
const started = await startMcpHttpProcess(processes);
// The live transport refuses a GET that does not accept an event stream.
const before = await rawHttpRequest(started.url);
expect(before.status).toBe(406);
started.child.kill(signal);
const [code, signalCode] = await once(started.child, "close");
expect(code).toBe(status);
expect(signalCode).toBeNull();
expect(started.stderr()).not.toContain(MCP_SHUTDOWN_FAILED);
await expect(rawHttpRequest(started.url)).rejects.toMatchObject({
code: "ECONNREFUSED",
});
},
SHUTDOWN_TIMEOUT_MS,
);
});