bambu-printer-mcp 1.1.48 → 1.1.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -94,7 +94,7 @@ If your agent is always on, such as OpenClaw or Hermes Agent running on a comput
94
94
 
95
95
  ### Before you print
96
96
 
97
- - **"Take a picture and make sure the bed is clear, then start the bracket I sliced last night."**\
97
+ - **"Start the bracket I sliced last night."**\
98
98
  It checks the camera image before it sends the job.
99
99
  - **"What's loaded in the AMS? Print this in whatever black I have."**\
100
100
  It reads the live AMS inventory and matches the file's filaments to your trays.
@@ -713,7 +713,7 @@ If `filename` does not include a directory prefix, the server prepends `cache/`
713
713
 
714
714
  #### cancel_print
715
715
 
716
- Cancel the currently running print job. Sends an `UpdateState` MQTT command with `state: "stop"`. Not resumable — use `pause_print` if you may want to continue.
716
+ Cancel the currently running print job. Sends Bambu Studio's stop, `{"print":{"command":"stop","param":"","sequence_id":"<n>"}}`, at MQTT QoS 1, and waits up to 10 seconds for the printer to acknowledge it. A stop that isn't acknowledged returns an error, and its MQTT client is closed so it can't be sent late. Not resumable — use `pause_print` if you may want to continue.
717
717
 
718
718
  ```json
719
719
  {
@@ -909,6 +909,15 @@ Inspect a prepared sliced 3MF or textual G-code file offline before deciding wha
909
909
 
910
910
  The generic result has `receipt_version: "1"`, `evidence: "file-only"`, `dispatch_authorized: false`, `artifact` (`sha256`, `byte_length`, `file_format`), the requested `selection`, and the original `inspection` including declared model, nozzles, materials/used filament positions, internal plate path and checked temperature peaks. Hash and byte length identify the exact inspected snapshot; a consumer must compare them with its own artifact and selected plate. The temporary snapshot is removed, and its path is not a dispatch capability. The receipt does not prove printer readiness, physical material/nozzle contents, fit, full motion simulation or permission to print. Actual print routes still independently inspect the dispatched snapshot and require fresh hardware state and human preflight.
911
911
 
912
+ #### Print options
913
+
914
+ Every print route sends the options Bambu Studio's Send dialog sends (Bambu Studio 02.08.02.61, `SelectMachine.cpp:3344-3356`): bed leveling, flow calibration and nozzle offset calibration, vibration calibration, first-layer inspection and `extruder_cali_manual_mode`. That covers the BambuNetwork bridge, the native helper and LAN `project_file`. Each option you don't pass resolves as Studio resolves it:
915
+
916
+ 1. Studio's saved choice for that printer type in `BambuStudio.conf`, if the printer offers it. For example, a P1S offers only on/off for bed leveling, so a saved "auto" counts as unset.
917
+ 2. Otherwise "auto" if the printer offers it, else "on". On a P1S, flow calibration and nozzle offset calibration are hidden, so they stay "auto".
918
+
919
+ Studio hard-codes vibration calibration off, first-layer inspection on and `extruder_cali_manual_mode` 0. For a P1S with nothing passed, the bridge sends `task_bed_leveling: true`, `auto_bed_leveling: 1`, `task_flow_cali: false`, `auto_flow_cali: 2`, `task_vibration_cali: false`, `task_layer_inspect: true`, `auto_offset_cali: 2` and `extruder_cali_manual_mode: 0`. An option you pass wins. `bed_leveling`/`flow_calibration` set "on" or "off", and `auto_bed_leveling`, `auto_flow_cali` and `auto_offset_cali` take 0 (off), 1 (on) or 2 (auto). On the H2/P2S LAN `project_file` route, the printer only receives flow calibration as on or off: no verified field requests "auto", so "auto" sends off, as before. The BambuNetwork and native routes carry `auto_flow_cali`. Only the printer type's own section of `BambuStudio.conf` is read; the file also holds access codes. `BAMBU_STUDIO_CONFIG` names another file, and an empty value uses no saved choices.
920
+
912
921
  #### print_3mf
913
922
 
914
923
  The primary tool for starting a Bambu print. **Recommended input: a pre-sliced `.gcode.3mf` exported from FULU OrcaSlicer-bambulab, OrcaSlicer, or Bambu Studio** — see [slicing guide](https://github.com/DMontgomery40/bambu-printer-mcp/blob/main/docs/SLICING.md). This tool handles the complete workflow:
@@ -1062,7 +1071,7 @@ If the project does not match those assumptions, the tool fails fast with a stru
1062
1071
  - `job` (not for idle, busy or offline): `name` is `subtask_name`, else the basename of `gcode_file` (a raw G-code print reports only its file path; that basename is the `jobName` the print returns); `id` is `task_id`, omitted when it is the LAN placeholder `"0"`; `progress` is `mc_percent`; `remainingSec` is `mc_remaining_time` (minutes) × 60; `layer`/`totalLayers` appear once the printer reports a total; `stage` is Bambu Studio's words for `stg_cur` ("Heatbed preheating", "Auto bed leveling").
1063
1072
  - `temps`: nozzle and bed `{actual, target}`, and `chamber` from the H2 chamber controller or the X1 sensor. On H2 and X2D the nozzle is the active extruder's, from `device.extruder`. P1 and A1 printers have no chamber sensor, so it is omitted.
1064
1073
  - `activeFilament`: the loaded spool's `material` and `#RRGGBB` `color`. `slot` is the index `ams_slots` uses: `amsId × 4 + tray` for an AMS, the unit id (128 and up) for an AMS-HT, and `"ext"` for the external spool, or `"254"` (left) / `"255"` (right) on dual-nozzle H2D, H2C and X2D. On H2 and X2D it comes from the active extruder's report.
