Skip to main content
Glama

take_screenshot

Capture a screenshot from a connected Android device and save it to a specified output path.

Instructions

Take a screenshot of the connected Android device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_pathYes

Implementation Reference

  • The handler function for the 'take_screenshot' tool. It uses adb to capture a screenshot from the Android device, pulls it locally, resizes it using PIL, saves to the output_path, and returns a confirmation message.
    @mcp.tool()
    def take_screenshot(output_path: str) -> str:
        """Take a screenshot of the connected Android device"""
    
        timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
        file = f"/sdcard/espresso-mcp_screenshot_{timestamp}.mp4"
    
        # Capture screenshot on the device
        subprocess.run(["adb", "shell", "screencap", "-p", file], check=True)
        # Pull the screenshot to the local machine
        subprocess.run(["adb", "pull", file, "screenshot.png"], check=True)
        # Remove the screenshot from the device
        subprocess.run(["adb", "shell", "rm", file], check=True)
    
        # Compress the screenshot to reduce size
        with PILImage.open("screenshot.png") as img:
            width, height = img.size
            new_width = int(width * 0.3)
            new_height = int(height * 0.3)
            resized_img = img.resize((new_width, new_height), PILImage.Resampling.LANCZOS)
            resized_img.save(output_path, "PNG", quality=85, optimize=True)
    
        return f"Screenshot saved to '{output_path}'."

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vs4vijay/espresso-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server