fix: support wildcard media types in Accept header validation #1948
+219
−48
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.
Summary
Fixes #1641
The MCP server was rejecting HTTP requests that use wildcard Accept headers like
*/*orapplication/*, returning406 Not Acceptable. This is incorrect behavior per RFC 9110 Section 12.5.1, which defines wildcard media types as valid content negotiation mechanisms.Many HTTP clients (including browsers, curl, and httpx) send
Accept: */*by default, meaning the server was incompatible with standard HTTP tooling.Changes
Modified
_check_accept_headers()inStreamableHTTPServerTransportto:*/*now matches any required content type,application/*matchesapplication/json, andtext/*matchestext/event-stream;q=0.9are now stripped before matching, so*/*;q=0.8is handled correctlyBehavior
*/*application/*text/*application/json, text/**/*;q=0.8text/plainTest plan
Added 7 regression tests in
tests/issues/test_1641_accept_header_wildcard.pycovering:*/*in both JSON and SSE response modesapplication/*matchingapplication/jsontext/*combined with explicitapplication/json