fix(server): cap /mcp body size (SRV-03)

The /mcp nest (to_mcp streamable HTTP service) collects the raw body
itself, so axum's extractor-based DefaultBodyLimit never applies and a
multi-GB chunked POST buffers entirely in memory (review-001 SRV-03).

Wrap the nest with an explicit counting-body middleware: 8 MiB cap
(headroom over the gateway's 2 MiB for JSON-RPC batch payloads),
Content-Length-declared oversizes rejected before reading, streaming
oversizes cut off mid-read and answered 413 (rmcp maps body-read errors
to 500, so the middleware sources the status itself).

Verification: cargo check (default + mcp + all-features); mcp test
suite pending tree unstuck from parallel agent's WIP.
This commit is contained in:
2026-08-29 08:47:50 +00:00
parent cc34c08e4e
commit a943d142c4
2 changed files with 199 additions and 0 deletions
+1
View File
@@ -43,6 +43,7 @@ uuid = { version = "1", features = ["v4"] }
futures = "0.3"
openapiv3 = "2"
http = "1"
http-body-util = "0.1"
url = "2"
bytes = "1"
jsonschema = { version = "0.46", default-features = false }