bambu-printer-mcp 1.1.80 → 1.1.81

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
@@ -1550,3 +1550,7 @@ Thank you to **[FULU Foundation](https://www.fulu.org/), [Louis Rossmann](https:
1550
1550
  Some printer command surfaces and workflow priorities were informed by [Bambuddy](https://github.com/maziggy/bambuddy), an AGPL-3.0 Bambu Lab printer management project. This project does not vendor Bambuddy code.
1551
1551
 
1552
1552
  </details>
1553
+
1554
+ ### Print dispatch truth (`counterpart/1`)
1555
+
1556
+ An error from `print_3mf` or `upload_gcode` carries `structuredContent.printOutcome`: `not-sent` means no print command was handed to a transport (including fresh-report timeouts, preparation failures and upload failures); `unknown` means a command may have reached the printer; `rejected` means the printer refused the command. A file upload alone is not a print command. Clients use this field, never error wording or firmware codes, to distinguish “Not started” from a print that needs checking. Missing or unrecognized values cannot prove nothing was sent. Other structured error fields remain compatible.
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
51
51
  import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
52
52
  import { parseProcessOverrides } from "./slicer/process-overrides.js";
53
53
  import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
54
- import { PrinterRefusal } from "./refusal.js";
54
+ import { PrinterRefusal, withPrintDispatch, markPrintCommandSent, printOutcome } from "./refusal.js";
55
55
  import { uploadProgressReporter } from "./upload-progress.js";
56
56
  import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
57
57
  dotenv.config();
@@ -1551,6 +1551,7 @@ class BambuPrinterMCPServer {
1551
1551
  throw new Error("The printer's SD card or USB stick is no longer ready. Check it and start the print again.");
1552
1552
  }
1553
1553
  assertActive();
1554
+ markPrintCommandSent();
1554
1555
  } });
1555
1556
  assertActive();
1556
1557
  this.bambu.recordCheckedJob(devIp, devId, remoteFileName, requirements, resumeFile, false);
@@ -1566,8 +1567,10 @@ class BambuPrinterMCPServer {
1566
1567
  validatePrinterState(dispatchStatus, requirements);
1567
1568
  this.bambu.assertPrintPreflight(dispatchStatus, preflight);
1568
1569
  },
1569
- assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
1570
- assertActive(); },
1570
+ assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) {
1571
+ assertActive();
1572
+ markPrintCommandSent();
1573
+ } },
1571
1574
  onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
1572
1575
  retainForDispatchedUpload(); },
1573
1576
  };
@@ -3197,7 +3200,7 @@ class BambuPrinterMCPServer {
3197
3200
  };
3198
3201
  });
3199
3202
  // A designer's settings extracted for this call are removed when it settles.
3200
- this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
3203
+ this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withPrintDispatch(() => withExtractedSettingsCleanup(async () => {
3201
3204
  const { name, arguments: args } = request.params;
3202
3205
  const sendNativeCommand = (options, execution = {}) => sendCommandWithBambuNative(options, { signal: extra.signal, ...execution });
3203
3206
  const progressToken = extra._meta?.progressToken;
@@ -4420,7 +4423,7 @@ class BambuPrinterMCPServer {
4420
4423
  : `Check parameters and try again. Error: ${message}`,
4421
4424
  message,
4422
4425
  tool: name,
4423
- ...(error instanceof PrinterRefusal ? { code: error.code } : {}),
4426
+ ...(error instanceof PrinterRefusal ? { code: error.code } : {}), ...(["print_3mf", "upload_gcode"].includes(name) ? { printOutcome: printOutcome(error) } : {}),
4424
4427
  // The slicer's own result.json; the message starts with its error_string and warnings.
4425
4428
  // A slicer failure always carries slicer_report: the plain sentence a person sees, the slicer's words for the log.
4426
4429
  // The report always says failed (a result.json that says success can still leave no output file).
@@ -4438,7 +4441,7 @@ class BambuPrinterMCPServer {
4438
4441
  isError: true,
4439
4442
  };
4440
4443
  }
4441
- }));
4444
+ })));
4442
4445
  }
4443
4446
  async startStdio() {
4444
4447
  const transport = new StdioServerTransport();
@@ -1,4 +1,4 @@
1
- import { PrinterRefusal } from "../refusal.js";
1
+ import { PrinterRefusal, markPrintCommandSent } from "../refusal.js";
2
2
  import { CameraStreams } from "./camera-stream.js";
3
3
  import { openTcpCameraSource, openRtspCameraSource } from "./camera-sources.js";
4
4
  import { cameraNumber } from "./camera-tools.js";
@@ -1106,6 +1106,7 @@ export class BambuImplementation {
1106
1106
  assertActive();
1107
1107
  if (legacyContainer) {
1108
1108
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
1109
+ markPrintCommandSent();
1109
1110
  try {
1110
1111
  await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remoteProjectPath }));
1111
1112
  }
