Skip to content

Commit 64abe69

Browse files
Migrate test_title.py to use Client and fix circular import
- Migrate tests/server/fastmcp/test_title.py to use Client.from_server() - Fix circular import by not re-exporting ClientSessionGroup from client module - Demonstrates cleaner API: no need to access ._mcp_server Github-Issue:#1728
1 parent ec5c846 commit 64abe69

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

src/mcp/client/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
from mcp.client.client import Client
44
from mcp.client.session import ClientSession
5-
from mcp.client.session_group import ClientSessionGroup
65
from mcp.client.transports.memory import create_in_memory_transport
76

87
__all__ = [
98
"Client",
109
"ClientSession",
11-
"ClientSessionGroup",
1210
"create_in_memory_transport",
1311
]

tests/server/fastmcp/test_title.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import pytest
44
from pydantic import AnyUrl
55

6+
from mcp import Client
67
from mcp.server.fastmcp import FastMCP
78
from mcp.server.fastmcp.resources import FunctionResource
8-
from mcp.shared.memory import create_connected_server_and_client_session
99
from mcp.shared.metadata_utils import get_display_name
1010
from mcp.types import Prompt, Resource, ResourceTemplate, Tool, ToolAnnotations
1111

@@ -25,8 +25,9 @@ async def test_server_name_title_description_version():
2525
assert mcp.version == "1.0"
2626

2727
# Start server and connect client
28-
async with create_connected_server_and_client_session(mcp._mcp_server) as client:
29-
init_result = await client.initialize()
28+
async with Client.from_server(mcp) as client:
29+
# Access initialization result from session
30+
init_result = await client.session.initialize()
3031
assert init_result.serverInfo.name == "TestServer"
3132
assert init_result.serverInfo.title == "Test Server Title"
3233
assert init_result.serverInfo.description == "This is a test server description."
@@ -61,9 +62,7 @@ def tool_with_both(message: str) -> str: # pragma: no cover
6162
return message
6263

6364
# Start server and connect client
64-
async with create_connected_server_and_client_session(mcp._mcp_server) as client:
65-
await client.initialize()
66-
65+
async with Client.from_server(mcp) as client:
6766
# List tools
6867
tools_result = await client.list_tools()
6968
tools = {tool.name: tool for tool in tools_result.tools}
@@ -105,9 +104,7 @@ def titled_prompt(topic: str) -> str: # pragma: no cover
105104
return f"Tell me about {topic}"
106105

107106
# Start server and connect client
108-
async with create_connected_server_and_client_session(mcp._mcp_server) as client:
109-
await client.initialize()
110-
107+
async with Client.from_server(mcp) as client:
111108
# List prompts
112109
prompts_result = await client.list_prompts()
113110
prompts = {prompt.name: prompt for prompt in prompts_result.prompts}
@@ -165,9 +162,7 @@ def titled_dynamic_resource(id: str) -> str: # pragma: no cover
165162
return f"Data for {id}"
166163

167164
# Start server and connect client
168-
async with create_connected_server_and_client_session(mcp._mcp_server) as client:
169-
await client.initialize()
170-
165+
async with Client.from_server(mcp) as client:
171166
# List resources
172167
resources_result = await client.list_resources()
173168
resources = {str(res.uri): res for res in resources_result.resources}

0 commit comments

Comments
 (0)