Skip to content

Commit 2ba4f2b

Browse files
committed
refactor cloud client helper to async context manager
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 7107179 commit 2ba4f2b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/basic_memory/mcp/async_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from contextlib import AbstractAsyncContextManager, asynccontextmanager
3-
from typing import AsyncGenerator, AsyncIterator, Callable, Optional
3+
from typing import AsyncIterator, Callable, Optional
44

55
from httpx import ASGITransport, AsyncClient, Timeout
66
from loguru import logger
@@ -60,11 +60,12 @@ async def _resolve_cloud_token(config) -> str:
6060
)
6161

6262

63+
@asynccontextmanager
6364
async def _cloud_client(
6465
config,
6566
timeout: Timeout,
6667
workspace: Optional[str] = None,
67-
) -> AsyncGenerator[AsyncClient, None]:
68+
) -> AsyncIterator[AsyncClient]:
6869
"""Create a cloud proxy client with resolved credentials."""
6970
token = await _resolve_cloud_token(config)
7071
proxy_base_url = f"{config.cloud_host}/proxy"
@@ -139,7 +140,7 @@ async def get_client(
139140

140141
if _force_cloud_mode():
141142
logger.info("Explicit cloud routing enabled - using cloud proxy client")
142-
async for client in _cloud_client(config, timeout, workspace=workspace):
143+
async with _cloud_client(config, timeout, workspace=workspace) as client:
143144
yield client
144145
return
145146

@@ -152,7 +153,7 @@ async def get_client(
152153
if project_mode == ProjectMode.CLOUD:
153154
logger.info(f"Project '{project_name}' is cloud mode - using cloud proxy client")
154155
try:
155-
async for client in _cloud_client(config, timeout, workspace=workspace):
156+
async with _cloud_client(config, timeout, workspace=workspace) as client:
156157
yield client
157158
except RuntimeError as exc:
158159
raise RuntimeError(

0 commit comments

Comments
 (0)