|
4 | 4 |
|
5 | 5 | from __future__ import annotations |
6 | 6 |
|
| 7 | +import warnings |
7 | 8 | from collections.abc import AsyncGenerator |
8 | 9 | from contextlib import asynccontextmanager |
9 | 10 | from typing import Any |
@@ -57,10 +58,30 @@ async def create_connected_server_and_client_session( |
57 | 58 | raise_exceptions: bool = False, |
58 | 59 | elicitation_callback: ElicitationFnT | None = None, |
59 | 60 | ) -> 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 | + ) |
61 | 84 |
|
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. |
64 | 85 | if isinstance(server, FastMCP): # pragma: no cover |
65 | 86 | server = server._mcp_server # type: ignore[reportPrivateUsage] |
66 | 87 |
|
|
0 commit comments