MCP Client Provider Open and Recovery

MCP Client Provider Open and Recovery A sequence diagram generated by Archify. enter server lifespan start() without await ensure_future(_open) yield; initialize can finish invoke tool get() await asyncio.shield(task) Cancellation of one waiter leaves the shared open running. await __aenter__ NotebookLMClient or error cached client or real error next get() retries failure aclose(exception triple) cancel open / await __aexit__ Background warm-up Shielded first use Retry and teardown MCP Host · initialize / tools · Sequence participant MCP Host initialize / tools FastMCP Lifespan · process owner · Sequence participant FastMCP Lifespan process owner Tool Handler · first real use · Sequence participant Tool Handler first real use ClientProvider · single-flight owner · Sequence participant ClientProvider single-flight owner Open Task · shared asyncio task · Sequence participant Open Task shared asyncio task Client Factory · async context manager · Sequence participant Client Factory async context manager Legend request return security async trace default message

Handshake Decoupling

  • • ClientProvider.start warms while initialize returns

One Shared Open

  • • _ensure_open_task plus asyncio.shield share one open

Owned Teardown

  • • aclose cancels warm-up, then exits the owned context