From 97bccb9104746f0db1019d24ecb9235bad09321d Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Wed, 28 May 2025 21:58:43 -0400 Subject: [PATCH] Update client.mdx --- docs/clients/client.mdx | 45 ++++++----------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/docs/clients/client.mdx b/docs/clients/client.mdx index 74ee9e3b4..504993fa4 100644 --- a/docs/clients/client.mdx +++ b/docs/clients/client.mdx @@ -286,55 +286,22 @@ When using stdio transports, clients support a `keep_alive` feature (enabled by When `keep_alive=False`, the client will automatically close the session when the context manager exits. - -```python keep_alive=True +```python from fastmcp import Client -# Client with keep_alive=True (default) -client = Client("my_mcp_server.py") +client = Client("my_mcp_server.py") # keep_alive=True by default async def example(): - # First session - async with client: - await client.ping() - - # Second session - uses the same subprocess - async with client: - await client.ping() - - # Manually close the session - await client.close() - - # Third session - will start a new subprocess - async with client: - await client.ping() - -asyncio.run(example()) -``` -```python keep_alive=False -from fastmcp import Client - -# Client with keep_alive=False -client = Client("my_mcp_server.py", keep_alive=False) - -async def example(): - # First session async with client: await client.ping() - # Second session - will start a new subprocess async with client: - await client.ping() - - # Third session - will start a new subprocess - async with client: - await client.ping() - -asyncio.run(example()) + await client.ping() # Same subprocess as above ``` - - + +For detailed examples and configuration options, see [Session Management in Transports](/clients/transports#session-management). + #### Timeouts