Skip to main content
Glama

record_video

Record Android device screen video using scrcpy. Save videos to designated directory with configurable resolution and bitrate settings.

Instructions

Start recording a video using scrcpy. The video will be saved to the videos directory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bitrateNo8M
device_idNo
filenameNo
resolutionNo

Implementation Reference

  • The primary handler function for the 'record_video' MCP tool. Decorated with @mcp.tool(), it registers the tool and implements the logic to start video recording of an Android device screen using scrcpy. It handles filename generation, process management, and tracks active recordings via a global dictionary.
    async def record_video(device_id: str = None, filename: str = None, resolution: str = None, bitrate: str = "8M") -> dict:
        """Start recording a video using scrcpy. The video will be saved to the videos directory."""
        try:
            # Use android-puppeteer/videos directory for video recordings
            current_dir = os.path.dirname(os.path.abspath(__file__))
            videos_dir = os.path.join(current_dir, "videos")
            os.makedirs(videos_dir, exist_ok=True)
    
            # Generate filename if not provided
            if filename:
                # Ensure it has .mp4 extension
                if not filename.endswith('.mp4'):
                    filename = f"{filename}.mp4"
            else:
                # Use timestamp if no filename provided
                timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
                filename = f"recording_{timestamp}.mp4"
    
            filepath = os.path.join(videos_dir, filename)
    
            # Create recording key for tracking
            recording_key = device_id or "default"
    
            # Check if already recording for this device
            if recording_key in active_recordings:
                return {
                    "success": False,
                    "error": f"Already recording for device {recording_key}. Stop the current recording first.",
                    "device_id": device_id or "default"
                }
    
            # Build scrcpy command for recording
            cmd = ['scrcpy']
    
            # Add device selection if specified
            if device_id:
                cmd.extend(['-s', device_id])
    
            # Add recording parameters
            cmd.extend(['--record', filepath])
    
            # Add video quality parameters
            cmd.extend(['--video-bit-rate', bitrate])
    
            if resolution:
                cmd.extend(['--max-size', resolution])
    
            # Add minimal parameters for recording
            cmd.extend([
                '--no-playback'  # Don't show the device screen (updated flag for scrcpy v3.2+)
            ])
    
            # Start the recording process
            process = subprocess.Popen(
                cmd,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                preexec_fn=os.setsid  # Create new process group for proper termination
            )
    
            # Give the process a moment to start and check if it's still running
            import time
            time.sleep(1)
    
            # Check if process started successfully
            if process.poll() is not None:
                # Process terminated immediately, capture error output
                stderr_output = process.stderr.read().decode() if process.stderr else ""
                stdout_output = process.stdout.read().decode() if process.stdout else ""
                return {
                    "success": False,
                    "error": f"scrcpy process terminated immediately. stderr: {stderr_output}, stdout: {stdout_output}",
                    "filepath": None,
                    "command": ' '.join(cmd)
                }
    
            # Store the process for later termination
            active_recordings[recording_key] = {
                "process": process,
                "filepath": filepath,
                "filename": filename,
                "start_time": datetime.now(),
                "device_id": device_id or "default"
            }
    
            return {
                "success": True,
                "message": f"Video recording started successfully",
                "filepath": filepath,
                "filename": filename,
                "device_id": device_id or "default",
                "recording_key": recording_key,
                "bitrate": bitrate,
                "resolution": resolution,
                "process_id": process.pid
            }
    
        except FileNotFoundError:
            return {
                "success": False,
                "error": "scrcpy not found. Please ensure scrcpy is installed and in PATH.",
                "filepath": None
            }
        except PermissionError:
            return {
                "success": False,
                "error": f"Permission denied: Cannot create directory or write to {videos_dir}",
                "filepath": None
            }
        except Exception as e:
            return {
                "success": False,
                "error": f"Unexpected error starting recording: {e}",
                "filepath": None
            }
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 the recording starts and where it's saved, but lacks critical behavioral details: whether it runs in background, requires specific device states, has time limits, or how errors are handled. For a tool with potential side effects, this is insufficient.

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 two concise sentences with zero waste. It front-loads the core action and efficiently states the tool and outcome. Every word contributes to understanding the purpose without redundancy.

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 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It covers the basic action but misses parameter explanations, behavioral context, and output details. For a tool that likely involves device interaction and file creation, more information is needed.

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

Parameters2/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 adds no information about the 4 parameters (bitrate, device_id, filename, resolution), such as their purposes, formats, or defaults. The baseline for low coverage is not met, as the description fails to explain parameters beyond the schema.

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 ('Start recording a video') and the tool used ('using scrcpy'), with the outcome ('saved to the videos directory'). It distinguishes from siblings like 'take_screenshot' or 'stop_video' by specifying video recording. However, it doesn't explicitly differentiate from all siblings (e.g., 'get_device_dimensions' is unrelated), 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 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. It doesn't mention prerequisites (e.g., device connection), when not to use it, or how it relates to siblings like 'stop_video' for ending recording. Usage is implied by the action but lacks explicit context.

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/pedro-rivas/android-puppeteer-mcp'

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