Skip to content

Add X-Accel-Buffering: no header to SSE responses#848

Open
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
rameshreddy-adutla:feat/293-x-accel-buffering-header
Open

Add X-Accel-Buffering: no header to SSE responses#848
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
rameshreddy-adutla:feat/293-x-accel-buffering-header

Conversation

@rameshreddy-adutla
Copy link

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:

  1. HttpServletSseServerTransportProvider — SSE endpoint handler
  2. HttpServletStreamableServerTransportProvider — GET handler (SSE stream)
  3. HttpServletStreamableServerTransportProvider — POST handler (streaming requests)

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add X-Accel-Buffering: no Header for SSE Responses

1 participant