fix: accept wildcard media types in Accept header per RFC 7231 - #2152
Conversation
|
@felixweinberger @maxisbey could you please review this when you get a chance? Thanks! |
b5d0136 to
6c49c5f
Compare
|
Bumping this — just rebased onto latest 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. 🙏 |
maxisbey
left a comment
There was a problem hiding this comment.
Thanks for this — the approach is correct and the test coverage is great. Two small asks before merge (suggestions inline, should be one-click applies).
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
- Normalize media types to lowercase for case-insensitive matching per RFC 7231 - Use exact match instead of startswith to prevent over-matching - Replace headers.update with headers.pop for cleaner Accept removal in tests
d8bd3e4 to
8e2ec6f
Compare
|
Thanks for the thorough review @maxisbey! Applied all your suggestions:
|
Summary
_check_accept_headersto accept wildcard media types (*/*,application/*,text/*) in theAcceptheader, per RFC 7231, section 5.3.2;q=0.8) before matching media typesProblem
The server rejected requests with wildcard
Acceptheaders like*/*orapplication/*, returning406 Not Acceptable. This violated RFC 7231 and broke interoperability with HTTP clients that sendAccept: */*by default (e.g.httpx,requests).Closes #1641
Test plan
*/*accepted for both SSE and JSON-only modesapplication/*+text/*accepted for SSE modeapplication/*alone correctly rejected for SSE mode (doesn't covertext/event-stream)*/*;q=0.8) handled correctlytext/html) still rejected