fix: accept single supported content type in SSE mode Accept header#2361
Open
4444J99 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: accept single supported content type in SSE mode Accept header#23614444J99 wants to merge 1 commit intomodelcontextprotocol:mainfrom
4444J99 wants to merge 1 commit intomodelcontextprotocol:mainfrom
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)