Skip to main content
Glama
README.md
# blender-headless-mcp

An MCP server that drives **Blender as a headless external process**, exposing scene building, rigging, cameras, procedural modeling, kinetic typography and rendering as MCP tools. No Blender add-on install, no GUI: the server launches `blender -b` and talks to it over stdio.

Because Blender is only ever launched as a separate process (never linked or imported as a library), this project stays MIT-licensed while Blender remains GPL.

## What it can do

- **Scenes**: presets for 9:16 / 1:1 / 4:5 / 16:9 / 720p / 4K, fps and frame ranges, world colors
- **Modeling**: primitives, bmesh mesh operations (inset/extrude/subdivide/bevel), modifiers (subsurf, bevel, mirror, array, solidify, boolean...), curves and bevels, joins/separates
- **Geometry Nodes**: build node trees from a node-type catalog (`gn_node_types`), wire sockets, expose inputs, or one-call presets (`scatter`, `noise_displace`)
- **Rigging**: armatures from bone lists, a 20-bone humanoid rig, pose keyframing, IK chains with targets, bone constraints, automatic-weights skinning, per-vertex weights, rigid bone attachments, a walk-cycle generator
- **Cameras**: look-at / track-to constraints, keyframed moves (dolly/push-in), zoom (focal length), orbit, follow-path, multi-camera cuts via timeline markers, camera shake
- **Text**: 3D text and per-letter kinetic typography (`pop`, `rise`, `drop`, `typewriter`)
- **Materials & lights**: Principled BSDF builder, image textures, point/sun/spot/area lights, one-call three-point lighting
- **Animation**: keyframes with easing, noise modifiers, shape keys
- **Rendering**: EEVEE (needs a GPU/OpenGL), Cycles (CPU path tracing, works headless anywhere), Workbench (instant previews); stills and H.264 mp4 animation
- **Photo to 2.5D**: turn a still photo into a parallax scene (depth estimation on CPU, displaced photo mesh) and render cinematic fly-throughs - with a **safe camera envelope computed up front (prevention)** and **probe-render self-checks with automatic correction (backstop)**, so videos come out clean without a human eyeballing stills
- **Honesty hatch**: `bpy_describe` / `bpy_search` introspect the live Blender API, and `exec_python` runs arbitrary bpy code for anything the named tools don't cover

## Requirements

- Python 3.10+, `mcp` package
- A Blender 4.4+ / 5.x binary (tested on Blender 5.3.0). Point the server at it with `BLENDER_BIN=/path/to/blender` or have `blender` on `PATH`.
- `ffmpeg` only if you probe/encode outside Blender; Blender encodes mp4 itself.

## Running

```bash
pip install .
BLENDER_BIN=/path/to/blender blender-mcp   # stdio MCP server
```

Claude Desktop / MCP client config:

```json
{
  "mcpServers": {
    "blender": {
      "command": "blender-mcp",
      "env": { "BLENDER_BIN": "/path/to/blender" }
    }
  }
}
```

## Example session

```python
new_scene(preset="9:16", fps=24, frame_end=24)
render_settings(engine="CYCLES", samples=16)
humanoid_rig(name="Hero", height=1.8)
add_ik(armature="Hero", bone="hand.R", chain_length=2)
walk_cycle(armature="Hero", frames=24)
add_camera(name="Cam", location=[0, -7, 1.4], look_at=[0, 0, 1])
camera_look_at(camera="Cam", target="Hero")          # live track-to
camera_move(camera="Cam", to_location=[0, -4.5, 1.2], start_frame=1, end_frame=24)
three_point_lighting(target=[0, 0, 1])
render_animation(path="walk.mp4", frame_end=24)
```

See `examples/demo_walk.py` (rigged character + camera dolly) and `examples/demo_text.py` (Geometry Nodes scatter + kinetic typography + camera orbit) for complete runnable scenes.

## Photo to 2.5D fly-through (with built-in QA)

The pipeline turns one still photo into a cinematic parallax video. Two layers keep it artifact-free:

1. **Prevention (primary).** `photo_to_scene` returns a `camera_envelope` alongside the scene: the safe
   dolly range, lateral offsets and pan/tilt angles for this exact photo, computed from the scene geometry
   and depth budget. The mesh extends past the frame with a mirror fold (a mirrored slice of the photo's
   own edge content); a camera pose is unsafe when the fold line would cross the central band of the frame
   (visible seam, doubled geometry) or when the frustum would reach past the extended plane (hole). Plan
   camera moves inside the returned `limits` and artifacts cannot occur by construction.
2. **Self-check (backstop).** `validate_frames(frames=[...])` probe-renders any frames at half resolution
   and analyzes the pixels for mirror seams, edge exposure, smears and blank frames. `photo_flythrough`
   wraps the whole pipeline: it clamps your requested moves into the envelope, probe-renders along the
   path, pulls offending poses back and re-probes (up to `max_adjust_rounds`), renders the mp4 only when
   probes are clean, then spot-checks the encoded file. Its report (`clean`, `clamps`, `attempts`,
   `unresolved`, `mp4_spot_check`) says honestly what was fixed and what couldn't be.

