Skip to content

Conversation

@TheodorNEngoy
Copy link
Contributor

@TheodorNEngoy TheodorNEngoy commented Feb 7, 2026

This adds a basic DoS guard for the built-in HTTP transports by limiting POST request body size.

  • Adds MaxBodyBytes to SSEOptions and StreamableHTTPOptions (default: DefaultMaxBodyBytes = 1_000_000; negative disables).
  • Adds MaxBodyBytes to SSEServerTransport and StreamableServerTransport for custom handler usage.
  • Returns 413 Request Entity Too Large when the limit is exceeded.
  • Includes tests covering both SSE and streamable handlers/transports.

Rationale: avoid unbounded io.ReadAll(req.Body) buffering for network-exposed servers.

@TheodorNEngoy
Copy link
Contributor Author

Local sanity check: go test ./... passes on this branch.

@maciej-kisiel
Copy link
Contributor

Adding a default for this limit is a backwards incompatible behavior change, which we generally try to avoid. Isn't this already easy enough to achieve by wrapping the MCP HTTP Handler with https://godoc.corp.google.com/pkg/net/http#MaxBytesHandler?

@maciej-kisiel maciej-kisiel added proposal A proposal for an a new API or behavior. See CONTRIBUTING.md. waiting for info and removed proposal A proposal for an a new API or behavior. See CONTRIBUTING.md. waiting for info labels Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants