Skip to content

Commit ad8b16f

Browse files
committed
Use ClassVar
1 parent 91637b1 commit ad8b16f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

python-mcp-client/source-code-final/mcp_client/mcp_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from contextlib import AsyncExitStack
3-
from typing import Any, Awaitable, Callable, Self
3+
from typing import Any, Awaitable, Callable, ClassVar, Self
44

55
from mcp import ClientSession, StdioServerParameters
66
from mcp.client.stdio import stdio_client
@@ -17,12 +17,15 @@ class MCPClient:
1717
# Call client methods here...
1818
"""
1919

20+
client_session: ClassVar[ClientSession]
21+
2022
def __init__(self, server_path: str):
2123
self.server_path = server_path
2224
self.exit_stack = AsyncExitStack()
2325

2426
async def __aenter__(self) -> Self:
25-
self.client_session = await self._connect_to_server()
27+
cls = type(self)
28+
cls.client_session = await self._connect_to_server()
2629
return self
2730

2831
async def __aexit__(self, *_) -> None:

0 commit comments

Comments
 (0)