Increase the bounded SSE event limit for larger responses

AD
9h ago
+89-28

Summary

Fixes #1259.

SSE events can legitimately exceed the 1 MiB limit introduced in v2.10.0, including MCP tools/list responses. Applications using the default SSE configuration currently fail on those events.

  • Increase the default max_event_size from 1 MiB to 8 MiB, while retaining an explicit per-event buffer limit. A caller can still set a smaller limit, a larger limit, or None to disable it.
  • Add SSEEventTooLarge(SSEError) for size-limit failures, allowing downstream consumers to distinguish deterministic oversize errors from transient transport errors. Existing except SSEError handlers remain compatible.
  • Add sync/async regression tests for legitimate large events, default-limit rejection, and the new exception; document the trade-off and configuration.

Design consideration: 8 MiB is a proposed bounded default, not a fixed requirement. It permits the reported 1.4 MiB response, at the cost of an increased maximum per-event buffer allocation. I am open to adjusting the default or exception design based on maintainer feedback. The approach is also outlined on issue #1259.

Validation

  • Fork test-suite CI: passed on Python 3.11–3.15, including lint, typing, package and documentation builds, tests, and the coverage gate.
  • Fork CodSpeed: all 17 performance and the memory benchmark tests passed, but uploading their results was rejected with 401 Unauthorized because the fork is not authorised for CodSpeed. Upstream PR checks should validate the integration.
  • The current PR branch contains one clean commit with the exact code tested above.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Prepared with AI assistance. The changes and linked validation results were reviewed before submission.