refactor(server): add shutdown idempotency guard and test teardown blocks

This commit is contained in:
Lucas Winther
2026-09-06 19:22:46 +02:00
parent f1e84d281a
commit 3d4a064593
3 changed files with 45 additions and 37 deletions
+1
View File
@@ -1,3 +1,4 @@
# MCP Stdio Server Assembly & Integration Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+3
View File
@@ -12,7 +12,10 @@ async function main(): Promise<void> {
const mcpServer = createServer(config);
// Bind graceful termination
let isShuttingDown = false;
const shutdown = async () => {
if (isShuttingDown) return;
isShuttingDown = true;
console.error("\n[openproject-mcp] Received termination signal, shutting down...");
await mcpServer.stop();
process.exit(0);
+6 -2
View File
@@ -199,6 +199,7 @@ describe("End-to-End Live Tool Calling over MCP Client", () => {
const client = new Client({ name: "test-runner", version: "1" });
await client.connect(clientTransport);
try {
// Call openproject_list_projects
const projRes = (await client.callTool({
name: "openproject_list_projects",
@@ -222,9 +223,10 @@ describe("End-to-End Live Tool Calling over MCP Client", () => {
expect(wpRes.isError).toBeFalsy();
const wpData = JSON.parse(wpRes.content[0]?.text ?? "{}");
expect(wpData.id).toBe(38);
} finally {
await client.close();
await mcpServer.stop();
}
});
test("tool error propagation returns isError: true without crashing client", async () => {
@@ -235,6 +237,7 @@ describe("End-to-End Live Tool Calling over MCP Client", () => {
const client = new Client({ name: "test-runner", version: "1" });
await client.connect(clientTransport);
try {
const errRes = (await client.callTool({
name: "openproject_get_project",
arguments: { projectId: 999999 },
@@ -244,9 +247,10 @@ describe("End-to-End Live Tool Calling over MCP Client", () => {
};
expect(errRes.isError).toBe(true);
expect(errRes.content[0]?.text).toContain("OPENPROJECT_NOT_FOUND");
} finally {
await client.close();
await mcpServer.stop();
}
});
});