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
{{ message }}
Repository navigation
Commit 7fdc944
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/client/transports.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,16 +46,32 @@ 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 1 MiB per event, measured in bytes before the event is parsed. The limit applies to
58
+
POST responses, the GET stream, and resumed streams. An oversized event in a POST response or resumed
59
+
stream fails that request with an SSE error. On the background GET stream, the client logs
60
+
the error and retries the stream. Set `max_sse_event_size=None` to disable the cap when you trust the
61
+
server and need larger events. JSON responses are unaffected. If you use `ClientSessionGroup`, set the
62
+
same option on `StreamableHttpParameters`.
63
+
49
64
!!! warning
50
65
`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
66
+
its parameters are `url`, `http_client`, `terminate_on_close`, and `max_sse_event_size`. Reach for `headers=` out
52
67
of habit and you get:
53
68
54
69
```text
55
70
TypeError: streamable_http_client() got an unexpected keyword argument 'headers'
56
71
```
57
72
58
-
Everything HTTP-shaped now lives on the one `httpx2.AsyncClient` you pass in.
73
+
Headers, authentication, proxies, and timeouts live on the one `httpx2.AsyncClient` you pass in.
74
+
`max_sse_event_size` applies to the MCP transport's SSE readers instead.
59
75
60
76
!!! info
61
77
`httpx2` keeps the familiar `httpx` API, so if you know `httpx` you already know how to do auth,
@@ -132,6 +148,7 @@ A **transport** is any async context manager that yields a `(read, write)` pair
132
148
133
149
*`Client("http://.../mcp")` (a URL) connects over Streamable HTTP, the production transport.
134
150
* Headers, auth, proxies and timeouts belong on an `httpx2.AsyncClient` you pass to `streamable_http_client(url, http_client=...)`. There is no `headers=` keyword.
151
+
* Use `streamable_http_client(url, max_sse_event_size=...)` to change the byte limit for each SSE event.
135
152
* 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
153
* stdio is `Client(StdioServerParameters(...))`. Wrap it in `stdio_client(...)` yourself only to redirect the child's stderr.
137
154
* 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=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