π The fast, Pythonic way to build MCP servers and clients.
Merge remote-tracking branch 'origin/main' into feature/client-auto-default
Jeremiah Lowin35c2b526520a
diff --cc fastmcp_slim/fastmcp/client/transports/config.pyindex ede949402,ea027a08a..3e391b44f--- a/fastmcp_slim/fastmcp/client/transports/config.py+++ b/fastmcp_slim/fastmcp/client/transports/config.py@@@ -90,22 -93,23 +93,38 @@@ class MCPConfigTransport(ClientTransporif len(self.config.mcpServers) == 1:self.transport = next(iter(self.config.mcpServers.values())).to_transport()self._transports.append(self.transport)+ else:+ # Sealing policy for the composite router built in `connect_session`.+ # It is held here, not on the router, because the router is rebuilt+ # on every connection while a guard tool's multi-round-trip spans+ # several of them (a proxy builds a fresh backend client per+ # request). A per-router key would seal `request_state` on one round+ # and reject its own token on the next. Only multi-server configs+ # mount a router, so single-server configs skip the import entirely+ # (it pulls in the SDK's server tier). Aliased so the local binding+ # does not shadow the type-checking-only name in the annotation+ # above.+ from mcp.server.request_state import (+ RequestStateSecurity as _RequestStateSecurity,+ )++ self._request_state_security = _RequestStateSecurity.ephemeral()+ @property+ def legacy_only(self) -> bool:+ """Whether this config can only carry the legacy protocol era.++ A single-server config delegates directly to the underlying transport+ (no proxy), so it inherits that transport's era capability β a modern+ Streamable HTTP backend must stay modern-capable under `mode="auto"`.+ A multi-server config mounts each backend behind a legacy-era+ `ProxyClient` on a composite server, so the composite it exposes is+ legacy-era and `mode="auto"` should negotiate the handshake.+ """+ if len(self.config.mcpServers) == 1:+ return self.transport.legacy_only+ return True+@contextlib.asynccontextmanagerasync def connect_session(self,diff --cc fastmcp_slim/fastmcp/server/providers/proxy.pyindex 8e4f4ed12,a3e9c46fd..c795212ba--- a/fastmcp_slim/fastmcp/server/providers/proxy.py+++ b/fastmcp_slim/fastmcp/server/providers/proxy.py@@@ -1214,16 -1292,16 +1292,23 @@@ class ProxyClient(Client[ClientTranspor):if "name" not in kwargs:kwargs["name"] = self.generate_name()- # ProxyClient defaults to the handshake era: a dual-era backend serves- # both, and a single proxy session can only be one era. Handshake keeps- # the server-initiated push forwarding (sampling / elicitation / roots,- # via the handlers installed below) that proxies rely on. To round-trip- # an upstream guard tool's InputRequiredResult (SEP-2322) instead, opt- # into the modern era explicitly with `create_proxy(target, mode="auto")`- # β the two are mutually exclusive per session. This pin is explicit- # rather than inherited, so flipping `Client`'s own default to `"auto"`- # never changes proxy behavior.+ # ProxyClient itself defaults to the handshake era when constructed+ # directly: a single proxy session can only be one era, and handshake+ # keeps the server-initiated push forwarding (sampling / elicitation /+ # roots, via the handlers installed below) that proxies rely on. When a+ # proxy is created from a non-Client target (`create_proxy(target)` /+ # `_create_client_factory`) with no explicit mode, the factory instead+ # MIRRORS the front connection's negotiated era onto this client per+ # request, so the whole chain speaks one era end-to-end. An explicit+ # `mode=` (e.g. `create_proxy(target, mode="auto")`) pins the era and+ # overrides mirroring. The eras are mutually exclusive per session.++ #++ # The handshake default is pinned explicitly rather than inherited from++ # `Client`, whose own default is `"auto"`: mirroring only applies when++ # there is a front request to mirror, so this is the fallback for a++ # directly-constructed ProxyClient, and it must not drift with the++ # client default.+ kwargs.setdefault("mode", "legacy")# Install context-restoring handler wrappers BEFORE super().__init__# registers them with the Client's session kwargs.self._proxy_rc_ref = [None]