class documentation

A single MCP session held open by a dedicated owner task.

The MCP transport and ClientSession are anyio context managers whose cancel scope is bound to the task that enters them, so they must be entered and exited in the same task. _run owns that task for the connection's whole lifetime; call_tool activities on the same event loop invoke session.call_tool directly (MCP multiplexes concurrent requests by id).

Method __init__ Undocumented
Async Method aclose Signal the owner task to exit its context managers and wait for it.
Method acquire Mark a call in flight; pause idle eviction while calls are active.
Method release Mark a call done; arm idle eviction once no calls remain in flight.
Async Method session Return the live client and session, or raise the connect failure.
Async Method _maybe_evict Undocumented
Method _on_idle Undocumented
Async Method _run Undocumented
Instance Variable _idle_handle Undocumented
Instance Variable _idle_task Undocumented
Instance Variable _idle_timeout Undocumented
Instance Variable _inflight Undocumented
Instance Variable _owner Undocumented
Instance Variable _ready Undocumented
Instance Variable _server Undocumented
Instance Variable _stop Undocumented
def __init__(self, server: str, client_factory: Callable[[], MCPClient], idle_timeout: timedelta): (source)

Undocumented

async def aclose(self): (source)

Signal the owner task to exit its context managers and wait for it.

def acquire(self): (source)

Mark a call in flight; pause idle eviction while calls are active.

def release(self): (source)

Mark a call done; arm idle eviction once no calls remain in flight.

async def session(self) -> tuple[MCPClient, ClientSession]: (source)

Return the live client and session, or raise the connect failure.

async def _maybe_evict(self): (source)

Undocumented

def _on_idle(self): (source)

Undocumented

async def _run(self, client_factory: Callable[[], MCPClient]): (source)

Undocumented

Undocumented

Undocumented

_idle_timeout = (source)

Undocumented

_inflight: int = (source)

Undocumented

Undocumented

_ready: asyncio.Future[tuple[MCPClient, ClientSession]] = (source)

Undocumented

Undocumented

Undocumented