Fix HTTP 406 when Accept header lacks text/event-stream#266
Open
omar-y-abdi wants to merge 2 commits intotadata-org:mainfrom
Open
Fix HTTP 406 when Accept header lacks text/event-stream#266omar-y-abdi wants to merge 2 commits intotadata-org:mainfrom
omar-y-abdi wants to merge 2 commits intotadata-org:mainfrom
Conversation
…port The upstream MCP StreamableHTTPSessionManager requires both application/json and text/event-stream in the Accept header. Standard HTTP JSON-RPC clients (e.g., Google Gemini CLI) only send Accept: application/json, causing a 406 Not Acceptable error. This adds _ensure_accept_headers() to the FastApiHttpSessionManager which appends text/event-stream to the Accept header when it is missing before delegating to the upstream session manager. This ensures standard HTTP JSON-RPC clients work out of the box with mount_http(). Fixes tadata-org#233
- Return early from the original scope reference when SSE is present (avoids copying the headers list on the happy path) - Hoist `new_headers = list(raw_headers)` before the branch to deduplicate the identical call in both if/else arms - Remove the intermediate `has_sse` variable; inline the early return
omar-y-abdi
commented
Mar 13, 2026
Author
omar-y-abdi
left a comment
There was a problem hiding this comment.
Many contributors got time to check it out?
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.
Fixes #233
Clients sending only Accept: application/json get a 406 from the upstream MCP library because it requires text/event-stream in the Accept header.
This adds _ensure_accept_headers() to FastApiHttpSessionManager that appends text/event-stream to the Accept header before delegating to the upstream session manager. The original request scope is not mutated.
Includes 8 new tests (3 integration, 5 unit). All 130 tests pass, coverage 83.53%, ruff and mypy clean.