Skip to main content
Glama
README.md
# nuke-mcp

Drive a **live** Foundry Nuke session from Claude Code (or any MCP client).
Edits appear immediately in the open Nuke and each edit is one Ctrl+Z step.

Tested with Nuke 17.0 (Python 3.11) on Linux and the `mcp` Python SDK 2.3. The Nuke
side is standard-library Python only, so other recent Nuke versions and OSes should
work, but are untested.

Requirements: Nuke (GUI, or a licence for `nuke -t`), Python 3.10+ for the MCP
server, [uv](https://docs.astral.sh/uv/) (or pip).

```
Claude Code ──stdio/MCP──▶ nuke_mcp (src/, venv Python 3.12)
                               │  newline-delimited JSON, 127.0.0.1:49512
                               ▼
                    nuke_mcp_bridge (nuke_side/, runs inside Nuke)
                               │  executeInMainThreadWithResult / undo groups
                               ▼
                             nuke API
```

## Layout

| Path | What |
|---|---|
| `nuke_side/menu.py` | GUI startup hook: "MCP" menu (Start/Stop/Status/Reload Commands), autostarts the bridge |
| `nuke_side/headless.py` | `Nuke -t headless.py [script.nk] [--port N]`: serve without a GUI |
| `nuke_side/nuke_mcp_bridge/server.py` | socket server, main-thread dispatch, undo wrapping |
| `nuke_side/nuke_mcp_bridge/registry.py` | `@command` registry, module discovery and reload |
| `nuke_side/nuke_mcp_bridge/serialize.py` | knob values / nodes to JSON |
| `nuke_side/nuke_mcp_bridge/commands/*.py` | built-in commands (core, graph, script, image) |
| `src/nuke_mcp/server.py` | MCP server; auto-loads every `tools/*.py` |
| `src/nuke_mcp/client.py` | socket client (reconnects once, long timeout) |
| `src/nuke_mcp/tools/*.py` | typed MCP tools, thin wrappers over bridge commands |
| `tests/smoke_test.py` | end-to-end test against a headless Nuke |

## Install

1. Nuke side: one line in `~/.nuke/init.py`:
   ```python
   if os.path.isdir('/path/to/nuke-mcp/nuke_side'):
       nuke.pluginAddPath('/path/to/nuke-mcp/nuke_side')
   ```
   Nuke then runs `nuke_side/menu.py` at GUI startup. To load it into an already-open
   Nuke without restarting, paste this into the Script Editor:
   ```python
   import sys; sys.path.insert(0, '/path/to/nuke-mcp/nuke_side')
   exec(open('/path/to/nuke-mcp/nuke_side/menu.py').read())
   ```
2. MCP side:
   ```
   uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python -e .
   claude mcp add --scope user nuke -- /path/to/nuke-mcp/.venv/bin/nuke-mcp
   ```

Env vars: `NUKE_MCP_PORT` (default 49512, set it the same on both sides),
`NUKE_MCP_AUTOSTART=0` (don't start with the GUI), `NUKE_MCP_TIMEOUT` (client, s,
default 600), `NUKE_MCP_COMMAND_PATHS` (extra command dirs).

## Extending

**Add a Nuke-side command** (no restarts): drop a file in `~/.nuke/nuke_mcp_commands/`
(or a dir in `NUKE_MCP_COMMAND_PATHS`), then run the `reload_commands` tool or
MCP > Reload Commands. It's immediately callable through the generic `call` tool.

```python
# ~/.nuke/nuke_mcp_commands/shots.py
import nuke
from nuke_mcp_bridge import command
from nuke_mcp_bridge.commands.graph import resolve_node, set_knob  # reusable helpers

@command(undo="MCP: set shot colour")          # undo label => one Ctrl+Z step,
def set_constant_rgb(nodes, rgb):              # rolled back if it raises
    """Set the RGB (keeping alpha) of several Constants."""
    return {n: set_knob(resolve_node(n), "color", rgb) for n in nodes}
```

Rules: parameters arrive as JSON keyword args; return JSON-able data (nodes and knobs
are converted automatically); set `undo=` on anything that changes the script;
commands run on Nuke's main thread unless `main_thread=False`.
Built-in commands go in `nuke_side/nuke_mcp_bridge/commands/` instead.

**Promote it to a typed MCP tool** (optional, nicer schema for the model): add a
function to a `src/nuke_mcp/tools/*.py` module (or a new module with
`register(mcp, nuke)`) that calls `nuke.call("set_constant_rgb", ...)`. Needs the
MCP server restarted (restart Claude Code / `/mcp` reconnect).

## Tools (v0.1)

core: `ping`, `list_commands`, `call`, `reload_commands`, `exec_python`, `batch` ·
graph: `list_nodes`, `get_node`, `knob_info`, `set_knobs`, `create_node`,
`delete_nodes`, `set_inputs`, `rename_node`, `select_nodes` ·
script: `script_info`, `save_script`, `set_frame`, `view_node`, `render`,
`sample_pixel`, `convert_color`

`set_knobs` value forms: scalar · list per channel (shorter list = leading channels,
so `[r,g,b]` keeps alpha) · `{"expression": ..., "channel": i}` · `{"script": ...}` ·
`{"keys": {frame: value}}`.

`convert_color` runs Nuke's own OCIO nodes on temporary nodes (no undo entries), so
`convert_color("#ff2400")` gives the working-space value that *displays* as #ff2400
through the Viewer's view transform. `source=` any colourspace name for other cases.

## Protocol (v1)

One JSON object per line each way.
Request `{"id", "cmd", "params": {}}` → `{"id", "ok": true, "result"}` or
`{"id", "ok": false, "error", "traceback"}`. Any language can talk to it:
`echo '{"id":1,"cmd":"ping"}' | nc -q1 127.0.0.1 49512`.

## Notes / gotchas

- Only listens on 127.0.0.1, but any local process can run Python in Nuke through it.
- Only the first Nuke opened gets the port; others log it and stay idle.
- `render` blocks the GUI; long renders should be headless `Nuke -x`.
- `nuke -t` starts with undo **disabled**; `serve_forever` enables it so rollback works.
- Nuke 17 `nuke.sample()` has no frame arg; use `node.sample(c, x, y, dx, dy, frame)`.
- mcp SDK v2 renamed FastMCP to `MCPServer` and splits list results into one content
  block per item, so the MCP layer always returns one object (`{"result": ...}` for
  non-dicts).

## Test

```
NUKE_BIN=/path/to/Nuke17.0 .venv/bin/python tests/smoke_test.py [script.nk]
```
Starts a headless Nuke on port 49599 (uses a Nuke licence while it runs, ~30 s),
builds its own test nodes and drives every core tool through the MCP layer. Pass a
script to run the same checks on a copy of it (it is never saved). If `NUKE_BIN`
is unset the test looks for a `Nuke*` executable on `PATH`.

## License

MIT

TDQS

A3.5/5.0

Scored across 22 tools

Disambiguation4/5

Most tools target a distinct resource+action (create_node, delete_nodes, set_inputs, rename_node, select_nodes), and knob_info vs get_node is a minor but readable split (single-knob detail vs whole-node inspection). The real overlap is the meta-layer: `call`, `batch`, and `exec_python` can all perform operations the dedicated tools already cover, though descriptions explicitly state precedence ('Use for commands that have no dedicated tool', 'Prefer the dedicated tools when one fits').

Naming Consistency4/5

Nearly everything follows a predictable snake_case verb_noun pattern (get_node, set_knobs, list_nodes, create_node, set_frame, save_script), with a few sensible single-verb commands (ping, render, call, batch). Minor deviations: knob_info/script_info use a noun_info form, and delete_nodes is plural while create_node/rename_node are singular.

Tool Count4/5

22 tools is slightly on the heavy side but each maps to a real Nuke operation (DAG editing, knob manipulation, rendering, colour conversion, pixel sampling, script lifecycle). Nothing feels redundant at the tool level; the count reflects a genuinely broad domain rather than padding.

Completeness4/5

Solid lifecycle coverage: create/delete/rename/select/list/inspect nodes, wire inputs, read and write knobs, plus render, save, frame control, colour conversion and pixel sampling. The escape hatches (list_commands/call/exec_python/batch) mean uncovered operations are still reachable, so there are no true dead ends; absence of explicit undo/redo or group-navigation tools is a minor gap.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues