execute_blender_code
Execute Python code in Blender by breaking it into smaller steps to automate 3D modeling, scene creation, and manipulation tasks directly within the Blender environment.
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:313-328 (handler)The core handler function decorated with @mcp.tool(), which registers and implements the execute_blender_code tool. It receives Python code, sends it to the Blender addon via socket connection for execution, and returns the result or error message. The docstring provides the input schema description.@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)}"