Skip to main content
Glama

execute_blender_code

Execute Python code directly in Blender to automate 3D modeling, scene manipulation, and rendering tasks through AI-assisted control.

Instructions

Execute arbitrary Python code in Blender. Make sure to do it step-by-step by breaking it into smaller chunks.

Parameters:

  • code: The Python code to execute

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • The core handler function for the 'execute_blender_code' tool. It uses a socket connection to send the provided Python code to the Blender addon for execution and returns the result or error message.
    @telemetry_tool("execute_blender_code") @mcp.tool() def execute_blender_code(ctx: Context, code: str) -> str: """ Execute arbitrary Python code in Blender. Make sure to do it step-by-step by breaking it into smaller chunks. Parameters: - code: The Python code to execute """ try: # Get the global connection blender = get_blender_connection() result = blender.send_command("execute_code", {"code": code}) return f"Code executed successfully: {result.get('result', '')}" except Exception as e: logger.error(f"Error executing code: {str(e)}") return f"Error executing code: {str(e)}"
  • The @mcp.tool() decorator registers the execute_blender_code function as an MCP tool.
    @mcp.tool()
  • Docstring defining the tool's input parameters and description, serving as the schema.
    """ Execute arbitrary Python code in Blender. Make sure to do it step-by-step by breaking it into smaller chunks. Parameters: - code: The Python code to execute """

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

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