Skip to main content
Glama
bambutler-mcp

bambutler-mcp

README.md
# bambutler

**Bambu + butler.** A print butler for Bambu Lab 3D printers on your local network, made for
Claude. You say "model a cable clip and print it in PLA". Claude models the part, slices it
with Bambu presets, shows you every setting with its reason, and asks "Is that what you want
to do?". On your yes it prints, and a small macOS monitor window opens and follows the job.

bambutler is a command-line tool (`bambutler`) and an [MCP](https://modelcontextprotocol.io)
server (`bambutler-mcp`). Both call the same functions, so they behave the same.

- **Propose, then print.** Every print starts from a stored proposal: presets, filaments per
  tray, supports, prime tower, calibrations, speed, estimates and warnings. Nothing prints
  without your yes, and a change makes a new proposal.
- **Saved presets.** Save the settings of a print that worked, lock them, and reuse them by
  name. A locked version never changes.
- **Bambu standard only.** Bambu system presets, Bambu start G-code, Bambu calibration flags.
  bambutler never writes custom G-code.
- **Lessons in code.** Post-slice checks catch known failures before they reach the printer
  (H2D nozzle reach, tree supports without interface, a shrunk prime tower, layout gaps).
- **Bambutler Monitor.** A read-only SwiftUI window: camera, temperatures, AMS, layers,
  filament changes, alerts. It opens by itself when a print starts.
- **Claude skills** in [`skills/`](skills/): the print loop and safety rules, printing,
  slicing, multi-material, modeling, setup and test coupons.
- Python 3.9+, **standard library only**. No cloud account. Works with Bambu printers that
  offer local MQTT/FTPS (X1, P1, A1, H2, P2 series and newer). The H2D is the most tested.

> **Not affiliated with, endorsed by, or supported by Bambu Lab.** "Bambu Lab", "Bambu Studio"
> and "AMS" are trademarks of their owners. Use at your own risk: a printer is a machine with
> hot parts and moving axes.

## Requirements

- **macOS or Linux**, Python 3.9 or newer. Tested on a Bambu Lab H2D; the other series use
  the same LAN protocol but are not tested on hardware yet. Windows is experimental: the
  code paths exist, but not all tests pass there yet.
- The printer in **LAN Only mode**, on the same network as your computer.
- **Developer Mode** on (printer screen: Settings > Network / LAN Only). Current firmware
  refuses print, pause and stop from third-party tools without it. Status works without it.
- The printer **access code** (LAN Only page on the printer screen). `bambutler setup` asks
  for it once.
- [Bambu Studio](https://bambulab.com/en/download/studio), installed and opened once, for
  slicing.
- [ffmpeg](https://ffmpeg.org) for camera photos on X1, H2 and P2S (P1 and A1 need nothing).
- For the monitor app: macOS 14+ and the Swift toolchain (`xcode-select --install`).
- Optional: [OpenSCAD](https://openscad.org) for modeling, [gmsh](https://gmsh.info) for STEP
  files.

## Install

```sh
uv tool install 'bambutler[tui] @ git+https://github.com/marlowetal653/bambutler'
# or
pipx install 'bambutler[tui] @ git+https://github.com/marlowetal653/bambutler'
# after the first PyPI release: uv tool install 'bambutler[tui]'
```

From a clone (for development):

```sh
git clone https://github.com/marlowetal653/bambutler
uv tool install --editable ./bambutler     # or: pipx install --editable ./bambutler
```

This installs two commands: `bambutler` and `bambutler-mcp`.

## Setup

Run this once, in a terminal:

```sh
bambutler setup
```

1. It finds printers on the LAN (SSDP). When none answers, it asks before it scans your
   subnet.
2. You pick a printer and give it a name.
3. You type the access code at a hidden prompt. bambutler tests it, pins the printer
   certificate, and stores the code in the macOS Keychain or the Linux secret service
   (service `bambutler`, account = serial). Without a secret store it writes a 0600 file,
   only after you agree to the path it shows.
4. It writes `config.json` (name, host, serial, model, certificate hash; no code).
5. It offers to install the skills, register the MCP server and build the monitor app, then
   runs `bambutler doctor`.

Other setup commands:

| Command | What it does |
| --- | --- |
| `bambutler doctor` | read-only health report: config, code source (never the code), reachability, certificate, Developer Mode, camera, slicer, MCP, watcher |
| `bambutler setup --rediscover` | find the printer again after an IP change (DHCP); asks before it changes the host |
| `bambutler setup --import-keychain` | move a code from the old `bambu-lan` keychain item or an inline config entry |
| `bambutler setup --forget NAME` | remove a printer and its stored code |

The config file is `~/.config/bambutler/config.json` (macOS also
`~/Library/Application Support/bambutler/config.json`, Windows
`%APPDATA%\bambutler\config.json`, or any path in `BAMBUTLER_CONFIG`).

## Quick start

Ask Claude, in Claude Code or Claude Desktop:

> Model a 40 mm cable clip for a 6 mm cable and print it in PLA.

Claude models the clip and shows a render. Then it proposes the print:

```text
Proposal p-7f3a (valid 30 min) for clip.gcode.3mf on lab-h2d
  process      0.20mm Standard @BBL H2D          (system preset)
  filament 1   Bambu PLA Basic -> A4, right      (assumption: PLA as you asked)
  supports     off                               (no overhang over 45 degrees)
  calibrations bed leveling auto, flow auto, vibration auto (default)
  speed        standard; timelapse off
  bed          is the plate clear?               (ask)
  estimate     18 min, 6.1 g, 50 layers
Is that what you want to do?
```

You answer "yes". The print starts, and Bambutler Monitor opens. When the print finishes,
Claude asks: "Save this as preset clip-pla and lock it?".

The same flow from a shell:

```sh
bambutler propose clip.stl                  # slices, checks, stores the proposal, prints it
bambutler print --proposal p-7f3a --yes     # starts exactly that proposal
bambutler events --kinds STATE,HMS,HANG,END
```

## Presets

A preset is a saved, named set of print settings. It names Bambu system presets and stores
only your overrides. Filaments match trays by Bambu `filament_id`.

```sh
bambutler preset save clip-pla --from-job JOB_ID   # or --from-3mf FILE.gcode.3mf
bambutler preset lock clip-pla                      # v1 never changes again
bambutler preset list
bambutler preset show clip-pla@v1
bambutler preset edit clip-pla --set wall_loops=3   # a locked preset gets v2
bambutler propose clip.stl --preset clip-pla        # one question: "Print with clip-pla@v2? Plate is clear?"
```

- Presets live in `<config dir>/presets/<name>/vN.json`.
- A preset never holds a host, a serial or an access code. The writer refuses them.
- If the Bambu base preset or the Studio version changed since the lock, the proposal warns.
- Bambu Studio presets are browsed with `bambutler studio presets` and
  `bambutler studio preset NAME`.

## Propose, then print

`propose_print` (CLI `bambutler propose`) does all of this, and sends nothing to the printer:

1. Reads the printer: state, trays per nozzle, HMS alerts.
2. Chooses each value from the named preset, or from the Bambu defaults plus stated
   assumptions.
3. Slices with the Bambu Studio CLI.
4. Runs the post-slice checks (nozzle reach, filament ids, support interface, layout gaps,
   prime tower).
5. Maps filaments to trays by `filament_id`. A colour match is only a fallback, marked as an
   assumption.
6. Stores the proposal for 30 minutes, with the file hash, the payload hash and a tray
   snapshot.

`print_file` (CLI `bambutler print --proposal ID --yes`) is the only way to start a print. It
builds the payload only from the stored proposal, and it refuses when the proposal expired,
the file changed, the printer state changed or the trays changed. When the MCP client
supports elicitation, the server asks you directly.

## Bambutler Monitor (macOS)

```sh
bambutler monitor install     # builds "Bambutler Monitor.app" from source (Swift)
bambutler monitor open        # opens it on the current job
```

- One window. It opens by itself when a print starts (`monitor.auto_open`, on by default).
- It shows the camera photo with its stage and layer, printer and toolhead temperatures,
  progress, prepare steps, a layer strip with filament changes, AMS trays, alerts and events.
- It is read-only. It has no network code and never sees the access code. It reads the state
  files that the watcher writes ([docs/STATE_FORMAT.md](docs/STATE_FORMAT.md)).
- Every action (pause, stop, print) goes through Claude or the CLI, so every action keeps its
  confirm gate.

### Terminal monitor

```sh
uv tool install --editable '.[tui]' --force   # or: pip install 'bambutler[tui]' (Textual)
bambutler monitor tui                         # starts the watcher, then runs here
bambutler monitor open --tui                  # the same in a new Terminal window
```

- It shows everything the app shows, in the terminal: job, state, stage, progress, prepare
  steps, the layer strip with filament changes, both nozzles, bed and chamber with sparklines,
  fans, AMS trays and external spools, alerts, events, settings and the camera photo.
- It has three controls, each behind a confirm that names the command, the printer and the
  job: pause (`space`), chamber light (`l`) and speed (`s`). Pause and speed first read the
  printer and refuse when it runs a job other than the one on the screen.
  There is no resume and no stop: resume on the printer screen, stop with `bambutler stop`.
- Other keys: `p` printer, `r` reload, `t` light or dark theme, `?` help, `q` quit.
- To open it instead of the app when a print starts, set `"monitor": {"ui": "tui"}` in
  `config.json` (or `BAMBUTLER_MONITOR_UI=tui`). The default is `"app"`.

### Print agent: Claude and the monitor in one window

```sh
bambutler agent                      # Claude Code with the print-butler agent + the monitor
bambutler agent --printer lab-h2d --layout below
bambutler agent -- --permission-mode acceptEdits   # arguments after -- go to claude
```

- `print-butler` is a Claude Code agent that does printing only. It reads the printer,
  proposes every print word for word, asks "Is that what you want to do?" and "Plate is
  clear?", and starts a print only on your clear yes. It follows the safety rules below and
  asks which build plate is installed before it proposes.
- With [tmux](https://github.com/tmux/tmux), Claude and the terminal monitor share one
  window in the tmux session `bambutler-<printer>`. The monitor goes to the right when the
  terminal has 180 columns or more, else below (`--layout right|below` to choose). Run the
  command again to re-attach. When Claude exits, the session ends. Inside tmux, the command
  splits the current window.
- Without tmux (`brew install tmux`, `sudo apt install tmux`), the monitor opens in its own
  Terminal window on macOS; on other systems, run `bambutler monitor tui` in a second
  terminal. Claude runs in this terminal. `--layout none` starts Claude only. With no printer
  configured, only Claude starts and helps you run `bambutler setup`.
- In the agent session, raw G-code (`bambutler gcode`, `home`, `temp`, `fan`) is refused:
  the launcher sets `BAMBUTLER_AGENT=1` and denies those Bash commands. Run them yourself in
  another terminal. When you decline the print in the confirm dialog (or leave "The build
  plate is clear" unticked), that proposal is blocked on every path.
- The watcher daemon starts first. The monitor pane needs `bambutler[tui]`; without it the
  pane shows the install hint and Claude still starts.
- The launcher passes the agent to `claude` with `--agents` and `--agent print-butler`, so
  no install step is needed. When `claude mcp get bambutler` finds no server, it adds this
  install's `bambutler-mcp` for the session with `--mcp-config`. `--claude PATH` and
  `--model M` are optional.
- The agent file is [`agents/print-butler.md`](agents/print-butler.md). The same file is the
  agent of the Claude Code plugin in this repository (`.claude-plugin/`): load it with
  `claude --plugin-dir /path/to/bambutler` and pick the agent `bambutler:print-butler`.

## MCP server

Claude Code:

```sh
claude mcp add --scope user bambutler -- bambutler-mcp
bambutler skills install
```

Claude Desktop (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "bambutler": {"command": "bambutler-mcp"}
  }
}
```

**Never put the access code in the MCP `env` block.** Run `bambutler setup` instead: the
server reads the code from the keychain when it needs it.

Without installing (from the repository):

```sh
claude mcp add --scope user bambutler -- uvx --from git+https://github.com/marlowetal653/bambutler bambutler-mcp
```

| Group | Tools |
| --- | --- |
| Loop | `printer_context`, `propose_print`, `print_file` (`proposal_id`, `confirm`) |
| Info | `list_printers`, `status`, `ams`, `events`, `camera_snapshot`, `list_storage_files`, `decode_hms` |
| Control | `pause`, `resume` (refused after an HMS pause), `stop` (`job`, `confirm`), `skip_objects`, `set_speed`, `light`, `set_ams_slot` |
| Slicer | `find_slicer`, `list_presets`, `show_preset`, `inspect_model`, `slice`, `preview`, `slice_info`, `make_studio_project` |
| Presets | `list_saved_presets`, `show_saved_preset`, `save_preset`, `lock_preset` |
| Help | `guide` (skill text, `lessons`, `index`) |

Raw G-code tools (`send_gcode`, `home`, `set_temperature`, `set_fan`) are registered only when
the server starts with `BAMBUTLER_RAW_GCODE=1`. The CLI keeps them for a human, with `--yes`.

### Skills

`bambutler skills install` copies the skills to `~/.claude/skills` with a version marker. It
refuses to overwrite a skill you edited (use `--force` to replace it). Clients without a
skills folder read the same text with the MCP tool `guide`.

| Skill | Content |
| --- | --- |
| `bambutler` | the loop (model, propose, confirm, print, monitor) and the safety rules |
| `bambutler-print` | proposal format, calibration policy, start, monitoring, HMS, stop by name, save and lock |
| `bambutler-slicing` | presets, flattening, H2D reach, `normal(auto)` vs tree, prime tower defaults, layout |
| `bambutler-multimaterial` | material pairs, AMS and nozzle feeds, interface variants, drying |
| `bambutler-modeling` | OpenSCAD, STEP to STL with gmsh, orientation by comparison |
| `bambutler-setup` | install, setup, Developer Mode, doctor, rediscovery |
| `bambutler-test-coupons` | small test pieces cut from the real part |

The lessons behind these rules are in [docs/LESSONS.md](docs/LESSONS.md).

## CLI

Every command takes `--printer NAME` (default: the first printer) and `--json`. Exit codes:
**0** ok, **1** refused by a safety gate or `--yes` missing, **2** usage error, **3** printer,
connection, config or slicer error (also `doctor` when a check fails).

| Command | What it does |
| --- | --- |
| `bambutler setup`, `bambutler doctor` | first setup; read-only health report |
| `bambutler printers` | configured printers and where each code comes from (never the code) |
| `bambutler status [--raw] [--refresh]` | state, stage, progress, temperatures, storage, AMS, errors |
| `bambutler ams` | AMS trays and external spools, with the nozzle each one feeds |
| `bambutler propose FILE [--preset NAME] [--set K=V]` | slice, check and store a proposal |
| `bambutler print --proposal ID --yes` | start a stored proposal |
| `bambutler watch`, `bambutler events [--since N] [--kinds A,B]` | the watcher and its event log |
| `bambutler snap [-o file.jpg]` | one camera frame |
| `bambutler pause`, `bambutler resume` | print control (resume is refused after an HMS pause) |
| `bambutler stop --job NAME --yes`, `bambutler skip ID... --job NAME --yes` | cancel the named job / skip objects in it |
| `bambutler speed silent\|standard\|sport\|ludicrous` | speed of the running print |
| `bambutler light on\|off\|flashing` | lights |
| `bambutler slot --ams N --slot S --type T --color RRGGBB` | material shown for a tray |
| `bambutler files [PATH]`, `bambutler hms CODE...` | storage listing; HMS decoding |
| `bambutler preset list\|show\|save\|edit\|lock\|use` | saved presets |
| `bambutler studio presets\|preset` | Bambu Studio presets |
| `bambutler slicer find`, `bambutler model FILE...` | find the slicer; inspect meshes |
| `bambutler slice MODEL... --machine M --process P --filament F ...` | slice to explore (printing goes through `propose`) |
| `bambutler preview FILE.3mf`, `bambutler info FILE.3mf` | plate image; estimates, filaments, nozzle map |
| `bambutler monitor install\|open\|uninstall` | the monitor app |
| `bambutler monitor tui`, `bambutler monitor open --tui` | the terminal monitor (`bambutler[tui]`) |
| `bambutler agent [--layout auto\|right\|below\|none]` | Claude Code with the print-butler agent next to the terminal monitor |
| `bambutler skills install [--force]` | copy the skills to `~/.claude/skills` |
| `bambutler gcode`, `bambutler home`, `bambutler temp`, `bambutler fan` | for a human at the keyboard, with `--yes` |

## Safety model

| Gate | Rule |
| --- | --- |
| Proposal | a print starts only from a stored proposal that you confirmed; it expires after 30 min |
| Drift | file hash, payload hash, printer state and tray snapshot must still match |
| Change | any change makes a new proposal and a new question |
| Calibrations | tri-state `auto`/`on`/`off`; never added without your request; "ran" only with a timeline record |
| Resume | refused after an HMS pause or a print error; you resume on the printer screen |
| Stop / skip | only with the running job's name; a different name is refused |
| G-code | no custom G-code; raw G-code tools are hidden from the agent unless `BAMBUTLER_RAW_GCODE=1` |
| Start G-code | `slice` refuses a generic start G-code and checks the Bambu machine marker in the result |
| Access code | stored in the keychain; never in config, argv, child environments, tool results, logs or the monitor app |
| Network | MQTT and FTPS pin the printer certificate from setup |

The camera URL holds the access code, so bambutler passes it to ffmpeg on stdin, never in
argv.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| timeout on port 8883 | the IP may have changed (DHCP): `bambutler setup --rediscover`. SSDP crosses subnets; a TCP scan does not |
| CONNACK 4 or 5, "wrong access code" | the code changed: run `bambutler setup` |
| `0502-4007`, `0500_0500_0001_0007` | turn on Developer Mode |
| `553 Could not create file` | insert a USB drive (H2D, H2S, P2S) or an SD card (X1, P1, A1) |
| `0500-4002` | wrong print URL form: propose again with the other `url_mode` |
| camera "live view off" | turn on LAN live view; during stage 74 and a pause the printer hides it |
| slice refused: only generic start G-code | update or reinstall Bambu Studio and open it once |
| `return_code -102` | G-code outside the reach of a nozzle on a dual-nozzle printer: move the object or tower |
| `return_code -17` | the presets do not fit each other: choose presets for this printer |

## Development

```sh
BAMBUTLER_NO_KEYCHAIN=1 python3 -m unittest discover -s tests -t . -v
cd monitor && swift build && swift test        # macOS
git config core.hooksPath .githooks            # once per clone: the secret gate
python3 tools/scan_secrets.py                  # prints CLEAN or MATCH <path> <rule>
```

- The tests run a fake printer (TLS MQTT broker, implicit-FTPS server, port-6000 camera) with
  a certificate made by `openssl` at test time. They skip if `openssl` is missing. No test
  talks to a real printer or reads the real keychain.
- The slicer integration test runs the real Bambu Studio CLI when it is installed.
- `tools/scan_secrets.py` compares your stored access codes with every file and the whole
  history, in its own process. It also checks serials, private IPs, emails, home paths,
  images outside `docs/img/`, and an optional denylist file outside the repo
  (`BAMBUTLER_DENYLIST`). The pre-commit hook runs it. CI runs it and gitleaks.
- `docs/LESSONS.md` is generated: `python3 -m bambutler.knowledge --markdown > docs/LESSONS.md`.
- Design notes: [docs/DESIGN.md](docs/DESIGN.md). State files:
  [docs/STATE_FORMAT.md](docs/STATE_FORMAT.md).

### Release checklist

1. Replace the GitHub owner placeholder in `pyproject.toml`, `README.md` and
   `.claude-plugin/plugin.json`. `python3 tools/scan_secrets.py --release` fails until it is
   gone.
2. Set the version in `bambutler/__init__.py` and `.claude-plugin/plugin.json`, and pin the
   plugin to that tag (later to `bambutler==X.Y.Z` on PyPI).
3. Run the tests, `swift test` and `python3 tools/scan_secrets.py --release`.
4. On pypi.org, add a trusted publisher for this repository, workflow `release.yml`,
   environment `pypi`. No API token is needed.
5. Push the tag `vX.Y.Z`. The `release` workflow runs the gates and publishes.

## Prior art and credits

This project shares no code with them, but learned a lot from their docs and source. See
[docs/PRIOR_ART.md](docs/PRIOR_ART.md).

- [greghesp/ha-bambulab](https://github.com/greghesp/ha-bambulab) (Home Assistant integration)
- [Doridian/OpenBambuAPI](https://github.com/Doridian/OpenBambuAPI) (protocol documentation)
- [BambuTools/bambulabs_api](https://github.com/BambuTools/bambulabs_api)
- [synman/bambu-printer-manager](https://github.com/synman/bambu-printer-manager) and
  [synman/bambu-mcp](https://github.com/synman/bambu-mcp)
- [griches/bambu-mcp](https://github.com/griches/bambu-mcp),
  [schwarztim/bambu-mcp](https://github.com/schwarztim/bambu-mcp),
  [Shockedrope/bambu-mcp-server](https://github.com/Shockedrope/bambu-mcp-server),
  [danielefinocchiaro/unofficial-bambu-mcp](https://github.com/danielefinocchiaro/unofficial-bambu-mcp),
  [MrMebelMan/bambuddy-mcp](https://github.com/MrMebelMan/bambuddy-mcp)

## License

MIT. See [LICENSE](LICENSE).

TDQS

B3.4/5.0

Scored across 30 tools

Disambiguation4/5

Most tools target a distinct resource+action, and the saved-preset vs Bambu Studio preset pairs are explicitly cross-referenced in their descriptions. The main soft overlaps are status / ams / printer_context (all surface printer and AMS state) and slice / propose_print / print_file, which form a layered workflow that an agent could still mis-order.

Naming Consistency3/5

A solid verb_noun convention dominates (list_saved_presets, show_preset, set_ams_slot, skip_objects, decode_hms), but a large minority are bare nouns or verbs (status, ams, events, light, slice, preview, pause, stop, guide). The mixed style is readable but not predictable from name alone.

Tool Count2/5

30 tools is above the threshold where a set stays easily scannable, and some of that bulk is redundant (status, ams and printer_context all report overlapping printer state). The domain is genuinely broad, but several monitoring tools could be consolidated.

Completeness4/5

The print lifecycle is well covered end to end: inspect/slice/propose/print, pause/resume/stop/skip, speed, lights, camera, events, HMS decoding, presets and guidance. Gaps are minor: storage is read-only (no upload/delete file), presets cannot be deleted or renamed, and there is no filament load/unload beyond set_ams_slot.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues