Skip to content

Commit ec5c846

Browse files
Add exports and deprecation warning
- Export Client from mcp and mcp.client modules - Add deprecation warning to create_connected_server_and_client_session - Document migration path in docstring Github-Issue:#1728
1 parent 8aac6b3 commit ec5c846

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/mcp/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .client.client import Client
12
from .client.session import ClientSession
23
from .client.session_group import ClientSessionGroup
34
from .client.stdio import StdioServerParameters, stdio_client
@@ -66,6 +67,7 @@
6667

6768
__all__ = [
6869
"CallToolRequest",
70+
"Client",
6971
"ClientCapabilities",
7072
"ClientNotification",
7173
"ClientRequest",

src/mcp/client/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""MCP Client module."""
2+
3+
from mcp.client.client import Client
4+
from mcp.client.session import ClientSession
5+
from mcp.client.session_group import ClientSessionGroup
6+
from mcp.client.transports.memory import create_in_memory_transport
7+
8+
__all__ = [
9+
"Client",
10+
"ClientSession",
11+
"ClientSessionGroup",
12+
"create_in_memory_transport",
13+
]

src/mcp/shared/memory.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import warnings
78
from collections.abc import AsyncGenerator
89
from contextlib import asynccontextmanager
910
from typing import Any
@@ -57,10 +58,30 @@ async def create_connected_server_and_client_session(
5758
raise_exceptions: bool = False,
5859
elicitation_callback: ElicitationFnT | None = None,
5960
) -> AsyncGenerator[ClientSession, None]:
60-
"""Creates a ClientSession that is connected to a running MCP server."""
61+
"""Creates a ClientSession that is connected to a running MCP server.
62+
63+
.. deprecated::
64+
Use :class:`mcp.client.Client` with :meth:`Client.from_server` instead.
65+
This function will be removed in a future version.
66+
67+
Example migration::
68+
69+
# Before
70+
async with create_connected_server_and_client_session(server) as session:
71+
result = await session.call_tool("my_tool", {...})
72+
73+
# After
74+
from mcp import Client
75+
async with Client.from_server(server) as client:
76+
result = await client.call_tool("my_tool", {...})
77+
"""
78+
warnings.warn(
79+
"create_connected_server_and_client_session is deprecated. "
80+
"Use Client.from_server(server) instead.",
81+
DeprecationWarning,
82+
stacklevel=2,
83+
)
6184

62-
# TODO(Marcelo): we should have a proper `Client` that can use this "in-memory transport",
63-
# and we should expose a method in the `FastMCP` so we don't access a private attribute.
6485
if isinstance(server, FastMCP): # pragma: no cover
6586
server = server._mcp_server # type: ignore[reportPrivateUsage]
6687

0 commit comments

Comments
 (0)