1065
- - `problems`: a non-zero `print_error` as 8 hex digits, such as `07008011`, and each HMS entry as `AAAA_BBBB_CCCC_DDDD`, such as `0300_1800_0001_0003`. Severity follows Bambu's HMS level: fatal is `fatal`, serious `error`, common `warning` and info `info`. Each HMS problem links to Bambu's page for that code. Messages come from the English HMS tables bundled with the pinned Bambu Studio release; `scripts/generate-hms-messages.mjs` turns them into `src/safety/hms-messages.ts` and the stage words into `src/printers/bambu-stages.ts`. A model without its own table, such as the P1S, gets the text the other tables share. Codes that Bambu lists for a printer without text are reported as `info`.
1074
+ - `problems`: a non-zero `print_error` as 8 hex digits, such as `07008011`, and each HMS entry as `AAAA_BBBB_CCCC_DDDD`, such as `0300_1800_0001_0003`. Severity follows Bambu's HMS level: fatal is `fatal`, serious `error`, common `warning` and info `info`. Each HMS problem links to Bambu's page for that code. Messages come from the English HMS tables bundled with the pinned Bambu Studio release; `scripts/generate-hms-messages.mjs` turns them into `src/safety/hms-messages.ts` and the stage words into `src/printers/bambu-stages.ts`. A model without its own table, such as the P1S, gets the text the other tables share. A code none of them has falls back to the user's own Bambu Studio download: `hms_en_<serial prefix>.json`, then `hms_en.json`, in the `hms` folder next to `BambuStudio.conf` (see `BAMBU_STUDIO_CONFIG`). Those files are read only, and Bambu's text is passed through unchanged. Codes that Bambu lists for a printer without text are reported as `info`.
1066
1075
  - **`counterpart_make_3mf`** takes `{parts: [{stl_path, name, filament?}], out_path}` and writes a new 3MF for multi-colour printing. The parts become one assembly: they keep their relative positions, and each part prints with its own filament number (by default part 1 uses filament 1, part 2 filament 2, and so on). Slice it with `slice_stl` and one `load_filaments` profile per filament number, then print it with `print_3mf` and `ams_slots` or `ams_mapping`. The file holds one assembly rather than one object per part, because Bambu Studio 02.08.02.61's CLI arranges separate objects apart, reports G-code path conflicts between stacked objects when arranging is off, and refuses `load_filament_ids` for 3MF input. It never overwrites a file. The result lists `path`, `objects`, `filaments` (the highest filament number) and each part's triangle count.
1067
1076
 
1068
1077
  `print_3mf` also returns `subtaskName`, the `subtask_name` it sends with the job, when it starts a 3MF with the LAN `project_file` command: an STL or 3MF sliced by `slice_stl`, and any 3MF on H2, P2S and A1. On H2 and P2S it also returns `taskId`, the `task_id` sent with the job; other models send `task_id: "0"`. A client can match `counterpart_print_progress` reports to its own print with these. Pre-sliced `.gcode.3mf` files on P1, X1 and A1 mini (sent as a G-code file), the X2D native route, and the BambuNetwork and Bambu Connect routes return neither.
@@ -18,6 +18,11 @@ export type BambuNativePrintOptions = {
18
18
  flowCalibration?: boolean;
19
19
  vibrationCalibration?: boolean;
20
20
  layerInspect?: boolean;
21
+ /** Bambu Studio's PrintParams auto_* values (0 off, 1 on, 2 auto) and extruder_cali_manual_mode. */
22
+ autoBedLeveling?: number;
23
+ autoFlowCali?: number;
24
+ autoOffsetCali?: number;
25
+ extruderCaliManualMode?: number;
21
26
  timelapse?: boolean;
22
27
  /** true: the SD card or USB stick; false: internal storage (eMMC); unset: BAMBU_NATIVE_TRY_EMMC_PRINT or internal. Reported as the requested storage. */
23
28
  externalStorage?: boolean;
@@ -745,8 +745,13 @@ export async function printWithBambuNative(options, onUpdate, execution) {
745
745
  BAMBU_NATIVE_NOZZLES_INFO: options.nozzlesInfo || "",
746
746
  BAMBU_NATIVE_BED_LEVELING: boolEnv(options.bedLeveling, true),
747
747
  BAMBU_NATIVE_FLOW_CALIBRATION: boolEnv(options.flowCalibration, true),
748
- BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, true),
749
- BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, false),
748
+ // Bambu Studio's Send dialog hard-codes these (SelectMachine.cpp:3344-3356).
749
+ BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, false),
750
+ BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, true),
751
+ ...(options.autoBedLeveling === undefined ? {} : { BAMBU_NATIVE_AUTO_BED_LEVELING: String(options.autoBedLeveling) }),
752
+ ...(options.autoFlowCali === undefined ? {} : { BAMBU_NATIVE_AUTO_FLOW_CALI: String(options.autoFlowCali) }),
753
+ ...(options.autoOffsetCali === undefined ? {} : { BAMBU_NATIVE_AUTO_OFFSET_CALI: String(options.autoOffsetCali) }),
754
+ ...(options.extruderCaliManualMode === undefined ? {} : { BAMBU_NATIVE_EXTRUDER_CALI_MANUAL_MODE: String(options.extruderCaliManualMode) }),
750
755
  BAMBU_NATIVE_TIMELAPSE: boolEnv(options.timelapse, false),
