async def app_lifespan(server: FastMCP) -> AsyncIterator[None]:
    """
    Context manager for the MCP server lifetime.
    """
    task = asyncio.create_task(periodic_updates())
    try:
        yield
    finally:
        task.cancel()
        try:
            await task
        except asyncio.CancelledError:
            pass

    Context manager for the MCP server lifetime.
    
llama-index-integrations/tools/llama-index-tools-mcp/tests/server.py