INNER CODE UNIT · Python
lifespan
kubernetes-sigs/agent-sandbox · clients/integrations/mcp-server/k8s_agent_sandbox_mcp_server/server.py:50
async def lifespan(server: FastMCP):
client = AsyncSandboxClient(
connection_config=settings.connection,
cleanup=False,
)
# The yielded mapping reaches tools via ctx.lifespan_context but is not
# published on the ASGI app, so probe routes cannot read it. Stash what
# they need on the server object, which routes reach as
# request.app.state.fastmcp_server. Before this runs, /readyz correctly
# reports "starting".
server.sandbox_client = client
server.probe_settings = settings
try:
yield {"client": client, "settings": settings}
finally:
await client.close()