751
756
  ...(options.externalStorage === undefined ? {} : { BAMBU_NATIVE_TRY_EMMC_PRINT: String(!options.externalStorage) }),
752
757
  }, 300000, onUpdate, execution);
@@ -793,8 +798,13 @@ export async function uploadWithBambuNative(options, onUpdate, execution) {
793
798
  BAMBU_NATIVE_NOZZLES_INFO: options.nozzlesInfo || "",
794
799
  BAMBU_NATIVE_BED_LEVELING: boolEnv(options.bedLeveling, true),
795
800
  BAMBU_NATIVE_FLOW_CALIBRATION: boolEnv(options.flowCalibration, true),
796
- BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, true),
797
- BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, false),
801
+ // Bambu Studio's Send dialog hard-codes these (SelectMachine.cpp:3344-3356).
802
+ BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, false),
803
+ BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, true),
804
+ ...(options.autoBedLeveling === undefined ? {} : { BAMBU_NATIVE_AUTO_BED_LEVELING: String(options.autoBedLeveling) }),
805
+ ...(options.autoFlowCali === undefined ? {} : { BAMBU_NATIVE_AUTO_FLOW_CALI: String(options.autoFlowCali) }),
806
+ ...(options.autoOffsetCali === undefined ? {} : { BAMBU_NATIVE_AUTO_OFFSET_CALI: String(options.autoOffsetCali) }),
807
+ ...(options.extruderCaliManualMode === undefined ? {} : { BAMBU_NATIVE_EXTRUDER_CALI_MANUAL_MODE: String(options.extruderCaliManualMode) }),
798
808
  BAMBU_NATIVE_TIMELAPSE: boolEnv(options.timelapse, false),
799
809
  }, 300000, onUpdate, execution);
