33import pytest
44from pydantic import AnyUrl
55
6+ from mcp import Client
67from mcp .server .fastmcp import FastMCP
78from mcp .server .fastmcp .resources import FunctionResource
8- from mcp .shared .memory import create_connected_server_and_client_session
99from mcp .shared .metadata_utils import get_display_name
1010from 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