Skip to main content
Glama
Eminemminem

BlenderMCP

by Eminemminem

get_viewport_screenshot

Capture screenshots from Blender's 3D viewport to document progress, share visual feedback, or create reference images for 3D modeling workflows.

Instructions

Capture a screenshot of the current Blender 3D viewport.

Parameters:

  • max_size: Maximum size in pixels for the largest dimension (default: 800)

Returns the screenshot as an Image.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_sizeNo

Implementation Reference

  • The primary handler for the 'get_viewport_screenshot' tool. It uses the @mcp.tool() decorator for automatic registration in FastMCP. The function sends a command to the Blender addon via socket to capture the viewport screenshot, saves it to a temporary PNG file, reads the bytes, cleans up the file, and returns an MCP Image object. The input schema is defined by the function signature (ctx: Context, max_size: int = 800) and docstring.
    @mcp.tool()
    def get_viewport_screenshot(ctx: Context, max_size: int = 800) -> Image:
        """
        Capture a screenshot of the current Blender 3D viewport.
        
        Parameters:
        - max_size: Maximum size in pixels for the largest dimension (default: 800)
        
        Returns the screenshot as an Image.
        """
        try:
            blender = get_blender_connection()
            
            # Create temp file path
            temp_dir = tempfile.gettempdir()
            temp_path = os.path.join(temp_dir, f"blender_screenshot_{os.getpid()}.png")
            
            result = blender.send_command("get_viewport_screenshot", {
                "max_size": max_size,
                "filepath": temp_path,
                "format": "png"
            })
            
            if "error" in result:
                raise Exception(result["error"])
            
            if not os.path.exists(temp_path):
                raise Exception("Screenshot file was not created")
            
            # Read the file
            with open(temp_path, 'rb') as f:
                image_bytes = f.read()
            
            # Delete the temp file
            os.remove(temp_path)
            
            return Image(data=image_bytes, format="png")
            
        except Exception as e:
            logger.error(f"Error capturing screenshot: {str(e)}")
            raise Exception(f"Screenshot failed: {str(e)}")

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/Eminemminem/blender-mcp'

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