This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -40,6 +40,7 @@ Every section heading below names the API it affects, so searching this page for
| use stdio or streamable HTTP directly, or maintain a custom transport | [Transports](#transports) |
| maintain OAuth client auth or a protected server | [OAuth and server auth](#oauth-and-server-auth) |
| relied on lenient handling of off-schema traffic, or assert on exact wire bytes | [Stricter protocol validation and wire behavior](#stricter-protocol-validation-and-wire-behavior) |
| rely on `import mcp` importing submodules, patch SDK internals, or subclass SDK pydantic models | [Import graph and startup](#import-graph-and-startup) |
| test against in-memory server/client pairs | [Testing utilities](#testing-utilities) |
| use roots, sampling, logging, or client-to-server progress | [Deprecations](#deprecations) |
| operate servers that 2026-era clients will also connect to | [Notes for 2026-era connections](#notes-for-2026-era-connections) |
Expand Down
Expand Up
@@ -2101,7 +2102,7 @@ v1's internal client set `follow_redirects=True`; set it explicitly when supplyi
`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:
- `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 and `follow_redirects=True`.
- `httpx_client_factory`: gone with no replacement — call your factory yourself and pass the result as `http_client`.
- `httpx_client_factory`: gone with no replacement — call your factory yourself and pass the result as `http_client`. The `McpHttpClientFactory` protocol type is no longer re-exported from `mcp.client.streamable_http` either; annotate your factory as `Callable[..., httpx2.AsyncClient]` (or your own protocol) instead of importing it.
Client-side stream resumption is also unchanged: the transport reconnects a dropped GET stream with `Last-Event-ID` on its own, and `session.send_request(..., metadata=ClientMessageMetadata(resumption_token=..., on_resumption_token_update=...))` (from `mcp.shared.message`) works as in v1.
Expand Down
Expand Up
@@ -2678,6 +2679,61 @@ The envelope exists for OpenTelemetry trace propagation ([SEP-414](https://githu
The SDK's new `opentelemetry-api` runtime dependency is covered under [Packaging, dependencies, and CLI](#packaging-dependencies-and-cli).
## Import graph and startup
### Imports are lazy; explicit imports are the supported form
`import mcp` no longer imports the SDK's whole module graph: the `mcp` package resolves each
export from its home module on first access, and every entry point loads only its own stack
(no server code behind a client, no web framework behind a stdio server, no wire schemas
before a message needs them). Nothing you import changes name or location, and
`from mcp import Client`, `mcp.types.Tool`, `from mcp import *` and object identity behave as
before. See [Imports & startup time](advanced/import-cost.md) for what loads when and how to
prewarm it.
A few incidental things did change:
* **Attribute chains that were never imported explicitly.** `import mcp` used to bind most
submodules as a side effect, so `import mcp` followed by `mcp.client.stdio.stdio_client(...)`
happened to work. It still resolves (the packages import a submodule on attribute access), but
the supported form is to import what you use: `from mcp.client.stdio import stdio_client`, or
`import mcp.client.stdio`.
* **Namespace bindings that tests used to patch.** Modules stopped re-binding names they only
imported: patch or import each object where it is defined. In particular,
`mcp.client.client.streamable_http_client` is `mcp.client.streamable_http.streamable_http_client`,
the HTTP-app pieces formerly bound in `mcp.server.lowlevel.server` / `mcp.server.mcpserver.server`
(`SseServerTransport`, `StreamableHTTPSessionManager`, the auth middleware and route builders)
live in `mcp.server.sse`, `mcp.server.streamable_http_manager` and `mcp.server.auth.*`, and
`get_access_token` / `auth_context_var` are defined in the transport-agnostic
`mcp.server.auth.access_token` (still importable from `mcp.server.auth.middleware.auth_context`).
* **Two web-framework-free homes.** The resumability contract (`EventStore`, `EventMessage`,
`EventCallback`, `EventId`, `StreamId`) is defined in `mcp.server.event_store`, and
`TransportSecurityMiddleware` now lives beside the transports rather than in
`mcp.server.transport_security`; both keep their previous import paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -124,6 +124,10 @@ On those types, every Python attribute is now snake_case: `result.is_error`, `to
**[Running your server](run/index.md)** covers the options; **[Add to an existing app](run/asgi.md)** covers mounting.
### Imports pay for what you use
`import mcp` is now nearly free, and every entry point loads only its own stack: a stdio server never loads the web framework, client code never loads the server, and the protocol's wire schemas load per negotiated version. The work did not vanish, it moved to first use (the first URL `Client`, the first HTTP app, the first message per protocol version), each a one-time cost. That first use is also thread-safe now: the SDK serializes each model's one-time build, which fixes an occasional failure v2 could hit when several threads first-used the same protocol type at once (for example, one client session per thread at process start). **[Imports & startup time](advanced/import-cost.md)** lists what loads when, and how to prewarm all of it at startup if that is where you want it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[experimental - do not merge] Cut startup cost: lazy exports, pay-for-what-you-use imports, deferred model builds #3220
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
[experimental - do not merge] Cut startup cost: lazy exports, pay-for-what-you-use imports, deferred model builds #3220
Filter by extension
Only manifest files
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.