@@ -1192,6 +1193,7 @@ export class BambuImplementation {
1192
1193
  };
1193
1194
  }
1194
1195
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
1196
+ markPrintCommandSent();
1195
1197
  try {
1196
1198
  await printer.publish(projectFileCmd);
1197
1199
  }
@@ -1797,6 +1799,7 @@ export class BambuImplementation {
1797
1799
  const printer = await this.getPrinter(host, serial, token);
1798
1800
  assertActive();
1799
1801
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
1802
+ markPrintCommandSent();
1800
1803
  try {
1801
1804
  await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remotePath }));
1802
1805
  }
package/dist/refusal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
3
- * such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
4
- * firmware details change with the printer). Neither one starts a print.
2
+ * A printer refusal with a stable diagnostic code, retained for existing clients.
3
+ * Counterpart uses structuredContent.printOutcome for dispatch truth, never
4
+ * these firmware-specific codes or the message.
5
5
  *
6
6
  * - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
7
7
  * MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
@@ -14,3 +14,9 @@ export declare class PrinterRefusal extends Error {
14
14
  readonly code: RefusalCode;
15
15
  constructor(code: RefusalCode, message: string);
16
16
  }
17
+ /** counterpart/1 dispatch-tool errors describe dispatch truth independently of firmware-specific codes. */
18
+ export type PrintOutcome = "not-sent" | "unknown" | "rejected";
19
+ export declare function withPrintDispatch<T>(run: () => T): T;
20
+ /** Call immediately before handing a print command to a transport. An acknowledgement may then be lost. */
21
+ export declare function markPrintCommandSent(): void;
22
+ export declare function printOutcome(error: unknown): PrintOutcome;
package/dist/refusal.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
1
2
  /**
2
- * A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
3
- * such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
4
- * firmware details change with the printer). Neither one starts a print.
3
+ * A printer refusal with a stable diagnostic code, retained for existing clients.
4
+ * Counterpart uses structuredContent.printOutcome for dispatch truth, never
5
+ * these firmware-specific codes or the message.
5
6
  *
6
7
  * - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
7
8
  * MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
@@ -16,3 +17,18 @@ export class PrinterRefusal extends Error {
16
17
  this.name = "PrinterRefusal";
17
18
  }
18
19
  }
20
+ const printDispatch = new AsyncLocalStorage();
21
+ export function withPrintDispatch(run) {
22
+ return printDispatch.run({ attempted: false }, run);
23
+ }
24
+ /** Call immediately before handing a print command to a transport. An acknowledgement may then be lost. */
25
+ export function markPrintCommandSent() {
26
+ const dispatch = printDispatch.getStore();
27
+ if (dispatch)
28
+ dispatch.attempted = true;
29
+ }
30
+ export function printOutcome(error) {
31
+ if (error instanceof PrinterRefusal && error.code === "printer-command-rejected")
32
+ return "rejected";
33
+ return printDispatch.getStore()?.attempted === false ? "not-sent" : "unknown";
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.80",
3
+ "version": "1.1.81",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -82,7 +82,7 @@ import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
82
82
  import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
83
83
  import { parseProcessOverrides } from "./slicer/process-overrides.js";
84
84
  import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
85
- import { PrinterRefusal } from "./refusal.js";
85
+ import { PrinterRefusal, withPrintDispatch, markPrintCommandSent, printOutcome } from "./refusal.js";
86
86
  import { uploadProgressReporter } from "./upload-progress.js";
87
87
  import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
88
88
 
@@ -1951,6 +1951,7 @@ class BambuPrinterMCPServer {
1951
1951
  throw new Error("The printer's SD card or USB stick is no longer ready. Check it and start the print again.");
1952
1952
  }
1953
1953
  assertActive();
1954
+ markPrintCommandSent();
1954
1955
  } });
1955
1956
  assertActive();
1956
1957
  this.bambu.recordCheckedJob(devIp, devId, remoteFileName, requirements, resumeFile, false);
@@ -1965,7 +1966,7 @@ class BambuPrinterMCPServer {
1965
1966
  validatePrinterState(dispatchStatus, requirements);
1966
1967
  this.bambu.assertPrintPreflight(dispatchStatus, preflight);
1967
1968
  },
1968
- assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) assertActive(); },
1969
+ assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) { assertActive(); markPrintCommandSent(); } },
1969
1970
  onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod) retainForDispatchedUpload(); },
1970
1971
  };
1971
1972
  let jobUpdates: BridgeJobUpdate[] = [];
@@ -3709,7 +3710,7 @@ class BambuPrinterMCPServer {
3709
3710
  });
3710
3711
 
3711
3712
  // A designer's settings extracted for this call are removed when it settles.
