Skip to content

Commit b109ebe

Browse files
committed
feat: add HEAD support for health checks and reject invalid HTTP methods with 405 status
Signed-off-by: Max Ostapenko <1611259+max-ostapenko@users.noreply.github.com>
1 parent 0301339 commit b109ebe

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ const handleRequest = async (req, res) => {
7575
res.end();
7676
return;
7777
}
78+
// HEAD is used by health checks / probes — respond quickly without delegating to MCP transport
79+
if (req.method === 'HEAD') {
80+
res.statusCode = 200;
81+
res.end();
82+
return;
83+
}
84+
// Only GET, POST, DELETE are valid MCP methods; reject everything else cleanly
85+
if (!['GET', 'POST', 'DELETE'].includes(req.method)) {
86+
res.statusCode = 405;
87+
res.setHeader('Allow', 'GET, POST, DELETE, OPTIONS, HEAD');
88+
res.end();
89+
return;
90+
}
7891
const { handleMcp } = await import('./mcpHandler.js');
7992
await handleMcp(req, res);
8093
return;

0 commit comments

Comments
 (0)