def generate_image(width: int = 100, height: int = 100, color: str = "random") -> Image:
    """Generate an image to test image return values."""
    # Create a random color image
    if color == "random":
        img_array = np.random.randint(0, 255, (height, width, 3), dtype=np.uint8)
    elif color == "red":
        img_array = np.zeros((height, width, 3), dtype=np.uint8)
        img_array[:, :, 0] = 255
    elif color == "green":
        img_array = np.zeros((height, width, 3), dtype=np.uint8)
        img_array[:, :, 1] = 255
    elif color == "blue":
        img_array = np.zeros((height, width, 3), dtype=np.uint8)
        img_array[:, :, 2] = 255
    else:
        img_array = np.zeros((height, width, 3), dtype=np.uint8)

    # Convert numpy array to PIL Image
    pil_img = PILImage.fromarray(img_array)

    # Save to bytes
    img_byte_arr = io.BytesIO()
    pil_img.save(img_byte_arr, format="PNG")
    img_byte_arr = img_byte_arr.getvalue()

    return Image(data=img_byte_arr, format="png")
Generate an image to test image return values.
llama-index-integrations/tools/llama-index-tools-mcp/tests/server.py