Skip to content

Commit 51efe4e

Browse files
committed
add health check endpoint to mcp server
1 parent 2c80bf4 commit 51efe4e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/transports/streamableHttp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class StreamableHttpRunner extends TransportRunnerBase {
4343

4444
app.enable("trust proxy"); // needed for reverse proxy support
4545
app.use(express.json());
46+
47+
// Health endpoint for container orchestration (placed before auth middleware)
48+
app.get("/health", (req: express.Request, res: express.Response) => {
49+
res.status(200).json({ status: "healthy", service: "mongodb-mcp" });
50+
});
51+
4652
app.use((req, res, next) => {
4753
for (const [key, value] of Object.entries(this.userConfig.httpHeaders)) {
4854
const header = req.headers[key.toLowerCase()];

tests/integration/transports/streamableHttp.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ describe("StreamableHttpRunner", () => {
103103
});
104104
});
105105
}
106+
107+
it("health endpoint works without authentication", async () => {
108+
// Health endpoint should work regardless of configured headers
109+
const response = await fetch(`${runner.serverAddress}/health`);
110+
expect(response.status).toBe(200);
111+
const data = (await response.json()) as { status: string; service: string };
112+
expect(data).toEqual({ status: "healthy", service: "mongodb-mcp" });
113+
});
106114
});
107115
}
108116

0 commit comments

Comments
 (0)