Fixing SSE (MCP) Behind NGINX in a Node.js + PM2 Stack
July 18th, 2025
TLDR
If your MCP server is using SSE and you are behind nginx, you need to turn buffering off!
My go-to stack for web development is a Node.js + Express app served behind an NGINX reverse proxy, with the Node app managed by PM2. It’s stable, battle-tested, and easy to deploy. But I recently ran into a subtle problem when I added an MCP server (based on Server-Sent Events SSE) to the stack.
Locally, everything worked. The browser connected to the MCP endpoint, got a response, and the initialize message came through just fine. But once deployed, the client hung on connect. No errors, just silence.
I spent some time with mcp inspector (great tool for doing simple MCP debugging), and convinced myself I wasn't crazy - the code was the same, the MCP server was being reached - but no response from initialize, no tool list, no messages.
The culprit? NGINX buffering and timeouts were silently breaking the SSE connection.
Here’s what fixed it:
location /mcp/ {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_set_header Host $host;
proxy_read_timeout 3600;
proxy_send_timeout 3600;
}
This block goes inside your server block in your NGINX config. It matches all URLs that start with /mcp/, including subpaths like /mcp/sse, and proxies them directly to your Node.js app. The critical line is proxy_buffering off;—without it, NGINX holds the event stream in memory instead of streaming it to the client, effectively breaking SSE. This won't effect anything else (you most likely already have another location block handling all the rest of the proxying in the first place).
You can tell this is the issue when your local dev (bypassing NGINX) works perfectly, but the deployed version stalls without receiving events.
Hope this saves someone else an hour of frustration.
Some more of my work...

Ramapo College
Professor of Computer Science, Chair of Computer Science and Cybersecurity, Director of MS in Computer Science, Data Science, Applied Mathematics

Frees Consulting and Development LLC
My consultancy - Your ideas into real working solutions and product: building MVPs, modernizing legacy systems and integrating AI and automation into your workflows.

Node.js C++ Integration
My work on Node.js and C++ Integration, a blog and e-book. Native addons, asynchronous processing, high performance cross-platform deployment.

Foundations of Web Development
For students and professionals - full-stack guide to web development focused on core architectural concepts and lasting understanding of how the web works
The views and opinions expressed in this blog are solely my own and do not represent those of Ramapo College or any other organization with which I am affiliated.