fix: accept single supported content type in SSE mode Accept header - #2361
fix: accept single supported content type in SSE mode Accept header#23614444J99 wants to merge 2 commits into
Conversation
…alidation Relax the Accept header validation for SSE-mode POST requests from requiring both application/json AND text/event-stream to requiring at least one. This restores compatibility with clients that send only Accept: text/event-stream (e.g. Anthropic's MCP proxy used by Claude.ai for remote MCP integrations). The MCP spec uses SHOULD (not MUST) for clients accepting both content types. The server already negotiates the response format based on the message type — notifications/responses get JSON 202s, requests get SSE streams — so requiring both types in the Accept header is stricter than necessary. Closes modelcontextprotocol#2349
|
Hi — checking in on this PR. It relaxes the The MCP spec uses SHOULD, not MUST, for accepting both content types. Full test suite passes (1146 tests), and the change is minimal (AND → OR in the validation check). Happy to rebase if needed. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The strict |
Summary
Relax the
Acceptheader validation for SSE-mode POST requests from requiring bothapplication/jsonANDtext/event-streamto requiring at least one. This restores compatibility with clients that send onlyAccept: text/event-stream, such as Anthropic's MCP proxy used by Claude.ai for remote MCP integrations.Closes #2349
Problem
The
_validate_accept_header()method uses a strict AND condition:This rejects clients sending
Accept: text/event-streamwithoutapplication/json, returning406 Not Acceptable. The MCP spec uses SHOULD (not MUST) for clients accepting both content types, and the server already negotiates response format based on message type — notifications/responses get JSON 202s regardless, and request responses use SSE streams.Changes
src/mcp/server/streamable_http.py: Change AND to OR in_validate_accept_header()for SSE mode, requiring at least one supported content type instead of bothtests/shared/test_streamable_http.py: Addtest_accept_header_single_typeparametrized test coveringtext/event-stream,application/json,application/*, andtext/*as individually sufficient Accept values; update incompatible test to remove values that now passtests/issues/test_1363_race_condition_streamable_http.py: Update race condition test expectations — single supported Accept types now return 200 instead of 406Test plan
test_accept_header_single_type— verifies each supported type individually accepted (4 cases)text/html,image/png) still correctly rejected with 406is_json_response_enabled=True) unchanged — still requiresapplication/jsonruff checkcleanpyrightclean (0 errors)