get_user_view
Capture and return the current Blender viewport as an image, focusing on the 3D viewport to show what the user sees. Supports custom dimensions and compression quality for the output image.
Instructions
Capture and return the current Blender viewport as an image.
Shows what the user is currently seeing in Blender.
Focus mostly on the 3D viewport. Use the UI to assist in your understanding of the scene but only refer to it if specifically prompted.
Args:
max_dimension: Maximum dimension (width or height) in pixels for the returned image
compression_quality: Image compression quality (1-100, higher is better quality but larger)
Returns:
An image of the current Blender viewport
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools.py:528-612 (handler)The core handler function for the 'get_user_view' tool. It connects to Blender, requests the current viewport screenshot via 'get_current_view' command, decodes the base64 image data, optionally resizes and compresses it using PIL for efficiency, and returns it as an MCP Image object. This captures exactly what the user sees in the Blender 3D viewport.@mcp.tool() def get_user_view() -> Image: """ Capture and return the current Blender viewport as an image. Shows what the user is currently seeing in Blender. Focus mostly on the 3D viewport. Use the UI to assist in your understanding of the scene but only refer to it if specifically prompted. Args: max_dimension: Maximum dimension (width or height) in pixels for the returned image compression_quality: Image compression quality (1-100, higher is better quality but larger) Returns: An image of the current Blender viewport """ max_dimension = 800 compression_quality = 85 # Use PIL to compress the image from PIL import Image as PILImage import io try: # Get the global connection blender = get_blender_connection() # Request current view result = blender.send_command("get_current_view") if "error" in result: # logger.error(f"Error getting view from Blender: {result.get('error')}") raise Exception(f"Error getting current view: {result.get('error')}") # Extract image information if "data" not in result or "width" not in result or "height" not in result: # logger.error("Incomplete image data returned from Blender") raise Exception("Incomplete image data returned from Blender") # Decode the base64 image data image_data = base64.b64decode(result["data"]) original_width = result["width"] original_height = result["height"] original_format = result.get("format", "png") # Compression is only needed if the image is large if original_width > 800 or original_height > 800 or len(image_data) > 1000000: # logger.info(f"Compressing image (original size: {len(image_data)} bytes)") # Open image from binary data img = PILImage.open(io.BytesIO(image_data)) # Resize if needed if original_width > max_dimension or original_height > max_dimension: # Calculate new dimensions maintaining aspect ratio if original_width > original_height: new_width = max_dimension new_height = int(original_height * (max_dimension / original_width)) else: new_height = max_dimension new_width = int(original_width * (max_dimension / original_height)) # Resize using high-quality resampling img = img.resize((new_width, new_height), PILImage.Resampling.LANCZOS) # Convert to RGB if needed if img.mode == 'RGBA': img = img.convert('RGB') # Save as JPEG with compression output = io.BytesIO() img.save(output, format='JPEG', quality=compression_quality, optimize=True) compressed_data = output.getvalue() # logger.info(f"Image compressed from {len(image_data)} to {len(compressed_data)} bytes") # Return compressed image return Image(data=compressed_data, format="jpeg") else: # Image is small enough, return as-is return Image(data=image_data, format=original_format) except Exception as e: # logger.error(f"Error processing viewport image: {str(e)}") raise Exception(f"Error processing viewport image: {str(e)}")