### From one sentence to a video

Say the agent is asked: *"the camera slowly goes to the house, and when it arrives in front of the house
it turns around and films the scene the house faces, with professional camera effects".* The tool-call
sequence:

```python
# 1. depth (host tool; Depth Anything V2 small, CPU, ~94 MB model cached after first run)
estimate_depth(image_path="cottage.jpg", out_path="cottage_depth.png")

# 2. one call does the rest: scene build, envelope clamping, probe QA, render, spot-check
photo_flythrough(
    image_path="cottage.jpg",
    depth_path="cottage_depth.png",
    moves=[
        # slow eased approach to the house (frames 1-110)
        {"to_location": [-0.14, 0.03, 2.10], "to_rotation_deg": [0, 4, 0],
         "from_location": [0, 0.05, 2.778], "start_frame": 1, "end_frame": 110,
         "easing": "EASE_IN_OUT"},
        # smooth turn to film what the house faces (frames 110-240)
        {"to_location": [0.26, -0.02, 1.95], "to_rotation_deg": [4, -17, 0],
         "start_frame": 110, "end_frame": 240, "easing": "EASE_IN_OUT"},
    ],
    shake={"strength": 0.012, "speed": 3},   # gentle handheld float
    out="cottage_flythrough.mp4", width=540, height=960, frame_end=240,
)
```

`moves` entries have the same shape as the `camera_move` tool; locations are metres in scene space (the
photo plane is `plane_height` tall, centred at the origin, camera starts at `camera_distance` on Z),
rotations are degrees `[tilt, pan, roll]`. If a requested move leaves the safe envelope, the report's
`clamps` tells you exactly how it was pulled in. If you'd rather drive the pieces yourself:
`photo_to_scene` (returns the envelope) -> `camera_move` -> `validate_frames` -> `render_animation`.

`examples/demo_photo.py` is this exact pipeline as a runnable script (it produced the demo video in
`examples/out/`).

## Architecture

```
MCP client ──stdio──▶ server.py ──subprocess stdio──▶ blender -b -P worker.py
                     (tool schema                 (JSON-lines in, results out
                      generated from               inside Blender's Python)
                      handlers.py)
```

- `blendermcp/handlers.py` — plain Python functions running inside Blender; the single source of truth for every tool
- `blendermcp/server.py` — AST-parses `handlers.py` and generates matching MCP tools, so signatures never drift
- `blendermcp/bridge.py` — process management, auto-restart, per-call timeouts
- `blendermcp/worker.py` — the in-Blender command loop

## Development

```bash
pip install -e .[test]
BLENDER_BIN=/path/to/blender pytest tests/
```

The test suite runs real Blender: scene/modeling, geometry nodes, armature/IK/binding, cameras, still+mp4 renders (verified with ffprobe), kinetic text and introspection.

## Headless render engines

GitHub Actions (`headless-render` workflow) downloads a Blender binary on every push, runs the test suite
and renders `examples/demo_walk.py`, uploading the mp4 as a build artifact. Note: Actions runners are
CPU-only with no OpenGL GPU - EEVEE is unavailable there; use **Cycles CPU** (or Workbench for previews),
which is what the demos default to.

EEVEE requires a GPU/OpenGL context and is unavailable on most headless servers. Use CYCLES (CPU, slower but exact) or WORKBENCH (fast flat previews) when running without a display. `blender_version` reports what the connected binary supports.

TDQS

C2.7/5.0

Scored across 87 tools

Disambiguation3/5

Most tools target distinct resources (modeling, rigging, materials, rendering), but the camera and render/QA areas overlap heavily: camera_move, camera_walk, camera_follow_path, camera_orbit, camera_shake, and photo_flythrough all move a camera, while render_frame, render_animation, validate_frames, and photo_flythrough all produce or check renders. Descriptions help disambiguate, but an agent must read carefully to pick the right tool.

Naming Consistency4/5

Almost all tools use snake_case with a verb_noun pattern (add_tree, create_mesh, set_transform, apply_modifier, keyframe_pose). There are minor deviations with noun-only names (scene_info, kinetic_text, humanoid_rig, walk_cycle, blender_version) and domain prefixes (camera_, gn_, build_, photo_), but the convention remains predictable.

Tool Count2/5

87 tools is far beyond the practical range for a single server, even for a broad domain like Blender. The tools are logically grouped into modeling, animation, rigging, rendering, and photo-scene pipelines, but the sheer number makes tool selection and context management unwieldy.

Completeness4/5

The surface covers an impressive lifecycle: scene setup, modeling, materials, lighting, cameras, animation, rigging, geometry nodes, rendering, and photo-to-3D QA, with exec_python/bpy_search as an escape hatch. Minor gaps remain around material/collection management and compositing, but agents can work around them.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues