From 5e2450bc7d14eda2f1e75f2efe276351cd9b5f44 Mon Sep 17 00:00:00 2001 From: Troy Zuroske Date: Wed, 16 Jul 2025 08:46:07 -0400 Subject: [PATCH] This adds a health check for the SSELocalServer as well as makes the host an configurable by an environment variable. --- src/index.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index ff2550d..c673963 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1505,6 +1505,10 @@ async function runSSELocalServer() { let transport: SSEServerTransport | null = null; const app = express(); + app.get('/health', (req, res) => { + res.status(200).send('OK'); + }); + app.get('/sse', async (req, res) => { transport = new SSEServerTransport(`/messages`, res); res.on('close', () => { @@ -1521,13 +1525,15 @@ async function runSSELocalServer() { } }); - const PORT = process.env.PORT || 3000; + const PORT = parseInt(process.env.PORT || "3000", 10); + const HOST = process.env.HOST || 'localhost'; console.log('Starting server on port', PORT); + console.log('Starting server on host', HOST) try { - app.listen(PORT, () => { - console.log(`MCP SSE Server listening on http://localhost:${PORT}`); - console.log(`SSE endpoint: http://localhost:${PORT}/sse`); - console.log(`Message endpoint: http://localhost:${PORT}/messages`); + app.listen(PORT, HOST, () => { + console.log(`MCP SSE Server listening on http://${HOST}:${PORT}`); + console.log(`SSE endpoint: http://${HOST}:${PORT}/sse`); + console.log(`Message endpoint: http://${HOST}:${PORT}/messages`); }); } catch (error) { console.error('Error starting server:', error); @@ -1614,3 +1620,4 @@ if (process.env.CLOUD_SERVICE === 'true') { process.exit(1); }); } +