Skip to content

fix: accept wildcard media types in Accept header per RFC 7231#2152

Open
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:fix/accept-header-wildcards
Open

fix: accept wildcard media types in Accept header per RFC 7231#2152
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:fix/accept-header-wildcards

Conversation

@shivama205
Copy link

Summary

  • Fix _check_accept_headers to accept wildcard media types (*/*, application/*, text/*) in the Accept header, per RFC 7231, section 5.3.2
  • Strip quality value parameters (e.g. ;q=0.8) before matching media types
  • Add comprehensive tests for wildcard acceptance and rejection scenarios

Problem

The server rejected requests with wildcard Accept headers like */* or application/*, returning 406 Not Acceptable. This violated RFC 7231 and broke interoperability with HTTP clients that send Accept: */* by default (e.g. httpx, requests).

Closes #1641

Test plan

  • Wildcard */* accepted for both SSE and JSON-only modes
  • application/* + text/* accepted for SSE mode
  • application/* alone correctly rejected for SSE mode (doesn't cover text/event-stream)
  • Quality parameters (*/*;q=0.8) handled correctly
  • Truly missing Accept header still rejected
  • Incompatible types (text/html) still rejected
  • All 1134 existing tests pass
  • Linting, formatting, and type checks clean

@shivama205
Copy link
Author

Hi @Kludex @maxisbey — could you please review this when you get a chance? This fixes #1641 (wildcard Accept header support per RFC 7231). All CI checks are passing. Thanks!

@shivama205
Copy link
Author

@felixweinberger @maxisbey could you please review this when you get a chance? Thanks!

The server rejected requests with wildcard Accept headers like `*/*`,
`application/*`, or `text/*`, returning 406 Not Acceptable. This violated
RFC 7231, section 5.3.2, which defines wildcard media ranges as valid.

Update `_check_accept_headers` to recognize `*/*` as matching all types,
`application/*` as matching `application/json`, and `text/*` as matching
`text/event-stream`. Also strip quality parameters before matching.

Github-Issue:modelcontextprotocol#1641
Reported-by:rh-fr
@shivama205 shivama205 force-pushed the fix/accept-header-wildcards branch from b5d0136 to 6c49c5f Compare March 4, 2026 18:36
@shivama205
Copy link
Author

Bumping this — just rebased onto latest main (clean, no conflicts). This fixes a real interoperability bug: clients like httpx and requests send Accept: */* by default and currently get a 406 Not Acceptable. All CI is passing.

If anyone's on the MCP Discord, would really appreciate a ping to get eyes on this. Happy to make any changes to get it merged. 🙏

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.

MCP Server won't work with wildcard in "Accept" header and therefore is non‑compliant with HTTP spec

1 participant