Skip to content

fix(server): respect Accept header q=0 (RFC 7231 "not acceptable")#3158

Draft
SpiliosDimakopoulos wants to merge 1 commit into
modelcontextprotocol:mainfrom
SpiliosDimakopoulos:fix-accept-header-q0
Draft

fix(server): respect Accept header q=0 (RFC 7231 "not acceptable")#3158
SpiliosDimakopoulos wants to merge 1 commit into
modelcontextprotocol:mainfrom
SpiliosDimakopoulos:fix-accept-header-q0

Conversation

@SpiliosDimakopoulos

Copy link
Copy Markdown

Fixes #3154

What

check_accept_headers() stripped every Accept-header parameter after the media
type (media_type.split(";")[0]), so application/json;q=0 — which per RFC 7231
§5.3.1 explicitly marks JSON as not acceptable — was parsed identically to
plain application/json. A client that explicitly ruled out a representation
could still receive it.

Details

  • Parses each media-range's q parameter (default 1.0 if absent/malformed).
  • q <= 0 moves the type from "accepted" to "rejected".
  • A specific type's rejection takes precedence over a broader wildcard that
    would otherwise accept it (e.g. application/json;q=0, */* still rejects
    JSON) — most-specific-wins, consistent with RFC 7231 §5.3.2 precedence.
  • Nonzero q values are unchanged: this SDK doesn't rank multiple acceptable
    representations by preference, it only gates on q=0 vs not.

Testing

  • test_accept_q0_for_the_required_type_is_not_acceptable — the exact example
    from the issue.
  • test_accept_q0_for_a_specific_type_overrides_a_present_wildcard — specific
    rejection beats a present wildcard.
  • test_accept_nonzero_q_for_the_required_type_is_still_acceptable — regression
    guard for nonzero q.
  • uv run pytest tests/server/, uv run ruff check ., uv run ruff format --check .,
    uv run pyright all pass.

Disclosure

I used AI (Claude) to help draft this fix and its tests; I've reviewed and
understand the change and I'm happy to answer questions about it.

check_accept_headers() discarded every Accept-header parameter after the
media type, so \�pplication/json;q=0\ (explicitly rejecting JSON) was
parsed the same as plain \�pplication/json\ (accepting it). Parse the
q value per RFC 7231 §5.3.1 and treat q<=0 as not-acceptable, with a
specific type's rejection taking precedence over a broader wildcard.

Fixes modelcontextprotocol#3154
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.

Fix Streamable HTTP Accept header quality-factor handling

1 participant