Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
Expand Down Expand Up @@ -1614,3 +1620,4 @@ if (process.env.CLOUD_SERVICE === 'true') {
process.exit(1);
});
}