execute_blender_code
Run Python code directly in Blender to automate 3D modeling tasks, manipulate scenes, control materials, and integrate assets through step-by-step execution.
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
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- src/blender_mcp/server.py:318-334 (handler)The main handler function for the 'execute_blender_code' tool. It connects to Blender via a persistent socket connection, sends the provided Python code to Blender using the 'execute_code' command, and returns the execution result or error message.@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)}"
- src/blender_mcp/server.py:318-318 (registration)The @mcp.tool() decorator registers the execute_blender_code function as an MCP tool.@mcp.tool()
- src/blender_mcp/server.py:319-325 (schema)The function signature and docstring define the input schema (ctx: Context, code: str) and output (str).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 """