Skip to main content
Glama
xiaohai-uid

Blender-Mind-MCP

by xiaohai-uid
README.md
# Blender-Mind-MCP (Production AI 3D Modeling & Blender Bridge)

A production-grade Model Context Protocol (MCP) server and Blender Addon ecosystem for automated 3D modeling, procedural asset generation, shader authoring, and multimodal viewport inspection.

---

## πŸ—οΈ Prior Art & Architectural Inspiration

This project incorporates architectural lessons and benchmarks from leading GitHub Blender AI projects (such as `ahujasid/blender-mcp` and `djeada/blender-mcp-server`):

1. **Thread-Safe Main-Thread Dispatching**: Blender’s Python C-API (`bpy`) is not thread-safe. As discovered in community issue audits, executing `bpy` calls inside raw socket listener threads triggers memory corruptions and segmentation faults. Our Blender Addon uses a thread-safe `queue.Queue` coupled with `bpy.app.timers` to ensure all scene modifications execute strictly in Blender’s main render/GUI loop.
2. **Undo Step Isolation**: Every AI code execution is bracketed with `bpy.ops.ed.undo_push()`, enabling seamless `Ctrl+Z` rollbacks inside Blender.
3. **Multimodal Viewport Capture**: Uses offscreen OpenGL rendering (`bpy.ops.render.opengl`) to return Base64-encoded PNG screenshots of the 3D viewport directly to multimodal vision models.
4. **Hexagonal Architecture (Ports & Adapters)**: Decouples pure 3D geometry generation from physical drivers, supporting both Live Socket connections (`127.0.0.1:9876`), headless CLI batching (`blender -b`), and offline procedural glTF binary simulation.

---

## πŸ“¦ Project Structure

```
blender-mind-mcp/
β”œβ”€β”€ addon/
β”‚   └── blender_mcp_addon.py       # Full Blender 3.x/4.x Addon (UI Sidebar Panel, Socket Server, Viewport Capture)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                   # stdio JSON-RPC MCP Server entry point
β”‚   β”œβ”€β”€ bridge/
β”‚   β”‚   └── socket_client.ts       # Robust TCP Socket Client with reconnect & timeout handling
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   └── domain/
β”‚   β”‚       β”œβ”€β”€ types.ts           # 3D Domain Types (Scene, Mesh, Material, Modifier, Transform)
β”‚   β”‚       β”œβ”€β”€ scene.ts           # Pure in-memory 3D scene graph & polygon math
β”‚   β”‚       └── bpy_generator.ts   # Modern Blender 4.x/3.x Python code synthesizer
β”‚   β”œβ”€β”€ ports/
β”‚   β”‚   └── driver.port.ts         # BlenderDriverPort interface specification
β”‚   β”œβ”€β”€ adapters/
β”‚   β”‚   β”œβ”€β”€ live_socket.adapter.ts # Live Socket Adapter (talks to active Blender GUI)
β”‚   β”‚   β”œβ”€β”€ blender_cli.adapter.ts # Headless CLI Adapter (talks to blender.exe)
β”‚   β”‚   └── mock_geometry.adapter.ts # Offline Simulation Adapter (glTF & OBJ binary synthesis)
β”‚   └── tools/
β”‚       └── index.ts               # 10 MCP Tools registry & dispatcher
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/                      # L1: Domain math & Python code generation
β”‚   β”œβ”€β”€ contract/                  # L2: MCP tool schemas & argument contracts
β”‚   β”œβ”€β”€ integration/               # L3: Binary glTF headers & TCP Socket Bridge
β”‚   └── run_tests.ts               # Complete Truth Ladder test runner
β”œβ”€β”€ package.json
└── tsconfig.json
```

---

## πŸš€ Quick Start

### 1. Install Addon in Blender
1. Open Blender (3.6+ or 4.x).
2. Go to **Edit > Preferences > Add-ons > Install...** (or the Install from Disk arrow in 4.2+).
3. Select `addon/blender_mcp_addon.py`.
4. Enable **Development: Blender MCP Bridge**.
5. In the 3D Viewport, press `N` to open the sidebar, click the **Blender MCP** tab, and click **Start MCP Server**.

