Add Streamable HTTP request body limits (#3095)

This commit is contained in:
Marcelo Trylesinski 2026-07-16 08:33:32 +02:00 • committed by GitHub
commit 03aaebd3aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 280 additions and 19 deletions

View file

@ -43,6 +43,7 @@ async def test_streamable_http_app_takes_runs_options_except_port() -> None:
"stateless_http",
"event_store",
"retry_interval",
"max_request_body_size",
"transport_security",
"host",
}
@ -56,6 +57,17 @@ async def test_a_request_before_the_session_manager_runs_is_rejected() -> None:
await http.post("/mcp")
async def test_streamable_http_app_applies_the_configured_request_body_limit() -> None:
"""The documented `max_request_body_size` option rejects larger requests with HTTP 413."""
server = MCPServer("Notes")
app = server.streamable_http_app(max_request_body_size=8)
transport = httpx2.ASGITransport(app=app)
async with server.session_manager.run():
async with httpx2.AsyncClient(transport=transport, base_url="http://localhost") as http:
response = await http.post("/mcp", content=b"123456789")
assert response.status_code == 413
async def test_mounting_at_the_root_keeps_the_default_path() -> None:
"""tutorial002: `Mount("/")` plus the default `streamable_http_path` leaves the endpoint at `/mcp`."""
(mount,) = tutorial002.app.routes

View file

@ -52,6 +52,7 @@ def test_streamable_http_app_has_no_era_knob() -> None:
"stateless_http",
"event_store",
"retry_interval",
"max_request_body_size",
"transport_security",
"host",
}