800
810
  if (result.resultCode !== 0) {
@@ -6,6 +6,7 @@
6
6
  import path from "node:path";
7
7
  import { BAMBU_STAGES } from "../printers/bambu-stages.js";
8
8
  import { HMS_MESSAGES, HMS_MESSAGES_SOURCE, PRINT_ERROR_MESSAGES } from "../safety/hms-messages.js";
9
+ import { studioDownloadedText } from "../studio-hms-text.js";
9
10
  import { isDualNozzleModel, normalizeModel } from "../safety/limits.js";
10
11
  import { finiteNumber, hmsCode, isHiddenNotice } from "../safety/printer-state.js";
11
12
  import { COUNTERPART_CONTRACT } from "./schemas.js";
@@ -73,7 +74,7 @@ export function bambuProblems(raw, serial, model) {
73
74
  // 0300400C only records a cancel; it is the state, not a problem.
74
75
  if (error !== undefined && Number.isInteger(error) && error > 0 && error <= 0xffffffff && error !== TASK_CANCELLED) {
75
76
  const code = error.toString(16).padStart(8, "0").toUpperCase();
76
- add({ code, severity: "error", message: tableText(PRINT_ERROR_MESSAGES, code, serial) ?? undocumented(code) });
77
+ add({ code, severity: "error", message: tableText(PRINT_ERROR_MESSAGES, code, serial) ?? studioDownloadedText("error", code, serial) ?? undocumented(code) });
77
78
  }
78
79
  for (const reported of Array.isArray(raw.hms) ? raw.hms : []) {
79
80
  const entry = hmsCode(reported);
@@ -89,7 +90,8 @@ export function bambuProblems(raw, serial, model) {
89
90
  add({
90
91
  code,
91
92
  severity: HMS_SEVERITIES[entry.severity] ?? "error",
92
- message: tableText(HMS_MESSAGES, entry.hex, serial) ?? undocumented(code),
93
+ // The pinned tag bundles no P1, X1 or A1 table; the user's own Studio download may have the text.
94
+ message: tableText(HMS_MESSAGES, entry.hex, serial) ?? studioDownloadedText("hms", entry.hex, serial) ?? undocumented(code),
93
95
  url: hmsUrl(entry.hex),
94
96
  });
95
97
  }
@@ -52,9 +52,11 @@ export const defaultFusionSystem = {
52
52
  /**
53
53
  * An open port is not enough: Blender's MCP add-on defaults to
54
54
  * localhost:9876, the add-in's own default. The add-in speaks newline-delimited JSON
55
- * (addon/server/socket_server.py) and answers {"type":"ping"} with
56
- * {"status":"success","result":{"pong":true}} without touching Fusion's API;
57
- * Blender's add-on answers an unknown command with an error.
55
+ * (addon/server/socket_server.py) and answers {"type":"ping"} without touching
56
+ * Fusion's API: on its fast path (event_bridge.py) with
57
+ * {"status":"success","result":{"ok":true,"status":"pong"}}, and through its
58
+ * command handler with {"pong":true}. Blender's add-on answers an unknown command
59
+ * with an error.
58
60
  */
59
61
  addinAnswers: (host, port, timeoutMs) => new Promise(resolve => {
60
62
  const socket = net.connect({ host, port });
@@ -78,7 +80,7 @@ export const defaultFusionSystem = {
78
80
  const newline = buffer.indexOf("\n");
79
81
  try {
80
82
  const reply = JSON.parse(newline >= 0 ? buffer.slice(0, newline) : buffer);
81
- done(reply?.status === "success" && reply?.result?.pong === true);
83
+ done(reply?.status === "success" && (reply?.result?.status === "pong" || reply?.result?.pong === true));
82
84
  }
83
85
  catch {
84
86
  if (newline >= 0)
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ import { FUSION_CALL_OUTPUT_SCHEMA, FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFA
18
18
  import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue } from "./ams-mapping.js";
19
19
  import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
20
20
  import { BambuImplementation, assertDirectPrintSupported, checkedFile } from "./printers/bambu.js";
21
+ import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-options.js";
21
22
  import { inspectPrintFile } from "./safety/print-file.js";
22
23
  import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
23
24
  import { isDualNozzleModel } from "./safety/limits.js";
@@ -123,6 +124,29 @@ function assertUniformCliNozzles(args) {
123
124
  }
124
125
  }
125
126
  const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2dpro", "h2s", "h2c", "x2d"];
127
+ /** The Send dialog options a caller set explicitly; the rest resolve as Bambu Studio does (studio-print-options.ts). */
128
+ function callerPrintOptions(args) {
129
+ const flag = (value) => value === undefined ? undefined : Boolean(value);
130
+ const int = (value, label) => {
131
+ if (value === undefined)
132
+ return undefined;
133
+ const number = Number(value);
134
+ if (!Number.isInteger(number))
135
+ throw new Error(`${label} must be an integer.`);
136
+ return number;
137
+ };
138
+ const options = {
139
+ bedLeveling: flag(args?.bed_leveling),
140
+ flowCalibration: flag(args?.flow_calibration),
141
+ vibrationCalibration: flag(args?.vibration_calibration),
142
+ layerInspect: flag(args?.layer_inspect),
143
+ autoBedLeveling: int(args?.auto_bed_leveling, "auto_bed_leveling"),
144
+ autoFlowCali: int(args?.auto_flow_cali, "auto_flow_cali"),
145
+ autoOffsetCali: int(args?.auto_offset_cali, "auto_offset_cali"),
146
+ extruderCaliManualMode: int(args?.extruder_cali_manual_mode, "extruder_cali_manual_mode"),
147
+ };
148
+ return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
149
+ }
126
150
  // X2D uses the same project_file/ams_mapping2 family of LAN print fields as
127
151
  // the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
128
152
  // jobs take the correct branch instead of the legacy 5-slot mapping.
@@ -1231,6 +1255,8 @@ class BambuPrinterMCPServer {
1231
1255
  return withPrinterOperation(devIp, devId, assertActive => withPrintSnapshot(threeMFPath, async (snapshot, retainForDispatchedUpload) => {
1232
1256
  const inspection = await inspectPrintFile(snapshot, { model: printModel, nozzleDiameters: printNozzles, plateIndex, bedType: printBedType });
1233
1257
  const resumeFile = await checkedFile(inspection, snapshot);
1258
+ // The options Bambu Studio's Send dialog would send; explicit ones win.
1259
+ const studio = resolveStudioPrintOptions(printModel, callerPrintOptions(args), { usedNozzles: usedNozzleCount(inspection) });
1234
1260
  let mapping = finalAmsMapping?.slice();
1235
1261
  if (finalAmsSlots) {
1236
1262
  if (finalAmsSlots.length !== inspection.usedFilamentPositions.length)
@@ -1295,18 +1321,18 @@ class BambuPrinterMCPServer {
1295
1321
  use_ssl_for_mqtt: args?.use_ssl_for_mqtt !== undefined ? Boolean(args.use_ssl_for_mqtt) : true,
1296
1322
  username: String(args?.username || "bblp"),
1297
1323
  password,
1298
- task_bed_leveling: args?.bed_leveling !== undefined ? Boolean(args.bed_leveling) : true,
1299
- task_flow_cali: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : true,
1300
- task_vibration_cali: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : true,
1301
- task_layer_inspect: args?.layer_inspect !== undefined ? Boolean(args.layer_inspect) : false,
1324
+ task_bed_leveling: studio.task_bed_leveling,
1325
+ task_flow_cali: studio.task_flow_cali,
1326
+ task_vibration_cali: studio.task_vibration_cali,
1327
+ task_layer_inspect: studio.task_layer_inspect,
1302
1328
  task_record_timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : false,
1303
1329
  task_use_ams: useAMS,
1304
1330
  task_bed_type: printBedType,
1305
1331
  extra_options: stringifyBridgeJson(args?.extra_options) || "",
1306
- auto_bed_leveling: args?.auto_bed_leveling !== undefined ? Number(args.auto_bed_leveling) : 0,
1307
- auto_flow_cali: args?.auto_flow_cali !== undefined ? Number(args.auto_flow_cali) : 0,
1308
- auto_offset_cali: args?.auto_offset_cali !== undefined ? Number(args.auto_offset_cali) : 0,
1309
- extruder_cali_manual_mode: args?.extruder_cali_manual_mode !== undefined ? Number(args.extruder_cali_manual_mode) : -1,
1332
+ auto_bed_leveling: studio.auto_bed_leveling,
1333
+ auto_flow_cali: studio.auto_flow_cali,
1334
+ auto_offset_cali: studio.auto_offset_cali,
1335
+ extruder_cali_manual_mode: studio.extruder_cali_manual_mode,
1310
1336
  task_ext_change_assist: args?.external_change_assist !== undefined ? Boolean(args.external_change_assist) : false,
1311
1337
  try_emmc_print: args?.try_emmc_print !== undefined ? Boolean(args.try_emmc_print) : false,
1312
1338
  };
@@ -1328,6 +1354,10 @@ class BambuPrinterMCPServer {
1328
1354
  flowCalibration: params.task_flow_cali,
1329
1355
  vibrationCalibration: params.task_vibration_cali,
1330
1356
  layerInspect: params.task_layer_inspect,
1357
+ autoBedLeveling: studio.auto_bed_leveling,
1358
+ autoFlowCali: studio.auto_flow_cali,
1359
+ autoOffsetCali: studio.auto_offset_cali,
1360
+ extruderCaliManualMode: studio.extruder_cali_manual_mode,
1331
1361
  timelapse: params.task_record_timelapse,
1332
1362
  externalStorage,
1333
1363
  }, native.onUpdate, { signal: native.signal, assertActive, beforeDispatch: async () => {
@@ -2150,10 +2180,10 @@ class BambuPrinterMCPServer {
2150
2180
  ams_mapping_info: { type: "string", description: "Raw JSON string for FULU PrintParams ams_mapping_info, matching OrcaSlicer-bambulab's detailed AMS mapping field." },
2151
2181
  nozzle_mapping: { type: "string", description: "Raw JSON string for FULU PrintParams nozzle_mapping." },
2152
2182
  nozzles_info: { type: "string", description: "Raw JSON string for FULU PrintParams nozzles_info." },
2153
- bed_leveling: { type: "boolean", description: "Enable auto bed leveling in FULU PrintParams (default: true)." },
2154
- flow_calibration: { type: "boolean", description: "Enable flow calibration in FULU PrintParams (default: true)." },
2155
- vibration_calibration: { type: "boolean", description: "Enable vibration calibration in FULU PrintParams (default: true)." },
2156
- layer_inspect: { type: "boolean", description: "Enable first-layer inspection where supported (default: false for BambuNetwork bridge)." },
2183
+ bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
2184
+ flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
2185
+ vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
2186
+ layer_inspect: { type: "boolean", description: "First-layer inspection where supported (default true, as Bambu Studio sends)." },
2157
2187
  timelapse: { type: "boolean", description: "Enable timelapse recording in FULU PrintParams (default: false)." },
2158
2188
  use_ssl_for_ftp: { type: "boolean", description: "Whether FULU local print should use SSL for FTP (default: true)." },
2159
2189
  use_ssl_for_mqtt: { type: "boolean", description: "Whether FULU local print should use SSL for MQTT (default: true)." },
@@ -2585,9 +2615,9 @@ class BambuPrinterMCPServer {
2585
2615
  type: "boolean",
2586
2616
  description: "When true, match the sliced 3MF's tray_info_idx requirements against live AMS inventory and use the resulting ams_slots. Ignored when ams_mapping or ams_slots is provided."
2587
2617
  },
2588
- bed_leveling: { type: "boolean", description: "Enable auto bed leveling (default: true)" },
2589
- flow_calibration: { type: "boolean", description: "Enable flow calibration (default: true)" },
2590
- vibration_calibration: { type: "boolean", description: "Enable vibration calibration (default: true)" },
2618
+ bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
2619
+ flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
2620
+ vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
2591
2621
  timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
2592
2622
  slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
2593
2623
  template_3mf_path: { type: "string", description: "Optional template 3MF whose embedded Bambu slicer settings should be reused when auto-slicing this print job." },
@@ -2621,9 +2651,9 @@ class BambuPrinterMCPServer {
2621
2651
  enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
2622
2652
  description: "Bed plate type currently installed (default: textured_plate)"
2623
2653
  },
2624
- bed_leveling: { type: "boolean", description: "Enable auto bed leveling (default: true)" },
2625
- flow_calibration: { type: "boolean", description: "Enable flow calibration (default: true)" },
2626
- vibration_calibration: { type: "boolean", description: "Enable vibration calibration (default: true)" },
2654
+ bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
2655
+ flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
2656
+ vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
2627
2657
  timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
2628
2658
  slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
2629
2659
  nozzle_diameter: { type: "string", description: "Nozzle diameter in mm for auto-slicing (default: 0.4)" }
@@ -3749,10 +3779,7 @@ class BambuPrinterMCPServer {
3749
3779
  amsMapping: finalAmsMapping,
3750
3780
  amsSlots: finalAmsSlots,
3751
3781
  bedType: printBedType,
3752
- bedLeveling: args?.bed_leveling !== undefined ? Boolean(args.bed_leveling) : undefined,
3753
- flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : undefined,
3754
- vibrationCalibration: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : undefined,
3755
- layerInspect: args?.layer_inspect !== undefined ? Boolean(args.layer_inspect) : undefined,
3782
+ ...callerPrintOptions(args),
3756
3783
  timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : undefined,
3757
3784
  });
3758
3785
  // Report what the printer did, not merely that a command was published.
@@ -3786,9 +3813,7 @@ class BambuPrinterMCPServer {
3786
3813
  useAMS: true,
3787
3814
  amsSlots: collarAnalysis.amsSlots,
3788
3815
  bedType: printBedType,
3789
- bedLeveling: args?.bed_leveling !== undefined ? Boolean(args.bed_leveling) : true,
3790
- flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : true,
3791
- vibrationCalibration: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : true,
3816
+ ...callerPrintOptions(args),
3792
3817
  timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : false,
3793
3818
  });
3794
3819
  result = {
@@ -13,6 +13,11 @@ interface BambuPrintOptionsInternal {
13
13
  flowCalibration?: boolean;
14
14
  vibrationCalibration?: boolean;
15
15
  layerInspect?: boolean;
16
+ /** Explicit Studio option values (0 off, 1 on, 2 auto); see studio-print-options.ts. */
17
+ autoBedLeveling?: number;
18
+ autoFlowCali?: number;
19
+ autoOffsetCali?: number;
20
+ extruderCaliManualMode?: number;
16
21
  timelapse?: boolean;
17
22
  amsMapping?: number[];
18
23
  /**
@@ -12,6 +12,7 @@ import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, d
12
12
  import { describeHmsKey, hiddenHmsKeys, hiddenHmsNotices, reportedHmsKey, unchippedNozzles, validatePrinterState, manualHeatingRequirements } from "../safety/printer-state.js";
13
13
  import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRemotePath, cancelPendingPrinterOperations } from "../safety/artifact.js";
14
14
  import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
15
+ import { resolveStudioPrintOptions, usedNozzleCount } from "../studio-print-options.js";
15
16
  import { Client as FTPClient } from "basic-ftp";
16
17
  import * as mqtt from "mqtt";
17
18
  import { BambuClient, GCodeFileCommand, GCodeLineCommand, PushAllCommand, UpdateFanCommand, UpdateLightCommand, UpdateStateCommand, } from "bambu-node";
@@ -37,6 +38,36 @@ function loadClientCreds() {
37
38
  }
38
39
  const CLIENT_CREDS = loadClientCreds();
39
40
  const COMMAND_SETTLE_MS = 300;
41
+ /** How long a stop waits for the printer's MQTT PUBACK before its client is closed (BAMBU_STOP_ACK_MS for tests). */
42
+ const stopAckMs = () => { const value = Number(process.env.BAMBU_STOP_ACK_MS); return Number.isInteger(value) && value > 0 ? value : 10000; };
43
+ /**
44
+ * Publish JSON exactly as Bambu Studio's MachineObject::publish_json does
45
+ * (DeviceManager.cpp:2462): the given message on device/<serial>/request at the
46
+ * given QoS. With QoS 1 it resolves on the printer's PUBACK. bambu-node's own
47
+ * publish has no QoS (MQTT.js defaults to 0).
48
+ */
49
+ function publishStudioJson(client, message, qos) {
50
+ const mqttClient = client.mqttClient;
51
+ const serial = client.config?.serialNumber;
52
+ if (!mqttClient || typeof mqttClient.publish !== "function" || typeof serial !== "string")
53
+ return client.publish(message);
54
+ return new Promise((resolve, reject) => {
55
+ mqttClient.publish(`device/${serial}/request`, JSON.stringify(message), { qos }, (error) => {
56
+ if (error)
57
+ reject(new Error(`Error publishing to device/${serial}/request: ${error.message}`));
58
+ else
59
+ resolve();
60
+ });
61
+ });
62
+ }
63
+ /**
64
+ * Bambu Studio's stop, MachineObject::command_task_abort (DeviceManager.cpp:1418-1426):
65
+ * {"print":{"command":"stop","param":"","sequence_id":"<n>"}} at QoS 1. bambu-node's
66
+ * UpdateStateCommand sends no param, at QoS 0.
67
+ */
68
+ const studioStopCommand = {
69
+ invoke: (client) => publishStudioJson(client, { print: { command: "stop", param: "", sequence_id: String(Date.now()) } }, 1),
70
+ };
40
71
  /** A cached report older than this may be refreshed once with PushAll; see readProgressReport. */
41
72
  const STALE_REPORT_MS = 300000;
42
73
  /** HMS 0500-0500-0001-0007: firmware 01.08.05+ rejected an unsigned MQTT command. */
@@ -844,6 +875,13 @@ export class BambuImplementation {
844
875
  model, nozzleDiameters: options.nozzleDiameters, plateIndex: options.plateIndex ?? 0, bedType: options.bedType,
845
876
  });
846
877
  const resumeFile = await checkedFile(inspection, options.filePath);
878
+ // The options Bambu Studio's Send dialog would send; explicit ones win.
879
+ const studio = resolveStudioPrintOptions(model, {
880
+ bedLeveling: options.bedLeveling, flowCalibration: options.flowCalibration,
881
+ vibrationCalibration: options.vibrationCalibration, layerInspect: options.layerInspect,
882
+ autoBedLeveling: options.autoBedLeveling, autoFlowCali: options.autoFlowCali,
883
+ autoOffsetCali: options.autoOffsetCali, extruderCaliManualMode: options.extruderCaliManualMode,
884
+ }, { usedNozzles: usedNozzleCount(inspection) });
847
885
  const projectMetadata = await this.resolveProjectFileMetadata(options.filePath, options.plateIndex, inspection.plateInternalPath);
848
886
  // Send project_file command via bambu-node MQTT (bypasses bambu-js
849
887
  // hardcoded use_ams=true and missing ams_mapping support)
@@ -1005,16 +1043,21 @@ export class BambuImplementation {
1005
1043
  md5,
1006
1044
  bed_type: options.bedType || "auto",
1007
1045
  timelapse: b(options.timelapse),
1008
- bed_leveling: b(options.bedLeveling ?? true),
1009
- auto_bed_leveling: 1,
1010
- flow_cali: b(options.flowCalibration ?? false),
1011
- vibration_cali: b(options.vibrationCalibration ?? true),
1012
- layer_inspect: b(options.layerInspect ?? false),
1046
+ bed_leveling: b(studio.task_bed_leveling),
1047
+ auto_bed_leveling: studio.auto_bed_leveling,
1048
+ // No verified project_file field requests automatic flow calibration
1049
+ // (Studio's PrintParams auto_flow_cali reaches the printer through the
1050
+ // plug-in, whose MQTT form is not public), so "auto" sends 0 as before,
1051
+ // and extrude_cali_flag keeps its existing 0. The bridge and native
1052
+ // routes carry auto_flow_cali.
1053
+ flow_cali: b(studio.task_flow_cali),
1054
+ vibration_cali: b(studio.task_vibration_cali),
1055
+ layer_inspect: b(studio.task_layer_inspect),
1013
1056
  use_ams: options.useAMS !== false,
1014
1057
  cfg: "0",
1015
1058
  extrude_cali_flag: 0,
1016
- extrude_cali_manual_mode: 0,
1017
- nozzle_offset_cali: 2,
1059
+ extrude_cali_manual_mode: studio.extruder_cali_manual_mode,
1060
+ nozzle_offset_cali: studio.auto_offset_cali,
1018
1061
  subtask_name: subtaskName,
1019
1062
  profile_id: "0",
1020
1063
  project_id: submissionId,
@@ -1033,10 +1076,10 @@ export class BambuImplementation {
1033
1076
  url: projectUrl,
1034
1077
  subtask_name: subtaskName,
1035
1078
  md5,
1036
- flow_cali: options.flowCalibration ?? true,
1037
- layer_inspect: options.layerInspect ?? true,
1038
- vibration_cali: options.vibrationCalibration ?? true,
1039
- bed_leveling: options.bedLeveling ?? true,
1079
+ flow_cali: studio.task_flow_cali,
1080
+ layer_inspect: studio.task_layer_inspect,
1081
+ vibration_cali: studio.task_vibration_cali,
1082
+ bed_leveling: studio.task_bed_leveling,
1040
1083
  bed_type: options.bedType || "textured_plate",
1041
1084
  timelapse: options.timelapse ?? false,
1042
1085
  use_ams: options.useAMS !== false,
@@ -1083,10 +1126,23 @@ export class BambuImplementation {
1083
1126
  try {
1084
1127
  if (dispatch)
1085
1128
  return await dispatch();
1086
- else
1087
- await invokeWithoutAck(printer, new UpdateStateCommand({ state: "stop" }));
1129
+ // A stop with no PUBACK must not stay queued in MQTT.js and reach a later job.
1130
+ const ackMs = stopAckMs();
1131
+ const deadline = new AbortController();
1132
+ const timer = setTimeout(() => deadline.abort(Object.assign(new Error("stop not acknowledged"), { name: "TimeoutError" })), ackMs);
1133
+ try {
1134
+ await this.invokeEmergencyCommand(printer, studioStopCommand, deadline.signal);
1135
+ }
1136
+ catch (error) {
1137
+ if (error?.name === "TimeoutError")
1138
+ throw new Error(`The printer did not acknowledge the stop within ${ackMs / 1000} s; its MQTT client was closed so the stop cannot be sent late. Check the printer.`);
1139
+ throw error;
1140
+ }
1141
+ finally {
1142
+ clearTimeout(timer);
1143
+ }
1088
1144
  this.checkedJobs.delete(`${host}\n${serial}`);
1089
- return { status: "success", message: "Cancel command sent successfully." };
1145
+ return { status: "success", message: "Stop sent and acknowledged by the printer (MQTT QoS 1), as Bambu Studio sends it. Check get_printer_status to confirm the job stopped." };
1090
1146
  }
1091
1147
  catch (error) {
1092
1148
  throw new Error(`Failed to cancel print: ${error.message}`);
@@ -1124,8 +1180,8 @@ export class BambuImplementation {
1124
1180
  signal?.throwIfAborted();
1125
1181
  const printer = await this.getPrinter(host, serial, token);
1126
1182
  signal?.throwIfAborted();
1127
- await this.invokeEmergencyCommand(printer, new UpdateStateCommand({ state: "stop" }), signal);
1128
- return { status: "success", message: "Cancel command sent over MQTT." };
1183
+ await this.invokeEmergencyCommand(printer, studioStopCommand, signal);
1184
+ return { status: "success", message: "Stop sent over MQTT and acknowledged by the printer (QoS 1)." };
1129
1185
  }
1130
1186
  /** Raw MQTT heater-off; switching off needs no material or model declaration. */
1131
1187
  async sendHeaterOffOverMqtt(host, serial, token, heater, signal) {
@@ -1264,7 +1320,7 @@ export class BambuImplementation {
1264
1320
  ]);
1265
1321
  const confirmedJob = jobIdentity(initialStatus.raw);
1266
1322
  const jobName = initialStatus.raw.subtask_name || initialStatus.raw.gcode_file;
1267
- await this.confirmHardwareAction(`Clear reported hardware errors on ${serial}: ${codes.map(describeHmsKey).join(", ")}?${jobName ? ` Current job: ${String(jobName)}.` : ""} Inspect the printer and resolve the physical cause first. Confirm only after removing obstructions and correcting the fault.`, true);
1323
+ await this.confirmHardwareAction(`Clear reported hardware errors on ${serial}: ${codes.map(describeHmsKey).join(", ")}?${jobName ? ` Current job: ${String(jobName)}.` : ""} Inspect the printer and resolve the physical cause first. Confirm only after correcting the fault.`, true);
1268
1324
  const beforeDispatch = async () => {
1269
1325
  assertActive();
1270
1326
  const currentStatus = await this.getSafetyStatus(host, serial, token);
@@ -0,0 +1,2 @@
1
+ /** Bambu Studio's downloaded text for a 16-hex HMS code or an 8-hex print_error code, by serial prefix, else from hms_en.json. */
2
+ export declare function studioDownloadedText(kind: "hms" | "error", code: string, serial: string): string | undefined;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * HMS and print-error text from the user's own Bambu Studio download, for
3
+ * codes the tables bundled at the pinned Studio tag lack (it bundles no P1,
4
+ * X1 or A1 table). Bambu Studio downloads hms_en_<serial prefix>.json and
5
+ * hms_en.json into an hms folder next to BambuStudio.conf; this reads them
6
+ * read-only and returns Bambu's text unchanged, with no advice added. The
7
+ * files are Bambu's and are never copied or redistributed.
8
+ */
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { studioConfigPath } from "./studio-print-options.js";
12
+ const cache = new Map();
13
+ function entries(value) {
14
+ const map = new Map();
15
+ if (!Array.isArray(value))
16
+ return map;
17
+ for (const entry of value) {
18
+ const code = typeof entry?.ecode === "string" ? entry.ecode.trim().toUpperCase() : "";
19
+ const text = typeof entry?.intro === "string" ? entry.intro.trim() : "";
20
+ if (/^[0-9A-F]{8}([0-9A-F]{8})?$/.test(code) && text)
21
+ map.set(code, text);
22
+ }
23
+ return map;
24
+ }
25
+ function load(file) {
26
+ let stat;
27
+ try {
28
+ stat = fs.statSync(file);
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ if (!stat.isFile() || stat.size > 32 * 1024 * 1024)
34
+ return undefined;
35
+ const cached = cache.get(file);
36
+ if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size)
37
+ return cached.table;
38
+ let table;
39
+ try {
40
+ const data = JSON.parse(fs.readFileSync(file, "utf8"))?.data;
41
+ table = { hms: entries(data?.device_hms?.en), error: entries(data?.device_error?.en) };
42
+ }
43
+ catch {
44
+ table = undefined;
45
+ }
46
+ cache.set(file, { mtimeMs: stat.mtimeMs, size: stat.size, table });
47
+ return table;
48
+ }
49
+ /** Bambu Studio's downloaded text for a 16-hex HMS code or an 8-hex print_error code, by serial prefix, else from hms_en.json. */
50
+ export function studioDownloadedText(kind, code, serial) {
51
+ const config = studioConfigPath();
52
+ if (!config)
53
+ return undefined;
54
+ const directory = path.join(path.dirname(config), "hms");
55
+ const prefix = serial.trim().toUpperCase().slice(0, 3);
56
+ const files = [...(/^[0-9A-Z]{3}$/.test(prefix) ? [`hms_en_${prefix}.json`] : []), "hms_en.json"];
57
+ for (const name of files) {
58
+ const text = load(path.join(directory, name))?.[kind].get(code.toUpperCase());
59
+ if (text)
60
+ return text;
61
+ }
62
+ return undefined;
63
+ }
@@ -0,0 +1,57 @@
1
+ export type StudioOptionValue = "off" | "on" | "auto";
2
+ export type StudioOptionSource = "caller" | "studio-config" | "studio-default";
3
+ /** Explicit caller choices; each one wins over Studio's resolution. */
4
+ export type CallerPrintOptions = {
5
+ bedLeveling?: boolean;
6
+ flowCalibration?: boolean;
7
+ vibrationCalibration?: boolean;
8
+ layerInspect?: boolean;
9
+ /** 0 off, 1 on, 2 auto, as Studio's getValueInt. */
10
+ autoBedLeveling?: number;
11
+ autoFlowCali?: number;
12
+ autoOffsetCali?: number;
13
+ extruderCaliManualMode?: number;
14
+ };
15
+ export type StudioPrintOptions = {
16
+ printerType?: string;
17
+ values: {
18
+ bed_leveling: StudioOptionValue;
19
+ flow_cali: StudioOptionValue;
20
+ nozzle_offset_cali: StudioOptionValue;
21
+ };
22
+ sources: {
23
+ bed_leveling: StudioOptionSource;
24
+ flow_cali: StudioOptionSource;
25
+ nozzle_offset_cali: StudioOptionSource;
26
+ };
27
+ task_bed_leveling: boolean;
28
+ task_flow_cali: boolean;
29
+ task_vibration_cali: boolean;
30
+ task_layer_inspect: boolean;
31
+ auto_bed_leveling: number;
32
+ auto_flow_cali: number;
33
+ auto_offset_cali: number;
34
+ extruder_cali_manual_mode: number;
35
+ };
36
+ /** Where Studio keeps BambuStudio.conf; BAMBU_STUDIO_CONFIG overrides it (empty: none). */
37
+ export declare function studioConfigPath(): string | undefined;
38
+ /**
39
+ * The Send dialog options Studio saved for a printer type, and nothing else:
40
+ * BambuStudio.conf also holds access codes, so only that one section is kept,
41
+ * and a parse failure is reported without any of the file's text.
42
+ */
43
+ export declare function readStudioSavedOptions(printerTypes: string[], configPath: string | undefined): Record<string, string> | undefined;
44
+ /**
45
+ * What Studio's Send dialog would send for this model, with the caller's
46
+ * explicit choices taking precedence. usedNozzles is the number of nozzles the
47
+ * job uses, for dual-nozzle printers.
48
+ */
49
+ export declare function resolveStudioPrintOptions(model: string, caller?: CallerPrintOptions, options?: {
50
+ usedNozzles?: number;
51
+ configPath?: string;
52
+ }): StudioPrintOptions;
53
+ /** The number of nozzles a job's used filaments print from, when the inspection knows. */
54
+ export declare function usedNozzleCount(inspection: {
55
+ usedFilamentPositions: number[];
56
+ filamentNozzleIndices?: Array<number | undefined>;
57
+ }): number | undefined;