Skip to main content
Glama

android_screenshot

Capture screenshots from Android devices or emulators to save locally for debugging, testing, or documentation purposes.

Instructions

Capture screenshot from Android device or emulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYesDevice serial number (use android_devices_list to get available devices)
outputPathYesLocal path where screenshot will be saved (e.g., ./screenshot.png)
optionsNo

Implementation Reference

  • Registers the 'android_screenshot' tool in the tools Map returned by createAndroidMediaTools(), including name, description, inputSchema, and handler function.
    tools.set('android_screenshot', {
      name: 'android_screenshot',
      description: 'Capture screenshot from Android device or emulator',
      inputSchema: {
        type: 'object',
        properties: {
          serial: {
            type: 'string',
            description: 'Device serial number (use android_devices_list to get available devices)'
          },
          outputPath: {
            type: 'string',
            description: 'Local path where screenshot will be saved (e.g., ./screenshot.png)'
          },
          options: {
            type: 'object',
            properties: {
              format: {
                type: 'string',
                enum: ['png', 'raw'],
                description: 'Screenshot format',
                default: 'png'
              },
              display: {
                type: 'number',
                description: 'Display ID for multi-display devices'
              }
            }
          }
        },
        required: ['serial', 'outputPath']
      },
      handler: async (args: any) => {
        const parsed = AndroidScreenshotSchema.parse(args);
        
        try {
          // Ensure output directory exists
          const outputDir = path.dirname(parsed.outputPath);
          await fs.mkdir(outputDir, { recursive: true });
          
          const adbArgs = ['-s', parsed.serial, 'exec-out', 'screencap'];
          
          if (parsed.options?.format === 'png') {
            adbArgs.push('-p'); // PNG format
          }
          
          if (parsed.options?.display !== undefined) {
            adbArgs.push('-d', parsed.options.display.toString());
          }
          
          // Capture screenshot to temporary location first
          const tempPath = `/sdcard/screenshot_${Date.now()}.png`;
          const captureResult = await processExecutor.execute('adb', [
            '-s', parsed.serial, 'shell', 'screencap', '-p', tempPath
          ], {
            timeout: 30000,
          });
          
          if (captureResult.exitCode !== 0) {
            return {
              success: false,
              error: {
                code: 'SCREENSHOT_CAPTURE_FAILED',
                message: 'Failed to capture screenshot on device',
                details: captureResult.stderr
              }
            };
          }
          
          // Pull screenshot to local machine
          const pullResult = await processExecutor.execute('adb', [
            '-s', parsed.serial, 'pull', tempPath, parsed.outputPath
          ], {
            timeout: 30000,
          });
          
          // Clean up temporary file
          await processExecutor.execute('adb', [
            '-s', parsed.serial, 'shell', 'rm', tempPath
          ], {
            timeout: 10000,
          });
          
          if (pullResult.exitCode === 0) {
            // Verify file was created
            let fileStats;
            try {
              fileStats = await fs.stat(parsed.outputPath);
            } catch {
              throw new Error(`Screenshot file was not created at ${parsed.outputPath}`);
            }
            
            return {
              success: true,
              data: {
                screenshotPath: parsed.outputPath,
                fileSize: fileStats.size,
                format: parsed.options?.format || 'png',
                device: parsed.serial,
                timestamp: new Date().toISOString()
              }
            };
          } else {
            return {
              success: false,
              error: {
                code: 'SCREENSHOT_PULL_FAILED',
                message: 'Failed to pull screenshot from device',
                details: pullResult.stderr
              }
            };
          }
          
        } catch (error: any) {
          return {
            success: false,
            error: {
              code: 'SCREENSHOT_ERROR',
              message: error.message,
              details: error
            }
          };
        }
      }
    });
  • Executes the screenshot capture: validates input with Zod schema, creates output directory, uses ADB to capture to /sdcard temp file, pulls to local outputPath, cleans up temp, handles various errors and returns structured success/error response.
    handler: async (args: any) => {
      const parsed = AndroidScreenshotSchema.parse(args);
      
      try {
        // Ensure output directory exists
        const outputDir = path.dirname(parsed.outputPath);
        await fs.mkdir(outputDir, { recursive: true });
        
        const adbArgs = ['-s', parsed.serial, 'exec-out', 'screencap'];
        
        if (parsed.options?.format === 'png') {
          adbArgs.push('-p'); // PNG format
        }
        
        if (parsed.options?.display !== undefined) {
          adbArgs.push('-d', parsed.options.display.toString());
        }
        
        // Capture screenshot to temporary location first
        const tempPath = `/sdcard/screenshot_${Date.now()}.png`;
        const captureResult = await processExecutor.execute('adb', [
          '-s', parsed.serial, 'shell', 'screencap', '-p', tempPath
        ], {
          timeout: 30000,
        });
        
        if (captureResult.exitCode !== 0) {
          return {
            success: false,
            error: {
              code: 'SCREENSHOT_CAPTURE_FAILED',
              message: 'Failed to capture screenshot on device',
              details: captureResult.stderr
            }
          };
        }
        
        // Pull screenshot to local machine
        const pullResult = await processExecutor.execute('adb', [
          '-s', parsed.serial, 'pull', tempPath, parsed.outputPath
        ], {
          timeout: 30000,
        });
        
        // Clean up temporary file
        await processExecutor.execute('adb', [
          '-s', parsed.serial, 'shell', 'rm', tempPath
        ], {
          timeout: 10000,
        });
        
        if (pullResult.exitCode === 0) {
          // Verify file was created
          let fileStats;
          try {
            fileStats = await fs.stat(parsed.outputPath);
          } catch {
            throw new Error(`Screenshot file was not created at ${parsed.outputPath}`);
          }
          
          return {
            success: true,
            data: {
              screenshotPath: parsed.outputPath,
              fileSize: fileStats.size,
              format: parsed.options?.format || 'png',
              device: parsed.serial,
              timestamp: new Date().toISOString()
            }
          };
        } else {
          return {
            success: false,
            error: {
              code: 'SCREENSHOT_PULL_FAILED',
              message: 'Failed to pull screenshot from device',
              details: pullResult.stderr
            }
          };
        }
        
      } catch (error: any) {
        return {
          success: false,
          error: {
            code: 'SCREENSHOT_ERROR',
            message: error.message,
            details: error
          }
        };
      }
    }
  • JSON Schema definition for the tool input parameters: serial (required string), outputPath (required string), optional options object with format (png/raw) and display (number).
    inputSchema: {
      type: 'object',
      properties: {
        serial: {
          type: 'string',
          description: 'Device serial number (use android_devices_list to get available devices)'
        },
        outputPath: {
          type: 'string',
          description: 'Local path where screenshot will be saved (e.g., ./screenshot.png)'
        },
        options: {
          type: 'object',
          properties: {
            format: {
              type: 'string',
              enum: ['png', 'raw'],
              description: 'Screenshot format',
              default: 'png'
            },
            display: {
              type: 'number',
              description: 'Display ID for multi-display devices'
            }
          }
        }
      },
      required: ['serial', 'outputPath']
    },
  • Internal Zod validation schema used within the handler to parse and validate input arguments before execution.
    const AndroidScreenshotSchema = z.object({
      serial: z.string().min(1),
      outputPath: z.string().min(1),
      options: z.object({
        format: z.enum(['png', 'raw']).default('png'),
        display: z.number().optional(),
      }).optional(),
    });
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the action ('Capture screenshot') but lacks details on behavioral traits: it doesn't specify if this requires device permissions, whether it's a blocking operation, potential errors (e.g., device not found), or what happens on success (e.g., file saved locally). For a tool with no annotations, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and appropriately sized, with every word contributing to understanding the core function.

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

Completeness2/5

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

Given no annotations, no output schema, and a tool that performs an action (screenshot capture) with potential side effects, the description is incomplete. It lacks details on prerequisites, error handling, output behavior (e.g., file saved confirmation), and doesn't compensate for the missing structured data, making it inadequate for safe and effective use.

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 67%, with parameters like 'serial' and 'outputPath' well-documented in the schema. The description adds no parameter-specific semantics beyond implying screenshot capture. It doesn't explain the 'options' object or provide context beyond what the schema offers, so it meets the baseline for moderate schema coverage.

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 action ('Capture screenshot') and target ('from Android device or emulator'), which is specific and unambiguous. It distinguishes from iOS screenshot tools (like ios_take_screenshot) but doesn't explicitly differentiate from other Android tools like android_list_devices or android_logcat, though the purpose is distinct by nature.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites (e.g., device must be connected or emulator running), nor does it compare to similar tools like ios_take_screenshot or other Android utilities. Usage is implied by the tool name and purpose alone.

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/cristianoaredes/mcp-mobile-server'

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