get_viewport_screenshot
Capture a screenshot of the current Blender 3D viewport, returning it as an image with adjustable maximum size for the largest dimension using the Model Context Protocol (MCP).
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
| Name | Required | Description | Default |
|---|---|---|---|
| max_size | No |
Implementation Reference
- src/blender_mcp/server.py:270-311 (handler)The @mcp.tool()-decorated handler function that executes the get_viewport_screenshot logic: connects to Blender, commands it to save a screenshot to a temp PNG file, reads the bytes, cleans up, and returns an MCP Image object.@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)}")
- src/blender_mcp/server.py:270-270 (registration)The @mcp.tool() decorator registers get_viewport_screenshot as an MCP tool.@mcp.tool()
- src/blender_mcp/server.py:272-279 (schema)Docstring defines input parameter (max_size: int = 800) and output (Image), serving as schema for the tool.""" 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. """