Add missing app.listen error handling to server examples
This commit is contained in:
parent
22dc79b2a4
commit
4056c098a1
8 changed files with 40 additions and 8 deletions
|
|
@ -102,7 +102,11 @@ async function runServer(port: number | null) {
|
|||
await transport.handlePostMessage(req, res);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
app.listen(port, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Server running on http://localhost:${port}/sse`);
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -200,7 +200,11 @@ export const setupAuthServer = ({authServerUrl, mcpServerUrl, strictResource}: {
|
|||
|
||||
const auth_port = authServerUrl.port;
|
||||
// Start the auth server
|
||||
authApp.listen(auth_port, () => {
|
||||
authApp.listen(auth_port, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`OAuth Authorization Server listening on port ${auth_port}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,11 @@ app.get('/mcp', async (req: Request, res: Response) => {
|
|||
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`MCP Streamable HTTP Server listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,11 @@ app.post('/messages', async (req: Request, res: Response) => {
|
|||
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Simple SSE Server (deprecated protocol version 2024-11-05) listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,11 @@ app.delete('/mcp', async (req: Request, res: Response) => {
|
|||
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`MCP Stateless Streamable HTTP Server listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -648,7 +648,11 @@ if (useOAuth && authMiddleware) {
|
|||
app.delete('/mcp', mcpDeleteHandler);
|
||||
}
|
||||
|
||||
app.listen(MCP_PORT, () => {
|
||||
app.listen(MCP_PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,11 @@ app.post("/messages", async (req: Request, res: Response) => {
|
|||
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Backwards compatible MCP server listening on port ${PORT}`);
|
||||
console.log(`
|
||||
==============================================
|
||||
|
|
|
|||
|
|
@ -112,7 +112,11 @@ app.get('/mcp', async (req: Request, res: Response) => {
|
|||
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Server listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue