Skip to main content
Glama
mikeysrecipes

BlenderMCP

get_viewport_screenshot

Capture screenshots of the Blender 3D viewport for documentation, progress tracking, or sharing visual updates during 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 main handler function for the 'get_viewport_screenshot' tool. It connects to the Blender addon, sends the screenshot command with max_size parameter, saves to a temporary PNG file, reads the image bytes, cleans up the file, 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)}")
  • The @mcp.tool() decorator registers the get_viewport_screenshot function as an MCP tool.
    @mcp.tool()
  • The function signature and docstring define the tool's input schema (ctx: Context, max_size: int = 800) and output (Image).
    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.
        """
  • Helper function used by the tool to obtain a persistent socket connection to the Blender addon server.
    def get_blender_connection():
        """Get or create a persistent Blender connection"""
        global _blender_connection, _polyhaven_enabled  # Add _polyhaven_enabled to globals
        
        # If we have an existing connection, check if it's still valid
        if _blender_connection is not None:
            try:
                # First check if PolyHaven is enabled by sending a ping command
                result = _blender_connection.send_command("get_polyhaven_status")
                # Store the PolyHaven status globally
                _polyhaven_enabled = result.get("enabled", False)
                return _blender_connection
            except Exception as e:
                # Connection is dead, close it and create a new one
                logger.warning(f"Existing connection is no longer valid: {str(e)}")
                try:
                    _blender_connection.disconnect()
                except:
                    pass
                _blender_connection = None
        
        # Create a new connection if needed
        if _blender_connection is None:
            _blender_connection = BlenderConnection(host="localhost", port=9876)
            if not _blender_connection.connect():
                logger.error("Failed to connect to Blender")
                _blender_connection = None
                raise Exception("Could not connect to Blender. Make sure the Blender addon is running.")
            logger.info("Created new persistent connection to Blender")
        
        return _blender_connection
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Capture') and return type ('Returns the screenshot as an Image'), but lacks details on permissions needed, potential side effects (e.g., if it pauses rendering), rate limits, error conditions, or what 'Image' entails (e.g., format, size constraints beyond max_size). This is inadequate for a tool with mutation-like behavior (capturing).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose, followed by a clear parameter section and return statement. Every sentence earns its place with no redundant or verbose language, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (capturing a screenshot with one parameter), no annotations, and no output schema, the description is minimally adequate. It covers the purpose, parameter semantics, and return type, but gaps remain in behavioral details (e.g., how the image is formatted, error handling) and usage guidelines, making it incomplete for confident agent invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaningful context for the single parameter 'max_size' by explaining it as 'Maximum size in pixels for the largest dimension' and providing the default value (800), which clarifies its role beyond the schema's basic type and title. However, it doesn't detail units or constraints (e.g., minimum/maximum values).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Capture a screenshot') and target resource ('current Blender 3D viewport'), distinguishing it from all sibling tools which involve downloading assets, executing code, getting status/info, or setting textures. No tautology or vagueness is present.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. While the purpose is clear, there is no mention of prerequisites (e.g., Blender must be running), exclusions, or comparisons to other screenshot or image-related tools, leaving usage context implicit at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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