Title: Tool results over 1 MiB cannot be received over SSE or streamable HTTP, and the limit is not configurable · Issue #3803 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Tool results over 1 MiB cannot be received over SSE or streamable HTTP, and the limit is not configurable · Issue #3803 · modelcontextprotocol/python-sdk
X Title: Tool results over 1 MiB cannot be received over SSE or streamable HTTP, and the limit is not configurable · Issue #3803 · modelcontextprotocol/python-sdk
Description: Summary A tool result larger than 1 MiB can never reach a client on an HTTP transport. The client opens every SSE stream with httpx2's default DEFAULT_MAX_EVENT_SIZE_BYTES = 1024 * 1024: in mcp/client/sse.py, through client.sse(url); in ...
Open Graph Description: Summary A tool result larger than 1 MiB can never reach a client on an HTTP transport. The client opens every SSE stream with httpx2's default DEFAULT_MAX_EVENT_SIZE_BYTES = 1024 * 1024: in mcp/cli...
X Description: Summary A tool result larger than 1 MiB can never reach a client on an HTTP transport. The client opens every SSE stream with httpx2's default DEFAULT_MAX_EVENT_SIZE_BYTES = 1024 * 1024: in mcp...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3803
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tool results over 1 MiB cannot be received over SSE or streamable HTTP, and the limit is not configurable","articleBody":"### Summary\n\nA tool result larger than 1 MiB can never reach a client on an HTTP transport. The client opens every SSE stream with `httpx2`'s default `DEFAULT_MAX_EVENT_SIZE_BYTES = 1024 * 1024`:\n- in `mcp/client/sse.py`, through `client.sse(url)`;\n- in `mcp/client/streamable_http.py`, through `EventSource(response)` in `_handle_sse_response`, the path a POST's response (and so a `tools/call` result) takes.\n\nNeither `sse_client` nor `streamable_http_client` takes a size parameter. A custom `http_client` cannot change it either, because the size is a per-call argument of `client.sse(...)` / `EventSource(...)`, not client configuration. The same result is delivered intact over stdio.\n\nThe failures also differ by transport:\n- **SSE:** the call fails with `MCPError(-32000, 'Connection closed')`, and the transport's task group then dies with `SSEError('Server-sent event exceeded the 1048576 byte limit.')`, so the whole session is lost.\n- **Streamable HTTP:** the call fails with `MCPError(-32000, 'SSE stream ended without a response')`, which does not mention the size limit; the session survives.\n\n### Reproducer (self-contained: an `MCPServer` on loopback and the SDK clients)\n\n```python\nimport asyncio\nimport socket\nimport threading\nimport time\n\nimport uvicorn\nfrom mcp import ClientSession\nfrom mcp.client.sse import sse_client\nfrom mcp.client.streamable_http import streamable_http_client\nfrom mcp.server.mcpserver import MCPServer\n\nserver = MCPServer(name=\"big-result\")\n\n@server.tool()\nasync def big(megabytes: int) -> str:\n \"\"\"Return `megabytes` MiB of text.\"\"\"\n return \"x\" * (megabytes * 1024 * 1024)\n\ndef serve(app) -> int:\n with socket.socket() as sock:\n sock.bind((\"127.0.0.1\", 0))\n port = sock.getsockname()[1]\n uv = uvicorn.Server(uvicorn.Config(app, host=\"127.0.0.1\", port=port, log_level=\"error\"))\n threading.Thread(target=uv.run, daemon=True).start()\n while not uv.started:\n time.sleep(0.05)\n return port\n\nasync def call(label: str, transport_cm) -> None:\n try:\n async with transport_cm as streams, ClientSession(streams[0], streams[1]) as session:\n await session.initialize()\n for mb in (0, 2):\n try:\n result = await asyncio.wait_for(session.call_tool(\"big\", {\"megabytes\": mb}), 30)\n print(f\" {label} {mb} MiB: ok, is_error={result.is_error}\")\n except BaseException as exc:\n print(f\" {label} {mb} MiB: {type(exc).__name__}: {exc!r:.160}\")\n except BaseException as exc:\n print(f\" {label} session exit: {type(exc).__name__}: {exc!r:.200}\")\n\nasync def main() -> None:\n sse_port = serve(server.sse_app())\n http_port = serve(server.streamable_http_app())\n await call(\"sse\", sse_client(f\"http://127.0.0.1:{sse_port}/sse\"))\n await call(\"streamable-http\", streamable_http_client(f\"http://127.0.0.1:{http_port}/mcp\"))\n\nasyncio.run(main())\n```\n\nOutput:\n\n```\n sse 0 MiB: ok, is_error=False\n sse 2 MiB: MCPError: MCPError(-32000, 'Connection closed', None)\n sse session exit: ExceptionGroup: ExceptionGroup('unhandled errors in a TaskGroup', [SSEError('Server-sent event exceeded the 1048576 byte limit.')])\n streamable-http 0 MiB: ok, is_error=False\n streamable-http 2 MiB: MCPError: MCPError(-32000, 'SSE stream ended without a response')\n```\n\n### Expected vs actual\n\n| | Expected | Actual |\n|---|---|---|\n| Large results | delivered up to a size the caller can configure (for example `max_event_size` on `sse_client` / `streamable_http_client`, passed through to `client.sse(...)` and `EventSource(...)`) | hard 1 MiB cap per SSE event, with no way to change it |\n| When the cap is hit | the call fails with an error that names the limit; the session survives | SSE: the session dies; streamable HTTP: a generic \"stream ended\" error with no mention of size |\n\nServers that return documents, graph results or large search results routinely exceed 1 MiB.\n\n### Environment\n\n- `mcp` 2.0.0, `httpx2` 2.13.0, `anyio` 4.14.2, `uvicorn` (from the SDK's dependency set)\n- CPython 3.14.10\n- Windows 11. Linux not tried; the limit comes from `httpx2`'s default and is platform-independent.\n\n### Workaround\n\nNone at the transport level. Downstream, the result-size limit is now an explicit host setting: oversized or failed calls are turned into a structured tool error naming the failure class, and each session is isolated so a transport failure cannot cancel the caller.\n","author":{"url":"https://github.com/gowthamrao","@type":"Person","name":"gowthamrao"},"datePublished":"2026-11-02T16:16:34Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3803"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:33a0ca50-fa54-e833-1020-01ea559469bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACFA:34CAB:1B7882E:230A7DA:6B015A37 |
| html-safe-nonce | 274ba8dbe5958b730f40e539dc99ef47e5c5833260e606ee290985c9925cbba9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0ZBOjM0Q0FCOjFCNzg4MkU6MjMwQTdEQTo2QjAxNUEzNyIsInZpc2l0b3JfaWQiOiI2NjYyMjI0ODM4OTQzMzk4NDU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9c6eb4c809ab727d10b2773396f93bfeeedf656710e6a9c00bef06876502be38 |
| hovercard-subject-tag | issue:6166391841 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3803/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9876bbdaa922ee84bebb801b539739b9e46b3c24240bbdcb37f75ea83fb7952a/modelcontextprotocol/python-sdk/issues/3803 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9876bbdaa922ee84bebb801b539739b9e46b3c24240bbdcb37f75ea83fb7952a/modelcontextprotocol/python-sdk/issues/3803 |
| og:image:alt | Summary A tool result larger than 1 MiB can never reach a client on an HTTP transport. The client opens every SSE stream with httpx2's default DEFAULT_MAX_EVENT_SIZE_BYTES = 1024 * 1024: in mcp/cli... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gowthamrao |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width