You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/client/transports.md
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,16 +46,31 @@ environment variables or pass an explicit `verify=ssl_context` to your `httpx2.A
46
46
(background in
47
47
[`httpx` and `httpx-sse` replaced by `httpx2`](../migration.md#httpx-and-httpx-sse-replaced-by-httpx2)).
48
48
49
+
### Larger SSE events
50
+
51
+
Pass `max_sse_event_size` when a server sends a large tool result or notification in one SSE event:
52
+
53
+
```python title="client.py" hl_lines="6-9"
54
+
--8<--"docs_src/client_transports/tutorial005.py"
55
+
```
56
+
57
+
The default is 16 MiB per event, measured in bytes before the event is parsed. The limit applies to
58
+
POST responses, the GET stream, and resumed streams. If an event exceeds it, the request fails with
59
+
an error naming the limit. Set `max_sse_event_size=None` to disable the cap when you trust the server
60
+
and need larger events. JSON responses are unaffected. If you use `ClientSessionGroup`, set the same
61
+
option on `StreamableHttpParameters`.
62
+
49
63
!!! warning
50
64
`streamable_http_client` used to take `headers=` and `timeout=` directly. It does not any more:
51
-
its only parameters are `url`, `http_client`and `terminate_on_close`. Reach for `headers=` out
65
+
its parameters are `url`, `http_client`, `terminate_on_close`, and `max_sse_event_size`. Reach for `headers=` out
52
66
of habit and you get:
53
67
54
68
```text
55
69
TypeError: streamable_http_client() got an unexpected keyword argument 'headers'
56
70
```
57
71
58
-
Everything HTTP-shaped now lives on the one `httpx2.AsyncClient` you pass in.
72
+
Headers, authentication, proxies, and timeouts live on the one `httpx2.AsyncClient` you pass in.
73
+
`max_sse_event_size` applies to the MCP transport's SSE readers instead.
59
74
60
75
!!! info
61
76
`httpx2` keeps the familiar `httpx` API, so if you know `httpx` you already know how to do auth,
@@ -132,6 +147,7 @@ A **transport** is any async context manager that yields a `(read, write)` pair
132
147
133
148
*`Client("http://.../mcp")` (a URL) connects over Streamable HTTP, the production transport.
134
149
* Headers, auth, proxies and timeouts belong on an `httpx2.AsyncClient` you pass to `streamable_http_client(url, http_client=...)`. There is no `headers=` keyword.
150
+
* Use `streamable_http_client(url, max_sse_event_size=...)` to change the byte limit for each SSE event.
135
151
* Redirects are followed only within the URL's own origin (a trailing-slash `307`/`308`), plus `http`→`https` on the same host. Anything else fails with `Redirect to … not followed`; configure the final URL.
136
152
* stdio is `Client(StdioServerParameters(...))`. Wrap it in `stdio_client(...)` yourself only to redirect the child's stderr.
137
153
* The subprocess gets an allow-listed environment, not yours; `env=` adds to it.
Copy file name to clipboardExpand all lines: docs/migration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2104,7 +2104,7 @@ async with http_client:
2104
2104
2105
2105
v1's internal client set `follow_redirects=True`. You don't need it on your own client: the transport follows a method-preserving redirect within the endpoint's origin (a trailing-slash 307/308, say) itself, and does not follow one anywhere else, whatever the client is configured to do.
2106
2106
2107
-
`streamable_http_client` itself keeps a small signature — `streamable_http_client(url, *, http_client=None, terminate_on_close=True)` — and now yields a 2-tuple (next section). The removed function's other parameters map onto the client you build:
2107
+
`streamable_http_client` itself keeps a small signature — `streamable_http_client(url, *, http_client=None, terminate_on_close=True, max_sse_event_size=16 * 1024 * 1024)` — and now yields a 2-tuple (next section). The removed function's other parameters map onto the client you build:
2108
2108
2109
2109
-`headers`, `timeout`, `sse_read_timeout`, `auth`: set them on the `httpx2.AsyncClient` as above. `streamablehttp_client` defaulted to `httpx.Timeout(30, read=300)`; a bare `httpx2.AsyncClient()` falls back to httpx2's flat 5-second timeout, too short for the long-lived GET stream, so set `timeout=httpx2.Timeout(30, read=300)` (as shown) to keep v1's values. Omitting `http_client` still gives you a default client with those timeouts.
2110
2110
-`httpx_client_factory`: gone with no replacement — call your factory yourself and pass the result as `http_client`.
0 commit comments