take_screenshot
Capture screenshots from connected Android devices. Save images to a specified output path using the designated tool on the espresso-mcp server.
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 main handler function for the 'take_screenshot' tool. It uses adb to capture a screenshot on the Android device, pulls it locally, resizes it using PIL, saves to output_path, and returns a success message. The @mcp.tool() decorator also handles registration and schema inference from the function signature.@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}'."