fix: Streamable HTTP Accept negotiation handling
Summary
Fixes #3154
This change fixes a protocol-handling issue in the SDK’s Streamable HTTP transport.
Some clients send Accept headers that include q=0 entries for unsupported media types. Previously, the server could still treat those values as acceptable, even though RFC 7231 specifies that q=0 means “not acceptable.” This patch correctly parses Accept header quality values and rejects media types with q=0 as expected.
Motivation and Context
The previous logic only looked for the presence of supported media types in the Accept header and did not honor quality values. As a result, clients could be accepted even when they explicitly declared that a response type was unacceptable. This change makes negotiation more standards-compliant and prevents mismatches between client intent and server behavior.
How Has This Been Tested?
I added regression tests covering:
Acceptheader handling withq=0- cases where unsupported media types are explicitly marked as unacceptable
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed
Additional context
The change is implemented in src/mcp/server/streamable_http.py, and regression coverage was added in tests/shared/test_streamable_http.py.