Skip to main content
Glama

capture_full_screen

Take a screenshot of your entire screen and save it as an image file for documentation or sharing purposes.

Instructions

Capture screenshot of the entire screen.

Args:
    output_path: Optional path to save the screenshot

Returns:
    JSON string with capture results and file path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_pathNo

Implementation Reference

  • Primary MCP tool handler and registration for 'capture_full_screen'. Initializes window manager and delegates capture, returns JSON results with file info.
    @mcp.tool()
    async def capture_full_screen(output_path: Optional[str] = None) -> str:
        """
        Capture screenshot of the entire screen.
        
        Args:
            output_path: Optional path to save the screenshot
        
        Returns:
            JSON string with capture results and file path.
        """
        try:
            wm = get_window_manager()
            captured_path = wm.capture_full_screen(output_path)
            
            result = {
                "status": "success",
                "output_path": captured_path,
                "file_exists": Path(captured_path).exists(),
                "file_size_mb": round(Path(captured_path).stat().st_size / (1024 * 1024), 2)
            }
            
            return json.dumps(result, indent=2)
            
        except Exception as e:
            logger.error(f"Failed to capture full screen: {e}")
            return json.dumps({
                "status": "error",
                "error": str(e),
                "output_path": output_path
            })
  • server.py:140-140 (registration)
    MCP tool registration decorator (@mcp.tool()) for capture_full_screen.
    @mcp.tool()
  • CrossPlatformWindowManager.capture_full_screen: Delegates to platform-specific manager (WindowsWindowManager or WindowCapture) or falls back to pyscreenshot.
    def capture_full_screen(self, output_path: Optional[str] = None) -> str:
        """Capture full screen screenshot."""
        if hasattr(self.manager, 'capture_full_screen'):
            return self.manager.capture_full_screen(output_path)
        else:
            # Fallback using pyscreenshot
            try:
                screenshot = ImageGrab.grab()
                
                if output_path is None:
                    timestamp = int(time.time())
                    output_path = f"screenshot_{timestamp}.png"
                
                screenshot.save(output_path)
                logger.info(f"Full screen captured: {output_path}")
                return output_path
                
            except Exception as e:
                logger.error(f"Failed to capture full screen: {e}")
                raise
  • WindowsWindowManager.capture_full_screen: Platform-specific implementation using PowerShell script to capture full screen via System.Drawing in Windows, copies back to WSL.
    def capture_full_screen(self, output_path: Optional[str] = None) -> str:
        """
        Capture full screen screenshot using PowerShell from WSL2.
        """
        if not self.powershell_available:
            raise Exception("PowerShell not available - cannot capture full screen")
        
        logger.info("Capturing full screen using PowerShell...")
        try:
            # PowerShell script to capture full screen
            ps_script = '''
            Add-Type -AssemblyName System.Windows.Forms
            Add-Type -AssemblyName System.Drawing
            
            # Get primary screen dimensions
            $primaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen
            $bounds = $primaryScreen.Bounds
            
            $width = $bounds.Width
            $height = $bounds.Height
            
            Write-Verbose "Screen dimensions: ${width}x${height}"
            
            # Capture full screen
            $bitmap = New-Object System.Drawing.Bitmap($width, $height)
            $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
            $graphics.CopyFromScreen(0, 0, 0, 0, [System.Drawing.Size]::new($width, $height))
            $graphics.Dispose()
            
            # Save to temporary file in Windows temp directory
            $tempPath = [System.IO.Path]::GetTempFileName() + ".png"
            $bitmap.Save($tempPath, [System.Drawing.Imaging.ImageFormat]::Png)
            $bitmap.Dispose()
            
            Write-Output $tempPath
            '''
            
            result = subprocess.run(
                ['powershell.exe', '-Command', ps_script],
                capture_output=True,
                text=True,
                check=True,
                timeout=30  # 30 second timeout for full screen capture
            )
            
            temp_windows_path = result.stdout.strip()
            if not temp_windows_path:
                raise Exception("PowerShell did not return temp file path")
            
            # Convert Windows path to WSL path
            wsl_temp_path = self._windows_path_to_wsl(temp_windows_path)
            
            if output_path is None:
                timestamp = int(time.time())
                output_path = f"fullscreen_{timestamp}.png"
            
            # Copy from Windows temp to desired location
            subprocess.run(['cp', wsl_temp_path, output_path], check=True)
            
            # Clean up Windows temp file
            subprocess.run(
                ['powershell.exe', '-Command', f'Remove-Item "{temp_windows_path}" -Force'],
                check=False  # Don't fail if cleanup fails
            )
            
            logger.info(f"Full screen captured: {output_path}")
            return output_path
            
        except subprocess.TimeoutExpired:
            logger.error("PowerShell full screen capture timed out after 30 seconds")
            raise Exception("Full screen capture timeout")
        except subprocess.CalledProcessError as e:
            logger.error(f"Failed to capture full screen: {e}")
            raise
        except Exception as e:
            logger.error(f"Full screen capture failed: {e}")
            raise
  • WindowCapture.capture_full_screen: Linux/X11 fallback implementation using pyscreenshot (ImageGrab.grab()).
    def capture_full_screen(self, output_path: Optional[str] = None) -> str:
        """
        Capture full screen screenshot.
        """
        try:
            screenshot = ImageGrab.grab()
            
            if output_path is None:
                timestamp = int(time.time())
                output_path = f"screenshot_{timestamp}.png"
            
            screenshot.save(output_path)
            logger.info(f"Full screen captured: {output_path}")
            return output_path
            
        except Exception as e:
            logger.error(f"Failed to capture full screen: {e}")
            raise

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/PovedaAqui/auto-snap-mcp'

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