Proxy servers like Nginx buffer responses by default, which causes
SSE streams to be delayed. Adding the X-Accel-Buffering: no header
instructs reverse proxies to disable response buffering for SSE
endpoints, ensuring real-time streaming delivery.
Applied to all three SSE response locations:
- HttpServletSseServerTransportProvider (SSE endpoint)
- HttpServletStreamableServerTransportProvider (GET and POST SSE)
Fixes modelcontextprotocol#293
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Adds the X-Accel-Buffering: no header to all SSE response endpoints to prevent reverse proxy buffering.
Problem
Proxy servers like Nginx buffer HTTP responses by default. For SSE (Server-Sent Events) endpoints, this causes events to be held in the buffer and delivered in batches instead of being streamed in real-time. This is particularly problematic for MCP transports that rely on SSE for real-time communication.
Fix
Added response.setHeader("X-Accel-Buffering", "no") to all three SSE response locations:
This header is a de facto standard supported by Nginx, AWS ALB, and other common proxies. It has no effect when no proxy is present.
Testing
All 680 existing tests pass (1 pre-existing Docker container startup failure unrelated to this change).
Fixes #293