Skip to main content
Glama

android_capture_frame_scrcpy

Capture a single Android device screen frame using scrcpy for faster performance than ADB screencap, saving locally or returning base64 encoded image.

Instructions

Capture a single frame via scrcpy (faster than ADB screencap)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathNoLocal path to save the frame (optional). If not provided, returns base64 encoded image.
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • Handler function that executes the android_capture_frame_scrcpy tool logic: processes input arguments, calls ADB wrapper's captureFrameScrcpy method, and returns the frame as base64 image or file path.
    export async function handleCaptureFrameScrcpy(adb: ADBWrapper, args: CaptureFrameScrcpyArgs): Promise<{ content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> }> {
      const { outputPath, deviceSerial } = args;
    
      try {
        const result = await adb.captureFrameScrcpy(outputPath, deviceSerial);
    
        if (typeof result === 'string') {
          return {
            content: [
              {
                type: 'text',
                text: `Frame saved to: ${result}`,
              },
            ],
          };
        } else {
          // Return as base64-encoded image
          return {
            content: [
              {
                type: 'image',
                data: result.toString('base64'),
                mimeType: 'image/png',
              },
            ],
          };
        }
      } catch (error) {
        throw new Error(`Failed to capture frame with scrcpy: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core helper method in ADBWrapper that spawns scrcpy process for single frame capture (optimized, faster than ADB screencap), handles output as file or buffer, with fallback to screenshot.
    async captureFrameScrcpy(outputPath?: string, deviceSerial?: string): Promise<string | Buffer> {
      const device = await this.getTargetDevice(deviceSerial);
    
      // Ensure scrcpy is available
      if (!this.scrcpyInitialized) {
        try {
          await this.downloadScrcpy();
        } catch (err) {
          console.warn('Scrcpy not available, falling back to ADB screencap');
          return this.screenshot(outputPath, deviceSerial);
        }
      }
    
      return new Promise((resolve, reject) => {
        try {
          const tempPath = outputPath || join(tmpdir(), `scrcpy_frame_${Date.now()}.png`);
          
          // Use scrcpy to dump one frame directly
          const process = spawn(this.scrcpyPath, [
            '--serial', device,
            '--no-display',
            '--max-fps=1',           // Single frame
            '--video-codec=h264',
            '--video-bit-rate=2M',
            // Frame dump to raw output
          ], {
            stdio: ['ignore', 'pipe', 'pipe'],
            timeout: 5000,
          });
    
          let frameBuffer = Buffer.alloc(0);
          
          process.stdout.on('data', (chunk: Buffer) => {
            frameBuffer = Buffer.concat([frameBuffer, chunk]);
          });
    
          process.on('close', async (code) => {
            if (code !== 0) {
              // Fall back to screenshot
              return this.screenshot(outputPath, deviceSerial)
                .then(resolve)
                .catch(reject);
            }
    
            if (outputPath) {
              await writeFile(outputPath, frameBuffer);
              resolve(outputPath);
            } else {
              resolve(frameBuffer);
            }
          });
    
          process.on('error', (err) => {
            // Fall back to standard screenshot
            this.screenshot(outputPath, deviceSerial)
              .then(resolve)
              .catch(reject);
          });
        } catch (err) {
          // Fall back to standard screenshot
          this.screenshot(outputPath, deviceSerial)
            .then(resolve)
            .catch(reject);
        }
      });
    }
  • Input schema definition for the android_capture_frame_scrcpy tool, including parameters for output path and device serial.
      name: 'android_capture_frame_scrcpy',
      description: 'Capture a single frame via scrcpy (faster than ADB screencap)',
      inputSchema: {
        type: 'object',
        properties: {
          outputPath: {
            type: 'string',
            description: 'Local path to save the frame (optional). If not provided, returns base64 encoded image.',
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
      },
    },
  • src/index.ts:500-501 (registration)
    Tool registration in the CallToolRequestSchema switch statement, dispatching to the handler function.
    case 'android_capture_frame_scrcpy':
      return await handleCaptureFrameScrcpy(this.adb, args as any);
  • src/index.ts:10-10 (registration)
    Import statement registering the handler function from handlers.ts.
    import { screenshotHandler, touchHandler, swipeHandler, launchAppHandler, listPackagesHandler, uiautomatorDumpHandler, uiautomatorFindHandler, uiautomatorClickHandler, uiautomatorWaitHandler, uiautomatorSetTextHandler, uiautomatorClearTextHandler, uiautomatorLongClickHandler, uiautomatorDoubleClickHandler, uiautomatorToggleCheckboxHandler, uiautomatorScrollInElementHandler, handleStartScrcpyStream, handleStopScrcpyStream, handleGetLatestFrame, handleCaptureFrameScrcpy, handleSendKeyEvent, handleInputText, handleExecuteCommand } from './handlers.js';
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 mentions 'faster than ADB screencap', which adds useful context about performance, but it doesn't disclose other behavioral traits such as whether it requires scrcpy to be running, what happens if no device is connected, or if it has any rate limits. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 front-loads the core purpose ('Capture a single frame via scrcpy') and adds a key benefit ('faster than ADB screencap'). There is no wasted text, and it's appropriately sized for the tool's complexity.

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?

Given no annotations, no output schema, and 2 parameters with full schema coverage, the description is minimal but adequate. It covers the basic purpose and a performance advantage, but for a tool that interacts with devices and saves files, it lacks details on error handling, prerequisites (e.g., scrcpy setup), or return values. It's complete enough for a simple tool but has clear gaps in context.

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 100%, so the schema already documents both parameters (outputPath and deviceSerial) with descriptions. The description adds no additional parameter information beyond what's in the schema, such as format details or examples. With high schema coverage, the baseline is 3, as the description doesn't compensate but also doesn't detract.

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: 'Capture a single frame via scrcpy' specifies the action (capture) and resource (frame), and it distinguishes from siblings by mentioning 'faster than ADB screencap', which differentiates it from android_screenshot. However, it doesn't explicitly name the sibling android_screenshot as an alternative, so it's not a perfect 5.

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

Usage Guidelines3/5

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

The description implies usage by stating 'faster than ADB screencap', suggesting this tool is preferred for speed over alternatives like android_screenshot. However, it doesn't explicitly state when to use this vs. other frame-capturing tools (e.g., android_get_latest_frame) or provide clear exclusions, so guidance is implied but not comprehensive.

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/jduartedj/android-mcp-server'

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