modelcontextprotocol / modelcontextprotocol/python-sdk
Fix Streamable HTTP Accept header quality-factor handling
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 24.3k
- Fork
- 4k
- Merge medio
- 1g 1h
- PR unite (30g)
- 31
Descrizione
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia tracciando la gestione delle richieste Streamable HTTP e l'esempio check_accept_headers nell'issue, concentrandoti su come vengono analizzati i parametri Accept. Verifica il comportamento con la richiesta fornita application/json;q=0 e text/event-stream;q=1.0 e considera ulteriori casi di fattori di qualità; il lavoro è completo quando i tipi di media esplicitamente non accettabili non vengono trattati come accettati secondo la semantica di RFC 7231.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 68/100