Skip to content

Commit bef37ce

Browse files
committed
add options to client server connection
1 parent ff86ee7 commit bef37ce

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

mcp_python/server/memory.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async def create_client_server_memory_streams() -> AsyncGenerator[
5252
@asynccontextmanager
5353
async def create_connected_server_and_client_session(
5454
server: Server,
55+
read_timeout_seconds: int | float | None = None,
56+
raise_exceptions: bool = False,
5557
) -> AsyncGenerator[ClientSession, None]:
5658
"""Creates a ServerSession that is connected to the `server`."""
5759
async with create_client_server_memory_streams() as (
@@ -64,18 +66,21 @@ async def create_connected_server_and_client_session(
6466
# Create a cancel scope for the server task
6567
async with anyio.create_task_group() as tg:
6668
tg.start_soon(
67-
server.run,
68-
server_read,
69-
server_write,
70-
server.create_initialization_options(),
69+
lambda: server.run(
70+
server_read,
71+
server_write,
72+
server.create_initialization_options(),
73+
raise_exceptions=raise_exceptions,
74+
)
7175
)
7276

7377
try:
7478
# Client session could be created here using client_read and
7579
# client_write This would allow testing the server with a client
7680
# in the same process
7781
async with ClientSession(
78-
read_stream=client_read, write_stream=client_write
82+
read_stream=client_read, write_stream=client_write,
83+
read_timeout_seconds=read_timeout_seconds,
7984
) as client_session:
8085
await client_session.initialize()
8186
yield client_session

0 commit comments

Comments
 (0)