Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Streamable HTTP: malformed requests return raw pydantic errors to the client

Aperta Adatta ai principianti
#3,698 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, security

Direzione di ricerca

Il testo grezzo di pydantic e del parsing JSON proviene dal gestore POST in src/mcp/server/streamable_http.py, intorno alle righe 580-596. Il percorso 2026-07-28 in _streamable_http_modern.py (intorno alla riga 415) restituisce già messaggi fissi, quindi copia quello schema. Esegui lo script di esempio per vedere i body attuali, poi verifica che un input malformato restituisca il testo fisso «Parse error» o «Invalid JSON-RPC message», mentre i dettagli finiscono solo nel log del server. Aggiungi test per i casi con jsonrpc mancante e con contenuto non JSON, e verifica la stessa modifica su v1.x.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug v1 v2
Initial Checks
Release line

2.x (current stable)
Also applies to latest 1.x

Description

When the Streamable HTTP POST handler rejects a malformed body, it returns the raw exception text to the client (streamable_http.py L580-L596):

  • No "jsonrpc" field → "Validation error: 6 validation errors for union[JSONRPCRequest,...] ... input_value={...} ... https://errors.pydantic.dev/2.14/v/missing"
  • Not JSON → "Parse error: EOF while parsing a value at line 1 column 27"

A security audit of our MCP server flagged this: the errors reveal that the backend is Python, using pydantic (down to the exact version) and the MCP Python SDK, which helps an attacker enumerate the environment.

Expected: fixed messages (Parse error, Invalid JSON-RPC message), with detail in the server log only. The 2026-07-28 path already does this (_streamable_http_modern.py L415).

The same code is on v1.x, which we run. I’d like to fix both if assigned: a few lines plus tests, with no new API.

Related: #3557 (error code on these lines), #3572 (same pydantic text in tool-argument errors).

Disclosure: this issue was drafte by Claude Code and reviewed/iterated by myself and another senior developer. I ran the reproduction and verified the output myself.

Example Code
import json

from mcp.server import MCPServer
from mcp.server.transport_security import TransportSecuritySettings
from starlette.testclient import TestClient

server = MCPServer("repro")


@server.tool()
def echo(text: str) -> str:
    return text


app = server.streamable_http_app(
    stateless_http=True,
    transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)
headers = {
    "Accept": "application/json, text/event-stream",
    "Content-Type": "application/json",
    "mcp-protocol-version": "2025-06-18",
}
with TestClient(app) as client:
    for body in (
        json.dumps({"id": 1, "method": "tools/call", "params": {"name": "echo", "arguments": {"text": "hi"}}}),
        json.dumps([{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}]),
        '{"jsonrpc": "2.0", "id": 1,',
    ):
        response = client.post("/mcp", content=body, headers=headers)
        print(response.status_code, json.dumps(response.json(), indent=2))
Python & MCP Python SDK
Python 3.12.9
mcp 2.3.0
pydantic 2.14.0
Lingua principale
Python
Stelle
24.5k
Fork
4k
Merge medio
18h 31m
PR unite (30g)
38

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/python-sdk

Tutte le issue di modelcontextprotocol/python-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.