3712
- this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
3713
+ this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withPrintDispatch(() => withExtractedSettingsCleanup(async () => {
3713
3714
  const { name, arguments: args } = request.params;
3714
3715
  const sendNativeCommand = (
3715
3716
  options: Parameters<typeof sendCommandWithBambuNative>[0],
@@ -5155,7 +5156,7 @@ class BambuPrinterMCPServer {
5155
5156
  : `Check parameters and try again. Error: ${message}`,
5156
5157
  message,
5157
5158
  tool: name,
5158
- ...(error instanceof PrinterRefusal ? { code: error.code } : {}),
5159
+ ...(error instanceof PrinterRefusal ? { code: error.code } : {}), ...(["print_3mf", "upload_gcode"].includes(name) ? { printOutcome: printOutcome(error) } : {}),
5159
5160
  // The slicer's own result.json; the message starts with its error_string and warnings.
5160
5161
  // A slicer failure always carries slicer_report: the plain sentence a person sees, the slicer's words for the log.
5161
5162
  // The report always says failed (a result.json that says success can still leave no output file).
@@ -5174,7 +5175,7 @@ class BambuPrinterMCPServer {
5174
5175
  isError: true,
5175
5176
  };
5176
5177
  }
5177
- }));
5178
+ })));
5178
5179
  }
5179
5180
 
5180
5181
  async startStdio() {
@@ -1,4 +1,4 @@
1
- import { PrinterRefusal } from "../refusal.js";
1
+ import { PrinterRefusal, markPrintCommandSent } from "../refusal.js";
2
2
  import {CameraStreams, type FrameOptions} from "./camera-stream.js";
3
3
  import {openTcpCameraSource, openRtspCameraSource} from "./camera-sources.js";
4
4
  import {cameraNumber} from "./camera-tools.js";
@@ -1273,6 +1273,7 @@ export class BambuImplementation {
1273
1273
  assertActive();
1274
1274
  if (legacyContainer) {
1275
1275
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
1276
+ markPrintCommandSent();
1276
1277
  try { await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remoteProjectPath })); } catch (error) { watcher.dispose(); throw error; }
1277
1278
  this.recordCheckedJob(host, serial, remoteProjectPath, requirements, resumeFile);
1278
1279
  const dispatch = await watcher.settled();
@@ -1354,6 +1355,7 @@ export class BambuImplementation {
1354
1355
  }
1355
1356
 
1356
1357
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
1358
+ markPrintCommandSent();
1357
1359
  try { await printer.publish(projectFileCmd); } catch (error) { watcher.dispose(); throw error; }
1358
1360
  this.recordCheckedJob(host, serial, remoteProjectPath, requirements, resumeFile);
1359
1361
  await new Promise((resolve) => setTimeout(resolve, 300));
@@ -2014,6 +2016,7 @@ export class BambuImplementation {
2014
2016
  const printer = await this.getPrinter(host, serial, token);
2015
2017
  assertActive();
2016
2018
  const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
2019
+ markPrintCommandSent();
2017
2020
  try { await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remotePath })); } catch (error) { watcher.dispose(); throw error; }
2018
2021
  this.recordCheckedJob(host, serial, remotePath, requirements, resumeFile);
2019
2022
  const dispatch = await watcher.settled();
package/src/refusal.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
1
3
  /**
2
- * A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
3
- * such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
4
- * firmware details change with the printer). Neither one starts a print.
4
+ * A printer refusal with a stable diagnostic code, retained for existing clients.
5
+ * Counterpart uses structuredContent.printOutcome for dispatch truth, never
6
+ * these firmware-specific codes or the message.
5
7
  *
6
8
  * - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
7
9
  * MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
@@ -17,3 +19,19 @@ export class PrinterRefusal extends Error {
17
19
  this.name = "PrinterRefusal";
18
20
  }
19
21
  }
22
+
23
+ /** counterpart/1 dispatch-tool errors describe dispatch truth independently of firmware-specific codes. */
24
+ export type PrintOutcome = "not-sent" | "unknown" | "rejected";
25
+ const printDispatch = new AsyncLocalStorage<{ attempted: boolean }>();
26
+ export function withPrintDispatch<T>(run: () => T): T {
27
+ return printDispatch.run({ attempted: false }, run);
28
+ }
29
+ /** Call immediately before handing a print command to a transport. An acknowledgement may then be lost. */
30
+ export function markPrintCommandSent(): void {
31
+ const dispatch = printDispatch.getStore();
32
+ if (dispatch) dispatch.attempted = true;
33
+ }
34
+ export function printOutcome(error: unknown): PrintOutcome {
35
+ if (error instanceof PrinterRefusal && error.code === "printer-command-rejected") return "rejected";
36
+ return printDispatch.getStore()?.attempted === false ? "not-sent" : "unknown";
37
+ }