Skip to content

Fix Streamable HTTP Accept header quality-factor handling #3154

Description

@dchou1618

Initial Checks

Description

Streamable HTTP currently ignores q=0 values in the Accept header, so requests that explicitly mark a media type as unacceptable can still be accepted. This violates RFC 7231 semantics for content negotiation and can cause clients and servers to disagree about which response format is actually allowed.

Example Code

from starlette.requests import Request

def check_accept_headers(request: Request) -> tuple[bool, bool]:
    accept_header = request.headers.get("accept", "")
    accept_types = [media_type.strip().split(";")[0].strip().lower() for media_type in accept_header.split(",")]

    has_wildcard = "*/*" in accept_types
    has_json = has_wildcard or any(t in ("application/json", "application/*") for t in accept_types)
    has_sse = has_wildcard or any(t in ("text/event-stream", "text/*") for t in accept_types)

    return has_json, has_sse

# Example: client explicitly rejects JSON
request = Request({"type": "http", "method": "GET", "headers": [(b"accept", b"application/json;q=0, text/event-stream;q=1.0")]})

print(check_accept_headers(request))
# -> (True, True)

Python & MCP Python SDK

Python 3.12.10
MCP Python SDK: 1.28.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesbugSomething isn't workingneeds confirmationNeeds confirmation that the PR is actually required or needed.v1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions