Skip to main content
Glama

get_user_view

Capture the current Blender viewport as an image to show what the user is seeing in the 3D workspace.

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the 'get_user_view' MCP tool. It connects to Blender, requests the current viewport image via 'get_current_view' command, decodes the base64 image data, optionally resizes and compresses it using PIL for efficiency, and returns an MCP Image object.
    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)}")

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/JotaDeRodriguez/Bonsai_mcp'

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