π The fast, Pythonic way to build MCP servers and clients.
Expose ClientGroup from package root (#4987)
Jeremiah Lowinfbe04c715553
diff --git a/docs/clients/client-groups.mdx b/docs/clients/client-groups.mdxindex 49b172340..e2adef623 100644--- a/docs/clients/client-groups.mdx+++ b/docs/clients/client-groups.mdx@@ -21,8 +21,7 @@ Construct the clients explicitly when each server needs its own handlers, authenfrom pathlib import Pathimport asyncio-from fastmcp import Client-from fastmcp.client.group import ClientGroup+from fastmcp import Client, ClientGrouplegacy_client = Client(Path("legacy_server.py"), mode="legacy")modern_client = Client("https://modern.example.com/mcp", mode="auto")@@ -76,7 +75,7 @@ The group aggregates names and detects collisions; it never stands between the a`ClientGroup.from_config` creates one client per server rather than passing the entire configuration through a proxy. A FastMCP-specific `mode` field can select the protocol behavior for each server:```python-from fastmcp.client.group import ClientGroup+from fastmcp import ClientGroupconfig = {"mcpServers": {diff --git a/fastmcp_slim/fastmcp/__init__.py b/fastmcp_slim/fastmcp/__init__.pyindex 9d64f128e..5a77961de 100644--- a/fastmcp_slim/fastmcp/__init__.py+++ b/fastmcp_slim/fastmcp/__init__.py@@ -12,6 +12,7 @@ from fastmcp.utilities.logging import configure_logging as _configure_loggingif TYPE_CHECKING:from fastmcp.client import Client as Client+ from fastmcp.client.group import ClientGroup as ClientGroupfrom fastmcp.apps.app import FastMCPApp as FastMCPAppfrom fastmcp.server.context import Context as Contextfrom fastmcp.server.server import FastMCP as FastMCP@@ -41,8 +42,8 @@ if settings.deprecation_warnings:# --- Lazy imports for performance (see #3292) ----# Client and the client submodule are deferred so that server-only users-# don't pay for the client import chain. Do not convert back to top-level.+# Client exports and the client submodule are deferred so that server-only users+# don't pay for the client import chain. Do not make these eager module imports.def __getattr__(name: str) -> object:@@ -53,6 +54,13 @@ def __getattr__(name: str) -> object:raise ImportError(_install_hints.CLIENT_SUPPORT) from excreturn Client+ if name == "ClientGroup":+ try:+ from fastmcp.client.group import ClientGroup+ except ImportError as exc:+ raise ImportError(_install_hints.CLIENT_SUPPORT) from exc++ return ClientGroupif name == "Context":try:from fastmcp.server.context import Context@@ -89,6 +97,7 @@ def __getattr__(name: str) -> object:__all__ = ["Client",+ "ClientGroup","Context","FastMCP","FastMCPApp",diff --git a/tests/client/group/test_client_group.py b/tests/client/group/test_client_group.pyindex b79d6f38d..8b4f58de6 100644--- a/tests/client/group/test_client_group.py+++ b/tests/client/group/test_client_group.py@@ -7,8 +7,7 @@ from unittest.mock import patchimport pytestfrom pydantic import ConfigDict-from fastmcp import Client, Context, FastMCP-from fastmcp.client.group import ClientGroup+from fastmcp import Client, ClientGroup, Context, FastMCPfrom fastmcp.client.transports import FastMCPTransportfrom fastmcp.mcp_config import MCPConfig, StdioMCPServerdiff --git a/tests/client/test_slim_package_boundaries.py b/tests/client/test_slim_package_boundaries.pyindex 187bf177a..c0167f37a 100644--- a/tests/client/test_slim_package_boundaries.py+++ b/tests/client/test_slim_package_boundaries.py@@ -72,8 +72,9 @@ def test_bare_slim_import_needs_only_mcp_types() -> None:while the full `mcp` package lives in the `[mcp]` extra pulled by`[client]`/`[server]`. With `mcp` absent but `mcp-types` present, `importfastmcp`, `import fastmcp.settings`, and `import fastmcp.types` must all- succeed, while `fastmcp.FastMCP` and `fastmcp.Client` raise the friendly- install-hint ImportError (they need `mcp.*` from the server/client extras).+ succeed, while `fastmcp.FastMCP`, `fastmcp.Client`, and+ `fastmcp.ClientGroup` raise the friendly install-hint ImportError (they need+ `mcp.*` from the server/client extras)."""script = textwrap.dedent("""@@ -97,7 +98,7 @@ def test_bare_slim_import_needs_only_mcp_types() -> None:assert "mcp_types" in sys.modules, "mcp_types should load on a bare install"assert "mcp" not in sys.modules, "full mcp must not load on a bare install"- for attr in ("FastMCP", "Client"):+ for attr in ("FastMCP", "Client", "ClientGroup"):try:getattr(fastmcp, attr)except ImportError: