I am building an express app for MCP Server. I was able to follow guides on building and deploying express app to vercel.
However, I can not seem to get the /sse endpoint working as the returns the stream response. The API handler is executed to the last line, but the browser never receives the response, not even response headers.
const app = express();
app.use(cors())
app.get("/", (req: Request, res: Response) => {
res.send("Hello World");
})
app.get(
'/sse',
async (req: Request, res: Response) => {
const transport = new SSEServerTransport('/messages', res);
const server = createMcpServer();
server.connect(transport);
})
export default app
The SSEServerTransport sets all required headers for streams - Content-Type: text/event-stream and Connection: keep-alive
vercel.json
{
"version": 2,
"outputDirectory": "dist",
"builds": [
{
"src": "dist/**/*.js",
"use": "@vercel/node",
"config": { "maxDuration": 300 }
}
],
"rewrites": [ { "source": "/(.*)", "destination": "/dist/index.js" } ]
}
The app works fine when I run it on the standard node, but running on @vercel/node never returns a byte for the /see calls, eventually it leads to timeout
After debugging a lot I noticed @vercel/node updates the Connection request header to close while the browser sends keep-alive. Is there a way I can configure Connection header to pass-through?