Last active
May 8, 2025 20:13
-
-
Save evalstate/196e3193a4ae5c4d5db9e8363d6c411d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "crashtest", | |
"version": "1.0.0", | |
"main": "dist/server.js", | |
"type": "module", | |
"scripts": { | |
"build": "tsc", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"dependencies": { | |
"@modelcontextprotocol/sdk": "^1.11.0", | |
"express": "^4.18.2", | |
"zod": "^3.22.4" | |
}, | |
"devDependencies": { | |
"@types/express": "^4.17.21", | |
"@types/node": "^20.12.10", | |
"typescript": "^5.8.3" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"description": "" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//npm install && npm run build && node ./dist/server.js | |
import express from "express"; | |
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | |
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"; | |
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"; | |
import { z } from "zod"; | |
const server = new McpServer({ | |
name: "crashtest", | |
version: "1.0.0" | |
}); | |
server.tool( | |
"crashtest0-undefined", | |
`Some Description`, | |
// { },//change to {} to crash | |
async (_extra) => { | |
return { | |
content: [{ type: "text", text: "did it work?" }], | |
}; | |
} | |
); | |
server.tool( | |
"crashtest1-empty", | |
`Some Description`, | |
{}, //change to {} to crash | |
async (_extra) => { | |
return { | |
content: [{ type: "text", text: "did it work?" }], | |
}; | |
} | |
); | |
server.tool( | |
"crashtest2-dummy", | |
`Some Description`, | |
{ dummyArg: z.string() }, //change to {} to crash | |
async (_extra) => { | |
return { | |
content: [{ type: "text", text: "did it work?" }], | |
}; | |
} | |
); | |
const app = express(); | |
app.use(express.json()); | |
app.use((req, res, next) => { | |
next(); | |
}); | |
const transports = { | |
streamable: {} as Record<string, StreamableHTTPServerTransport>, | |
sse: {} as Record<string, SSEServerTransport> | |
}; | |
// Streamable HTTP endpoint placeholder | |
app.all('/mcp', async (req, res) => { | |
console.log(`[MCP HTTP] ${req.method} ${req.originalUrl}`); | |
}); | |
// SSE endpoint | |
app.get('/sse', async (req, res) => { | |
console.log(`[SSE] New connection from ${req.ip}`); | |
const transport = new SSEServerTransport('/messages', res); | |
transports.sse[transport.sessionId] = transport; | |
res.on("close", () => { | |
delete transports.sse[transport.sessionId]; | |
}); | |
await server.connect(transport); | |
}); | |
// Message endpoint | |
app.post('/messages', async (req, res) => { | |
const sessionId = req.query.sessionId as string; | |
const transport = transports.sse[sessionId]; | |
if (transport) { | |
await transport.handlePostMessage(req, res, req.body); | |
} else { | |
res.status(400).send('No transport found for sessionId'); | |
} | |
}); | |
// Start server | |
app.listen(8080, () => { | |
console.log(`Server listening on port 8080`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "crashtest", | |
"version": "1.0.0", | |
"main": "dist/server.js", | |
"type": "module", | |
"scripts": { | |
"build": "tsc", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"dependencies": { | |
"@modelcontextprotocol/sdk": "^1.10.2", | |
"express": "^4.18.2", | |
"zod": "^3.22.4" | |
}, | |
"devDependencies": { | |
"@types/express": "^4.17.21", | |
"@types/node": "^20.12.10", | |
"typescript": "^5.8.3" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"description": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.11.1