### 2. Configure MCP Client (Antigravity / Claude / Codex)
Add to your project or global MCP configuration (`.mcp.json`):

```json
{
  "mcpServers": {
    "blender": {
      "command": "node",
      "args": [
        "--disable-warning=ExperimentalWarning",
        "--experimental-strip-types",
        "C:/Users/a1691/Documents/antigravity/noble-hypatia/src/index.ts"
      ]
    }
  }
}
```

---

## πŸ› οΈ 10 Core MCP Tools

| Tool Name | Description | Key Capabilities |
| :--- | :--- | :--- |
| `blender_create_primitive` | Create procedural 3D mesh | `cube`, `sphere`, `cylinder`, `torus`, `plane`, `cone`, `monkey` |
| `blender_apply_modifier` | Attach procedural modifiers | `subsurf`, `bevel`, `boolean`, `mirror`, `array`, `solidify` |
| `blender_procedural_material` | PBR Principled BSDF shader | `base_color`, `metallic`, `roughness`, `transmission` (glass), `emission` |
| `blender_setup_lighting` | Position & tune light sources | `SUN`, `POINT`, `SPOT`, `AREA` (wattage, radius, color tint) |
| `blender_setup_camera` | Camera framing & lens | `location`, `look_at` tracking, `focal_length` in mm |
| `blender_capture_viewport` | Visual viewport snapshot | Returns Base64 PNG image directly to multimodal LLMs |
| `blender_export_asset` | 3D model baking & export | `.glb`, `.gltf`, `.obj`, `.stl`, `.fbx` |
| `blender_inspect_scene` | Topology & scene tree inspection | Hierarchical object list, polycount, vertex count, modifiers |
| `blender_execute_bpy` | Raw parameter Python execution | Sandboxed execution with stdout/stderr capture |
| `blender_health` | System diagnostics | Reports active driver, port status, and Blender build |

---

## πŸ§ͺ Truth Ladder Verification

```bash
npm test
```

Executes all 6 test suites across the 4-level Truth Ladder:
- **L1 Unit**: 100% pure domain modeling & Python code synthesizer AST checks.
- **L2 Contract**: Schema definitions and dispatch verification for all 10 tools.
- **L3 Integration**: Binary glTF v2 Header (`0x46546C67`) & OBJ structure validation.
- **L3 Integration**: Live TCP Socket Client-Server loopback test on `127.0.0.1:9899`.
- **L4 E2E**: Live stdio JSON-RPC pipe roundtrip.

TDQS

A3.7/5.0

Scored across 10 tools

Disambiguation5/5

Each tool targets a distinct aspect of 3D workflow: camera setup, primitive creation, modifiers, materials, lighting, viewport capture, export, scene inspection, custom scripting, and health check. There is no functional overlap that would cause an agent to misselect a tool.

Naming Consistency4/5

Almost all tools follow a consistent 'blender_verb_noun' pattern (setup_camera, create_primitive, export_asset, inspect_scene). Two exceptions exist: 'blender_procedural_material' lacks a verb, and 'blender_health' is a noun-only name, but they are still recognizable and do not break the overall pattern significantly.

Tool Count5/5

With 10 tools, the set is well-scoped for a Blender integration. It covers the essential actions for scene creation, modification, inspection, and export without overwhelming bloat. Each tool earns its place, and the count is optimal for the domain.

Completeness4/5

The tool set covers the full modeling workflow: creating primitives, applying modifiers, materials, lighting, camera, viewport capture, export, and scene inspection. Minor gaps exist, such as direct editing of transforms or deletion of objects, but these can be managed via the custom `blender_execute_bpy` tool, so the surface is largely complete for typical tasks.

Maintenance

ActivityMaintained
ResponsivenessResponsive