Skip to main content
Glama

android-screenshot

Capture screenshots from Android devices for debugging, testing, or documentation purposes. Specify device serial and image quality to retrieve visual device state.

Instructions

Get a screenshot from a device.

Args: serial: Device serial number ctx: MCP context quality: JPEG quality (1-100, lower means smaller file size)

Returns: The device screenshot as an image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYes
qualityNo

Implementation Reference

  • The handler function for the 'android-screenshot' MCP tool. It captures a screenshot from the specified Android device using the device manager, validates the data, converts PNG to JPEG for compression (with configurable quality), logs the process, and returns the image via MCP Image object. Handles errors and test data gracefully.
    @mcp.tool(name="android-screenshot")
    async def screenshot(serial: str, ctx: Context, quality: int = 75) -> Image:
        """
        Get a screenshot from a device.
    
        Args:
            serial: Device serial number
            ctx: MCP context
            quality: JPEG quality (1-100, lower means smaller file size)
    
        Returns:
            The device screenshot as an image
        """
        try:
            # Get the device
            device = await get_device_manager().get_device(serial)
            if not device:
                await ctx.error(f"Device {serial} not connected or not found.")
                return Image(data=b"", format="png")
    
            # Take a screenshot using the Device abstraction
            await ctx.info(f"Capturing screenshot from device {serial}...")
            screenshot_data = await device.take_screenshot()
    
            # Check if we're in a test environment (FAKE_SCREENSHOT_DATA is a marker used in tests)
            if screenshot_data == b"FAKE_SCREENSHOT_DATA":
                await ctx.info("Using test screenshot data")
                return Image(data=screenshot_data, format="png")
    
            # Validate we have real image data to convert
            if not screenshot_data or len(screenshot_data) < 100:  # A real PNG should be larger than this
                await ctx.error("Invalid or empty screenshot data received")
                return Image(data=screenshot_data, format="png")
    
            try:
                # Convert PNG to JPEG to reduce size
                await ctx.info(f"Converting screenshot to JPEG (quality: {quality})...")
                buffer = io.BytesIO()
    
                # Load the PNG data into a PIL Image
                with PILImage.open(io.BytesIO(screenshot_data)) as img:
                    # Convert to RGB (removing alpha channel if present) and save as JPEG
                    converted_img = img.convert("RGB") if img.mode == "RGBA" else img
                    converted_img.save(buffer, format="JPEG", quality=quality, optimize=True)
                    jpeg_data = buffer.getvalue()
    
                # Get size reduction info for logging
                png_size = len(screenshot_data) / 1024
                jpg_size = len(jpeg_data) / 1024
                reduction = 100 - (jpg_size / png_size * 100) if png_size > 0 else 0
    
                await ctx.info(
                    f"Screenshot converted successfully: {png_size:.1f}KB → {jpg_size:.1f}KB ({reduction:.1f}% reduction)"
                )
                return Image(data=jpeg_data, format="jpeg")
            except UnidentifiedImageError:
                # If we can't parse the image data, return it as-is
                logger.warning("Could not identify image data, returning unprocessed")
                return Image(data=screenshot_data, format="png")
        except Exception as e:
            logger.exception("Error capturing screenshot: %s", e)
            await ctx.error(f"Error capturing screenshot: {e!s}")
            return Image(data=b"", format="png")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get a screenshot' implies a read operation, it doesn't specify permissions needed, whether this requires device unlocking, potential performance impact, or error conditions. The description mentions the return format but not response time, file size implications, or connectivity requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by Args and Returns sections. Each sentence earns its place by providing essential information. However, the 'ctx: MCP context' parameter mention in Args is unnecessary since it's not in the actual input schema, creating minor waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 2-parameter tool with no annotations and no output schema, the description provides basic coverage but has significant gaps. It explains what the tool does and parameter meanings, but lacks usage context, behavioral details, and comprehensive parameter guidance. The return statement is helpful but doesn't specify image format details or potential errors.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides basic semantic meaning for both parameters: 'serial' as 'Device serial number' and 'quality' as 'JPEG quality (1-100, lower means smaller file size)'. This adds value beyond the bare schema, but doesn't explain serial number format, how to obtain it, or quality tradeoffs beyond file size.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with 'Get a screenshot from a device' - a specific verb (Get) and resource (screenshot). It distinguishes from siblings like android-file or android-log by focusing on visual capture rather than file operations or logging. However, it doesn't explicitly differentiate from potential visual siblings like android-ui.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like android-device, android-ui, and android-shell that might offer related functionality, there's no indication of when screenshot capture is appropriate versus other device interaction methods. No prerequisites or exclusions are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/hyperb1iss/droidmind'

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