Skip to content

Fix HTTP 406 when Accept header lacks text/event-stream#266

Open
omar-y-abdi wants to merge 2 commits intotadata-org:mainfrom
omar-y-abdi:fix/http-accept-header-validation
Open

Fix HTTP 406 when Accept header lacks text/event-stream#266
omar-y-abdi wants to merge 2 commits intotadata-org:mainfrom
omar-y-abdi:fix/http-accept-header-validation

Conversation

@omar-y-abdi
Copy link
Copy Markdown

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.

…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
Copy link
Copy Markdown
Author

@omar-y-abdi omar-y-abdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many contributors got time to check it out?

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.

[BUG] HTTP endpoint incorrectly requires text/event-stream Accept header

1 participant