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
| Name | Required | Description | Default |
|---|---|---|---|
| output_path | Yes |
Implementation Reference
- src/espresso_mcp/server.py:178-200 (handler)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}'."