Reset session after closing

This commit is contained in:
Jeremiah Lowin 2025-05-28 22:02:03 -04:00
commit 975f151a9b
2 changed files with 5 additions and 5 deletions

View file

@ -268,6 +268,8 @@ class Client(Generic[ClientTransportT]):
async def close(self):
await self.transport.close()
self._session = None
self._initialize_result = None
# --- MCP Client Methods ---

View file

@ -121,9 +121,7 @@ class TestKeepAlive:
client = Client(transport=PythonStdioTransport(script_path=stdio_script))
assert client.transport.keep_alive is True
with pytest.raises(
RuntimeError, match="Server session was closed unexpectedly"
):
async with client:
await client.close()
async with client:
await client.close()
with pytest.raises(RuntimeError, match="Client is not connected"):
await client.call_tool("pid")