bambu-printer-mcp 1.1.53 → 1.1.55
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 +4 -1
- package/dist/bambu-network-bridge.d.ts +8 -2
- package/dist/bambu-network-bridge.js +25 -3
- package/dist/index.js +31 -12
- package/dist/slicer/process-overrides.d.ts +5 -3
- package/dist/slicer/process-overrides.js +30 -1
- package/package.json +1 -1
- package/src/bambu-network-bridge.ts +25 -3
- package/src/index.ts +30 -12
- package/src/slicer/process-overrides.ts +26 -3
package/README.md
CHANGED
|
@@ -1200,8 +1200,11 @@ When `slicer_type` is `bambustudio` (the default), these additional parameters a
|
|
|
1200
1200
|
| `layer_height` | number | Layer height in mm, such as 0.28, 0.2 or 0.12; at most the nozzle diameter |
|
|
1201
1201
|
| `wall_loops` | integer | Number of walls, 0 to 1000 |
|
|
1202
1202
|
| `sparse_infill_density` | string | Sparse infill density, such as `"15%"` |
|
|
1203
|
+
| `enable_support` | boolean | Turn support generation on or off |
|
|
1204
|
+
| `support_type` | string | `normal(auto)`, `tree(auto)`, `normal(manual)` or `tree(manual)` |
|
|
1205
|
+
| `support_threshold_angle` | integer | Overhang threshold for automatic supports, 0 to 90 degrees (0 lets the slicer decide) |
|
|
1203
1206
|
|
|
1204
|
-
`layer_height`, `wall_loops
|
|
1207
|
+
`layer_height`, `wall_loops`, `sparse_infill_density` and the three support arguments are written as a process override on top of the machine and process preset the tool resolves, using Bambu Studio's keys and string forms (`"0.2"`, `"2"`, `"15%"`). Every other preset value, and the machine preset, stay as resolved, and your own profile files are not changed. They work with every Bambu-compatible slicer, including remote `orca-slicer-api` slicing, and are refused for PrusaSlicer, Slic3r and Cura.
|
|
1205
1208
|
|
|
1206
1209
|
**Example: Slice with auto-orient and 3 copies**
|
|
1207
1210
|
```json
|
|
@@ -193,10 +193,16 @@ export declare class BambuNetworkBridge {
|
|
|
193
193
|
* Shares the LAN session queue: one reader of the plug-in's events at a time.
|
|
194
194
|
*/
|
|
195
195
|
withCloudSession<T>(devId: string, options: BambuNetworkBridgeOptions, assertActive: () => void, timing: Readonly<CloudTiming>, run: (session: CloudSession) => Promise<T>): Promise<T>;
|
|
196
|
-
/**
|
|
197
|
-
|
|
196
|
+
/**
|
|
197
|
+
* A cloud print in a cloud session, so the plug-in has the printer's state. With a fallback this is
|
|
198
|
+
* Bambu Studio's order for a cloud-bound printer it can also reach on the LAN (PrintJob.cpp,
|
|
199
|
+
* SendAttemptRoute::LanWithRecord, then ::Cloud): start_local_print_with_record, then start_print
|
|
200
|
+
* when the first failed before its print command was sent. `firstFailure` is the first method's result.
|
|
201
|
+
*/
|
|
202
|
+
startCloudPrint(devId: string, method: string, payload: JsonObject, options?: BambuNetworkBridgeOptions, assertActive?: () => void, timing?: Readonly<CloudTiming>, fallbackMethod?: string): Promise<{
|
|
198
203
|
result: unknown;
|
|
199
204
|
jobUpdates: BridgeJobUpdate[];
|
|
205
|
+
firstFailure?: number;
|
|
200
206
|
}>;
|
|
201
207
|
/**
|
|
202
208
|
* A print control over Bambu Cloud: how Bambu Studio and FULU's slicer control a printer
|
|
@@ -16,8 +16,16 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 120000;
|
|
|
16
16
|
const LOCAL_CONNECT_STATUS = ["ok", "failed", "lost"];
|
|
17
17
|
// bambu_networking.hpp BAMBU_NETWORK_ERR_PRINT_LP_PUBLISH_MSG_FAILED.
|
|
18
18
|
const LOCAL_PRINT_PUBLISH_FAILED = -4030;
|
|
19
|
+
// A with-record send falls back to start_print only on its own preparation failures (the plug-in's
|
|
20
|
+
// PRINT_WR_* results, -2010 to -2140: project, upload, task record, FTPS), which come before the print
|
|
21
|
+
// command, so the printer has no job. Any other result may have reached the printer and is never
|
|
22
|
+
// replayed. Of those, Studio also stops on a file missing or too large (should_stop_without_fallback).
|
|
23
|
+
const WITH_RECORD_PREPARATION_FAILURE = (value) => value <= -2010 && value >= -2140 && value !== -2040 && value !== -2100;
|
|
19
24
|
// bambu_networking.hpp print errors that name a recoverable cause.
|
|
20
25
|
const BAMBU_NETWORK_PRINT_ERRORS = {
|
|
26
|
+
[-2120]: "Bambu Cloud refused to create the print task",
|
|
27
|
+
[-2130]: "FTPS upload to the printer failed",
|
|
28
|
+
[-3120]: "Bambu Cloud refused to create the print task",
|
|
21
29
|
[-4010]: "the file exceeds the 1 GB upload limit",
|
|
22
30
|
[-4020]: "FTPS upload to the printer failed",
|
|
23
31
|
[LOCAL_PRINT_PUBLISH_FAILED]: "the networking plug-in could not send the print command to the printer over MQTT",
|
|
@@ -706,9 +714,23 @@ export class BambuNetworkBridge {
|
|
|
706
714
|
release();
|
|
707
715
|
}
|
|
708
716
|
}
|
|
709
|
-
/**
|
|
710
|
-
|
|
711
|
-
|
|
717
|
+
/**
|
|
718
|
+
* A cloud print in a cloud session, so the plug-in has the printer's state. With a fallback this is
|
|
719
|
+
* Bambu Studio's order for a cloud-bound printer it can also reach on the LAN (PrintJob.cpp,
|
|
720
|
+
* SendAttemptRoute::LanWithRecord, then ::Cloud): start_local_print_with_record, then start_print
|
|
721
|
+
* when the first failed before its print command was sent. `firstFailure` is the first method's result.
|
|
722
|
+
*/
|
|
723
|
+
async startCloudPrint(devId, method, payload, options = {}, assertActive = () => { }, timing = CLOUD_PRINT_TIMING, fallbackMethod) {
|
|
724
|
+
return await this.withCloudSession(devId, options, assertActive, timing, async (session) => {
|
|
725
|
+
const result = await this.callWithAgent(method, payload, options);
|
|
726
|
+
const value = bridgeNumericResult(result);
|
|
727
|
+
if (!fallbackMethod || value === undefined || !WITH_RECORD_PREPARATION_FAILURE(value))
|
|
728
|
+
return { result, jobUpdates: session.jobUpdates };
|
|
729
|
+
options.trace?.({ step: "fallback", from: method, to: fallbackMethod, result: value });
|
|
730
|
+
const params = payload.params;
|
|
731
|
+
const fallbackPayload = params ? { ...payload, params: { ...params, comments: `failed(${value})` } } : payload;
|
|
732
|
+
return { result: await this.callWithAgent(fallbackMethod, fallbackPayload, options), jobUpdates: session.jobUpdates, firstFailure: value };
|
|
733
|
+
});
|
|
712
734
|
}
|
|
713
735
|
/**
|
|
714
736
|
* A print control over Bambu Cloud: how Bambu Studio and FULU's slicer control a printer
|
package/dist/index.js
CHANGED
|
@@ -1247,9 +1247,15 @@ class BambuPrinterMCPServer {
|
|
|
1247
1247
|
throw new Error("plate_index must be a non-negative integer.");
|
|
1248
1248
|
}
|
|
1249
1249
|
const connectionType = resolveConnection(args).type;
|
|
1250
|
-
|
|
1251
|
-
|
|
1250
|
+
// With no method given, a cloud print follows Bambu Studio's order for a cloud-bound printer it can
|
|
1251
|
+
// reach on the LAN (PrintJob.cpp): start_local_print_with_record in the cloud session, then start_print.
|
|
1252
|
+
// This server always has the printer's IP and access code, which Studio needs for the first.
|
|
1253
|
+
const studioCloudRoute = connectionType === "cloud" && args?.bambu_network_method === undefined;
|
|
1254
|
+
const bridgePrintMethod = studioCloudRoute ? "start_local_print_with_record" : resolveBambuNetworkPrintMethod(args?.bambu_network_method !== undefined ? String(args.bambu_network_method) : undefined, connectionType);
|
|
1255
|
+
let bridgeMethod = toBridgeMethod(bridgePrintMethod);
|
|
1252
1256
|
const isLocalBridgePrint = bridgePrintMethod !== "start_print";
|
|
1257
|
+
const inCloudSession = studioCloudRoute || !isLocalBridgePrint;
|
|
1258
|
+
let cloudFallbackMethod = studioCloudRoute ? toBridgeMethod("start_print") : undefined;
|
|
1253
1259
|
const devId = String(args?.dev_id || bambuSerial || DEFAULT_BAMBU_DEV_ID).trim();
|
|
1254
1260
|
if (!devId) {
|
|
1255
1261
|
throw new Error("dev_id is required for FULU BambuNetwork printing. Pass dev_id or set BAMBU_DEV_ID/BAMBU_SERIAL.");
|
|
@@ -1313,6 +1319,11 @@ class BambuPrinterMCPServer {
|
|
|
1313
1319
|
const amsMapping = stringifyBridgeJson(mapping?.map(value => bridgeAmsMappingValue(value, isDualNozzleModel(printModel))));
|
|
1314
1320
|
const remoteFileName = uniquePrintName(threeMFPath);
|
|
1315
1321
|
const checkedName = remoteFileName.replace(/(?:\.gcode)?\.3mf$/i, "");
|
|
1322
|
+
if (cloudFallbackMethod && externalStorageState(confirmedStatus.raw) !== "normal") {
|
|
1323
|
+
// Studio sends straight through the cloud when the printer has no storage for the LAN upload.
|
|
1324
|
+
bridgeMethod = cloudFallbackMethod;
|
|
1325
|
+
cloudFallbackMethod = undefined;
|
|
1326
|
+
}
|
|
1316
1327
|
const params = {
|
|
1317
1328
|
dev_id: devId,
|
|
1318
1329
|
// Firmware can report the task name instead of the uploaded filename.
|
|
@@ -1407,26 +1418,31 @@ class BambuPrinterMCPServer {
|
|
|
1407
1418
|
const bridgeOptions = {
|
|
1408
1419
|
...this.bridgeOptionsFromArgs(args, "print_3mf_bambu_network"),
|
|
1409
1420
|
beforeDispatch: async (method) => {
|
|
1410
|
-
if (method !== bridgeMethod)
|
|
1421
|
+
if (method !== bridgeMethod && method !== cloudFallbackMethod)
|
|
1411
1422
|
return;
|
|
1412
1423
|
assertActive();
|
|
1413
1424
|
const dispatchStatus = await this.bambu.getSafetyStatus(devIp, devId, password || bambuToken);
|
|
1414
1425
|
validatePrinterState(dispatchStatus, requirements);
|
|
1415
1426
|
this.bambu.assertPrintPreflight(dispatchStatus, preflight);
|
|
1416
1427
|
},
|
|
1417
|
-
assertDispatchAllowed: method => { if (method === bridgeMethod)
|
|
1428
|
+
assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
|
|
1418
1429
|
assertActive(); },
|
|
1419
|
-
onDispatched: method => { if (method === bridgeMethod)
|
|
1430
|
+
onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
|
|
1420
1431
|
retainForDispatchedUpload(); },
|
|
1421
1432
|
};
|
|
1422
1433
|
let jobUpdates = [];
|
|
1423
1434
|
let bridgeResult;
|
|
1424
|
-
|
|
1435
|
+
let firstFailure;
|
|
1436
|
+
if (!inCloudSession) {
|
|
1425
1437
|
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startLocalPrint({ devId, devIp, username: String(params.username), password, useSsl: params.use_ssl_for_mqtt }, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1426
1438
|
}
|
|
1427
1439
|
else {
|
|
1428
|
-
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1440
|
+
({ result: bridgeResult, jobUpdates, firstFailure } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive, undefined, cloudFallbackMethod));
|
|
1441
|
+
if (firstFailure !== undefined)
|
|
1442
|
+
bridgeMethod = cloudFallbackMethod;
|
|
1429
1443
|
}
|
|
1444
|
+
const firstAttempt = firstFailure !== undefined
|
|
1445
|
+
? ` It first tried net.start_local_print_with_record, as Bambu Studio does, which returned ${firstFailure}${describeBambuNetworkPrintError(firstFailure)}.` : "";
|
|
1430
1446
|
if (typeof bridgeResult === "object" && bridgeResult !== null && bridgeResult.ok === false) {
|
|
1431
1447
|
throw new Error(`FULU BambuNetwork bridge method ${bridgeMethod} failed: ${String(bridgeResult.error || "unknown bridge error")}`);
|
|
1432
1448
|
}
|
|
@@ -1438,13 +1454,13 @@ class BambuPrinterMCPServer {
|
|
|
1438
1454
|
const reported = jobUpdates.filter(update => update.code !== 0 || update.msg).slice(-3)
|
|
1439
1455
|
.map(update => `status ${update.status}, code ${update.code}${update.msg ? `: ${update.msg}` : ""}`).join("; ");
|
|
1440
1456
|
throw new Error(`FULU BambuNetwork bridge method ${bridgeMethod} returned non-zero result ${value}${describeBambuNetworkPrintError(value)}.` +
|
|
1441
|
-
(reported ? ` Plug-in reported: ${reported}.` : ""));
|
|
1457
|
+
(reported ? ` Plug-in reported: ${reported}.` : "") + firstAttempt);
|
|
1442
1458
|
}
|
|
1443
1459
|
assertActive();
|
|
1444
1460
|
this.bambu.recordCheckedJob(devIp, devId, remoteFileName, requirements, resumeFile, false);
|
|
1445
1461
|
return {
|
|
1446
1462
|
status: "success",
|
|
1447
|
-
message: `FULU BambuNetwork ${
|
|
1463
|
+
message: `FULU BambuNetwork ${bridgeMethod.replace(/^net\./, "")} command for ${threeMfFilename} sent successfully.${firstAttempt}`,
|
|
1448
1464
|
bridgeMethod,
|
|
1449
1465
|
bridgeResult,
|
|
1450
1466
|
clientJobId,
|
|
@@ -2121,7 +2137,10 @@ class BambuPrinterMCPServer {
|
|
|
2121
2137
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates for local slicers; remote slicing defaults to plate 1 and rejects 0. Use 1, 2, etc. to slice only a specific plate in multi-plate 3MF projects." },
|
|
2122
2138
|
layer_height: { type: "number", exclusiveMinimum: 0, description: "Layer height in mm, such as 0.28 (draft), 0.2 (standard) or 0.12 (fine). Written as the process preset's layer_height over the machine and process preset this tool resolves; at most the nozzle diameter. Bambu-compatible slicers only." },
|
|
2123
2139
|
wall_loops: { type: "integer", minimum: 0, maximum: 1000, description: "Number of walls (perimeters), written as the process preset's wall_loops. Bambu-compatible slicers only." },
|
|
2124
|
-
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." }
|
|
2140
|
+
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." },
|
|
2141
|
+
enable_support: { type: "boolean", description: "Turn support generation on or off, written as the process preset's enable_support. Bambu-compatible slicers only." },
|
|
2142
|
+
support_type: { type: "string", enum: ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"], description: "Support style, written as the process preset's support_type. Bambu-compatible slicers only." },
|
|
2143
|
+
support_threshold_angle: { type: "integer", minimum: 0, maximum: 90, description: "Overhang threshold in degrees for automatic supports, written as the process preset's support_threshold_angle (0 lets the slicer decide). Bambu-compatible slicers only." }
|
|
2125
2144
|
},
|
|
2126
2145
|
required: ["stl_path", "bambu_model"]
|
|
2127
2146
|
}
|
|
@@ -2197,7 +2216,7 @@ class BambuPrinterMCPServer {
|
|
|
2197
2216
|
description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
|
|
2198
2217
|
},
|
|
2199
2218
|
connection_type: { type: "string", enum: ["cloud", "lan"], description: "BambuNetwork connection type to put in FULU PrintParams; cloud uses restored internet printing, lan uses local bridge printing." },
|
|
2200
|
-
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method to invoke; defaults to
|
|
2219
|
+
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method to invoke; defaults to start_local_print for lan, and for cloud to Bambu Studio's order: start_local_print_with_record, then start_print if that fails." },
|
|
2201
2220
|
dev_id: { type: "string", description: "Bambu device id used by BambuNetwork; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
2202
2221
|
dev_ip: { type: "string", description: "Printer IP address for LAN/local bridge methods; defaults to host when provided." },
|
|
2203
2222
|
host: { type: "string", description: "Printer host or IP address, used as dev_ip for LAN/local bridge methods." },
|
|
@@ -2626,7 +2645,7 @@ class BambuPrinterMCPServer {
|
|
|
2626
2645
|
},
|
|
2627
2646
|
try_emmc_print: { type: "boolean", description: "X2D native printing: true stores the job on internal storage (eMMC), false on the SD card or USB stick (refused unless the printer reports one ready). Omit to use the card when ready, else eMMC; BAMBU_NATIVE_TRY_EMMC_PRINT sets a server default." },
|
|
2628
2647
|
connection_type: { type: "string", enum: ["cloud", "lan"], description: "BambuNetwork connection type when connection_mode is bambu_network; cloud uses restored internet printing, lan uses local bridge printing." },
|
|
2629
|
-
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to
|
|
2648
|
+
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to start_local_print for lan, and for cloud to Bambu Studio's order: start_local_print_with_record, then start_print if that fails." },
|
|
2630
2649
|
dev_id: { type: "string", description: "Bambu device id for FULU BambuNetwork printing; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
2631
2650
|
dev_ip: { type: "string", description: "Printer IP address for FULU BambuNetwork LAN/local print methods; defaults to host when provided." },
|
|
2632
2651
|
bridge_command: { type: "string", description: "Override command for the FULU bridge host or macOS/WSL wrapper; defaults to BAMBU_NETWORK_BRIDGE_COMMAND. Per-call overrides require MCP_ALLOW_EXECUTABLE_ARG=1." },
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* slice_stl's layer_height, wall_loops and
|
|
2
|
+
* slice_stl's layer_height, wall_loops, sparse_infill_density and support arguments
|
|
3
3
|
* (PRD §8.4). They are written over the process preset the slicer already
|
|
4
4
|
* resolved, using Bambu Studio/Orca keys and their string forms ("0.2", "2",
|
|
5
5
|
* "15%"), so the machine preset and every other process value stay as resolved.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
export
|
|
7
|
+
export declare const PROCESS_OVERRIDE_KEYS: readonly ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"];
|
|
8
|
+
export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number], string>>;
|
|
9
|
+
/** Bambu Studio's and OrcaSlicer's support_type values. */
|
|
10
|
+
export declare const SUPPORT_TYPES: readonly ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"];
|
|
9
11
|
/** Validate the tool arguments; undefined when none are given. */
|
|
10
12
|
export declare function parseProcessOverrides(args: Record<string, unknown> | undefined, nozzleDiameter: number): ProcessOverrides | undefined;
|
|
11
13
|
/** The process profile with the overrides written over its values. */
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* slice_stl's layer_height, wall_loops, sparse_infill_density and support arguments
|
|
3
|
+
* (PRD §8.4). They are written over the process preset the slicer already
|
|
4
|
+
* resolved, using Bambu Studio/Orca keys and their string forms ("0.2", "2",
|
|
5
|
+
* "15%"), so the machine preset and every other process value stay as resolved.
|
|
6
|
+
*/
|
|
7
|
+
export const PROCESS_OVERRIDE_KEYS = ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"];
|
|
8
|
+
/** Bambu Studio's and OrcaSlicer's support_type values. */
|
|
9
|
+
export const SUPPORT_TYPES = ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"];
|
|
2
10
|
/** Validate the tool arguments; undefined when none are given. */
|
|
3
11
|
export function parseProcessOverrides(args, nozzleDiameter) {
|
|
4
12
|
const overrides = {};
|
|
@@ -25,6 +33,27 @@ export function parseProcessOverrides(args, nozzleDiameter) {
|
|
|
25
33
|
throw new Error('sparse_infill_density must be a percentage from 0% to 100%, such as "15%".');
|
|
26
34
|
overrides.sparse_infill_density = `${Number(match[1])}%`;
|
|
27
35
|
}
|
|
36
|
+
const enableSupport = args?.enable_support;
|
|
37
|
+
if (enableSupport !== undefined) {
|
|
38
|
+
if (typeof enableSupport !== "boolean")
|
|
39
|
+
throw new Error("enable_support must be true or false.");
|
|
40
|
+
overrides.enable_support = enableSupport ? "1" : "0";
|
|
41
|
+
}
|
|
42
|
+
const supportType = args?.support_type;
|
|
43
|
+
if (supportType !== undefined) {
|
|
44
|
+
if (typeof supportType !== "string" || !SUPPORT_TYPES.includes(supportType)) {
|
|
45
|
+
throw new Error(`support_type must be one of ${SUPPORT_TYPES.join(", ")}.`);
|
|
46
|
+
}
|
|
47
|
+
overrides.support_type = supportType;
|
|
48
|
+
}
|
|
49
|
+
const threshold = args?.support_threshold_angle;
|
|
50
|
+
if (threshold !== undefined) {
|
|
51
|
+
// Studio's threshold angle runs 0-90 degrees; 0 lets the slicer pick by its own rule.
|
|
52
|
+
if (typeof threshold !== "number" || !Number.isInteger(threshold) || threshold < 0 || threshold > 90) {
|
|
53
|
+
throw new Error("support_threshold_angle must be an integer number of degrees from 0 to 90.");
|
|
54
|
+
}
|
|
55
|
+
overrides.support_threshold_angle = String(threshold);
|
|
56
|
+
}
|
|
28
57
|
return Object.keys(overrides).length ? overrides : undefined;
|
|
29
58
|
}
|
|
30
59
|
/** The process profile with the overrides written over its values. */
|
package/package.json
CHANGED
|
@@ -17,8 +17,16 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 120_000;
|
|
|
17
17
|
const LOCAL_CONNECT_STATUS = ["ok", "failed", "lost"];
|
|
18
18
|
// bambu_networking.hpp BAMBU_NETWORK_ERR_PRINT_LP_PUBLISH_MSG_FAILED.
|
|
19
19
|
const LOCAL_PRINT_PUBLISH_FAILED = -4030;
|
|
20
|
+
// A with-record send falls back to start_print only on its own preparation failures (the plug-in's
|
|
21
|
+
// PRINT_WR_* results, -2010 to -2140: project, upload, task record, FTPS), which come before the print
|
|
22
|
+
// command, so the printer has no job. Any other result may have reached the printer and is never
|
|
23
|
+
// replayed. Of those, Studio also stops on a file missing or too large (should_stop_without_fallback).
|
|
24
|
+
const WITH_RECORD_PREPARATION_FAILURE = (value: number) => value <= -2010 && value >= -2140 && value !== -2040 && value !== -2100;
|
|
20
25
|
// bambu_networking.hpp print errors that name a recoverable cause.
|
|
21
26
|
const BAMBU_NETWORK_PRINT_ERRORS: Record<number, string> = {
|
|
27
|
+
[-2120]: "Bambu Cloud refused to create the print task",
|
|
28
|
+
[-2130]: "FTPS upload to the printer failed",
|
|
29
|
+
[-3120]: "Bambu Cloud refused to create the print task",
|
|
22
30
|
[-4010]: "the file exceeds the 1 GB upload limit",
|
|
23
31
|
[-4020]: "FTPS upload to the printer failed",
|
|
24
32
|
[LOCAL_PRINT_PUBLISH_FAILED]: "the networking plug-in could not send the print command to the printer over MQTT",
|
|
@@ -852,10 +860,24 @@ export class BambuNetworkBridge {
|
|
|
852
860
|
}
|
|
853
861
|
}
|
|
854
862
|
|
|
855
|
-
/**
|
|
863
|
+
/**
|
|
864
|
+
* A cloud print in a cloud session, so the plug-in has the printer's state. With a fallback this is
|
|
865
|
+
* Bambu Studio's order for a cloud-bound printer it can also reach on the LAN (PrintJob.cpp,
|
|
866
|
+
* SendAttemptRoute::LanWithRecord, then ::Cloud): start_local_print_with_record, then start_print
|
|
867
|
+
* when the first failed before its print command was sent. `firstFailure` is the first method's result.
|
|
868
|
+
*/
|
|
856
869
|
async startCloudPrint(devId: string, method: string, payload: JsonObject, options: BambuNetworkBridgeOptions = {},
|
|
857
|
-
assertActive: () => void = () => {}, timing: Readonly<CloudTiming> = CLOUD_PRINT_TIMING
|
|
858
|
-
|
|
870
|
+
assertActive: () => void = () => {}, timing: Readonly<CloudTiming> = CLOUD_PRINT_TIMING, fallbackMethod?: string
|
|
871
|
+
): Promise<{ result: unknown; jobUpdates: BridgeJobUpdate[]; firstFailure?: number }> {
|
|
872
|
+
return await this.withCloudSession(devId, options, assertActive, timing, async session => {
|
|
873
|
+
const result = await this.callWithAgent(method, payload, options);
|
|
874
|
+
const value = bridgeNumericResult(result);
|
|
875
|
+
if (!fallbackMethod || value === undefined || !WITH_RECORD_PREPARATION_FAILURE(value)) return { result, jobUpdates: session.jobUpdates };
|
|
876
|
+
options.trace?.({ step: "fallback", from: method, to: fallbackMethod, result: value });
|
|
877
|
+
const params = (payload as { params?: JsonObject }).params;
|
|
878
|
+
const fallbackPayload = params ? { ...payload, params: { ...params, comments: `failed(${value})` } } : payload;
|
|
879
|
+
return { result: await this.callWithAgent(fallbackMethod, fallbackPayload, options), jobUpdates: session.jobUpdates, firstFailure: value };
|
|
880
|
+
});
|
|
859
881
|
}
|
|
860
882
|
|
|
861
883
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1645,12 +1645,18 @@ class BambuPrinterMCPServer {
|
|
|
1645
1645
|
|
|
1646
1646
|
const connectionType = resolveConnection(args).type;
|
|
1647
1647
|
|
|
1648
|
-
|
|
1648
|
+
// With no method given, a cloud print follows Bambu Studio's order for a cloud-bound printer it can
|
|
1649
|
+
// reach on the LAN (PrintJob.cpp): start_local_print_with_record in the cloud session, then start_print.
|
|
1650
|
+
// This server always has the printer's IP and access code, which Studio needs for the first.
|
|
1651
|
+
const studioCloudRoute = connectionType === "cloud" && args?.bambu_network_method === undefined;
|
|
1652
|
+
const bridgePrintMethod = studioCloudRoute ? "start_local_print_with_record" : resolveBambuNetworkPrintMethod(
|
|
1649
1653
|
args?.bambu_network_method !== undefined ? String(args.bambu_network_method) : undefined,
|
|
1650
1654
|
connectionType
|
|
1651
1655
|
);
|
|
1652
|
-
|
|
1656
|
+
let bridgeMethod = toBridgeMethod(bridgePrintMethod);
|
|
1653
1657
|
const isLocalBridgePrint = bridgePrintMethod !== "start_print";
|
|
1658
|
+
const inCloudSession = studioCloudRoute || !isLocalBridgePrint;
|
|
1659
|
+
let cloudFallbackMethod = studioCloudRoute ? toBridgeMethod("start_print") : undefined;
|
|
1654
1660
|
|
|
1655
1661
|
const devId = String(args?.dev_id || bambuSerial || DEFAULT_BAMBU_DEV_ID).trim();
|
|
1656
1662
|
if (!devId) {
|
|
@@ -1730,6 +1736,11 @@ class BambuPrinterMCPServer {
|
|
|
1730
1736
|
const amsMapping = stringifyBridgeJson(mapping?.map(value => bridgeAmsMappingValue(value, isDualNozzleModel(printModel))));
|
|
1731
1737
|
const remoteFileName = uniquePrintName(threeMFPath);
|
|
1732
1738
|
const checkedName = remoteFileName.replace(/(?:\.gcode)?\.3mf$/i, "");
|
|
1739
|
+
if (cloudFallbackMethod && externalStorageState(confirmedStatus.raw) !== "normal") {
|
|
1740
|
+
// Studio sends straight through the cloud when the printer has no storage for the LAN upload.
|
|
1741
|
+
bridgeMethod = cloudFallbackMethod;
|
|
1742
|
+
cloudFallbackMethod = undefined;
|
|
1743
|
+
}
|
|
1733
1744
|
const params: Record<string, unknown> = {
|
|
1734
1745
|
dev_id: devId,
|
|
1735
1746
|
// Firmware can report the task name instead of the uploaded filename.
|
|
@@ -1825,18 +1836,19 @@ class BambuPrinterMCPServer {
|
|
|
1825
1836
|
const bridgeOptions: BambuNetworkBridgeOptions = {
|
|
1826
1837
|
...this.bridgeOptionsFromArgs(args, "print_3mf_bambu_network"),
|
|
1827
1838
|
beforeDispatch: async method => {
|
|
1828
|
-
if (method !== bridgeMethod) return;
|
|
1839
|
+
if (method !== bridgeMethod && method !== cloudFallbackMethod) return;
|
|
1829
1840
|
assertActive();
|
|
1830
1841
|
const dispatchStatus = await this.bambu.getSafetyStatus(devIp, devId, password || bambuToken);
|
|
1831
1842
|
validatePrinterState(dispatchStatus, requirements);
|
|
1832
1843
|
this.bambu.assertPrintPreflight(dispatchStatus, preflight);
|
|
1833
1844
|
},
|
|
1834
|
-
assertDispatchAllowed: method => { if (method === bridgeMethod) assertActive(); },
|
|
1835
|
-
onDispatched: method => { if (method === bridgeMethod) retainForDispatchedUpload(); },
|
|
1845
|
+
assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) assertActive(); },
|
|
1846
|
+
onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod) retainForDispatchedUpload(); },
|
|
1836
1847
|
};
|
|
1837
1848
|
let jobUpdates: BridgeJobUpdate[] = [];
|
|
1838
1849
|
let bridgeResult: unknown;
|
|
1839
|
-
|
|
1850
|
+
let firstFailure: number | undefined;
|
|
1851
|
+
if (!inCloudSession) {
|
|
1840
1852
|
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startLocalPrint(
|
|
1841
1853
|
{ devId, devIp, username: String(params.username), password, useSsl: params.use_ssl_for_mqtt as boolean },
|
|
1842
1854
|
bridgeMethod,
|
|
@@ -1845,8 +1857,11 @@ class BambuPrinterMCPServer {
|
|
|
1845
1857
|
assertActive
|
|
1846
1858
|
));
|
|
1847
1859
|
} else {
|
|
1848
|
-
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1860
|
+
({ result: bridgeResult, jobUpdates, firstFailure } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive, undefined, cloudFallbackMethod));
|
|
1861
|
+
if (firstFailure !== undefined) bridgeMethod = cloudFallbackMethod!;
|
|
1849
1862
|
}
|
|
1863
|
+
const firstAttempt = firstFailure !== undefined
|
|
1864
|
+
? ` It first tried net.start_local_print_with_record, as Bambu Studio does, which returned ${firstFailure}${describeBambuNetworkPrintError(firstFailure)}.` : "";
|
|
1850
1865
|
|
|
1851
1866
|
if (typeof bridgeResult === "object" && bridgeResult !== null && (bridgeResult as { ok?: unknown }).ok === false) {
|
|
1852
1867
|
throw new Error(`FULU BambuNetwork bridge method ${bridgeMethod} failed: ${String((bridgeResult as { error?: unknown }).error || "unknown bridge error")}`);
|
|
@@ -1861,7 +1876,7 @@ class BambuPrinterMCPServer {
|
|
|
1861
1876
|
const reported = jobUpdates.filter(update => update.code !== 0 || update.msg).slice(-3)
|
|
1862
1877
|
.map(update => `status ${update.status}, code ${update.code}${update.msg ? `: ${update.msg}` : ""}`).join("; ");
|
|
1863
1878
|
throw new Error(`FULU BambuNetwork bridge method ${bridgeMethod} returned non-zero result ${value}${describeBambuNetworkPrintError(value)}.` +
|
|
1864
|
-
(reported ? ` Plug-in reported: ${reported}.` : ""));
|
|
1879
|
+
(reported ? ` Plug-in reported: ${reported}.` : "") + firstAttempt);
|
|
1865
1880
|
}
|
|
1866
1881
|
|
|
1867
1882
|
assertActive();
|
|
@@ -1869,7 +1884,7 @@ class BambuPrinterMCPServer {
|
|
|
1869
1884
|
|
|
1870
1885
|
return {
|
|
1871
1886
|
status: "success",
|
|
1872
|
-
message: `FULU BambuNetwork ${
|
|
1887
|
+
message: `FULU BambuNetwork ${bridgeMethod.replace(/^net\./, "")} command for ${threeMfFilename} sent successfully.${firstAttempt}`,
|
|
1873
1888
|
bridgeMethod,
|
|
1874
1889
|
bridgeResult,
|
|
1875
1890
|
clientJobId,
|
|
@@ -2654,7 +2669,10 @@ class BambuPrinterMCPServer {
|
|
|
2654
2669
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates for local slicers; remote slicing defaults to plate 1 and rejects 0. Use 1, 2, etc. to slice only a specific plate in multi-plate 3MF projects." },
|
|
2655
2670
|
layer_height: { type: "number", exclusiveMinimum: 0, description: "Layer height in mm, such as 0.28 (draft), 0.2 (standard) or 0.12 (fine). Written as the process preset's layer_height over the machine and process preset this tool resolves; at most the nozzle diameter. Bambu-compatible slicers only." },
|
|
2656
2671
|
wall_loops: { type: "integer", minimum: 0, maximum: 1000, description: "Number of walls (perimeters), written as the process preset's wall_loops. Bambu-compatible slicers only." },
|
|
2657
|
-
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." }
|
|
2672
|
+
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." },
|
|
2673
|
+
enable_support: { type: "boolean", description: "Turn support generation on or off, written as the process preset's enable_support. Bambu-compatible slicers only." },
|
|
2674
|
+
support_type: { type: "string", enum: ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"], description: "Support style, written as the process preset's support_type. Bambu-compatible slicers only." },
|
|
2675
|
+
support_threshold_angle: { type: "integer", minimum: 0, maximum: 90, description: "Overhang threshold in degrees for automatic supports, written as the process preset's support_threshold_angle (0 lets the slicer decide). Bambu-compatible slicers only." }
|
|
2658
2676
|
},
|
|
2659
2677
|
required: ["stl_path", "bambu_model"]
|
|
2660
2678
|
}
|
|
@@ -2730,7 +2748,7 @@ class BambuPrinterMCPServer {
|
|
|
2730
2748
|
description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
|
|
2731
2749
|
},
|
|
2732
2750
|
connection_type: { type: "string", enum: ["cloud", "lan"], description: "BambuNetwork connection type to put in FULU PrintParams; cloud uses restored internet printing, lan uses local bridge printing." },
|
|
2733
|
-
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method to invoke; defaults to
|
|
2751
|
+
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method to invoke; defaults to start_local_print for lan, and for cloud to Bambu Studio's order: start_local_print_with_record, then start_print if that fails." },
|
|
2734
2752
|
dev_id: { type: "string", description: "Bambu device id used by BambuNetwork; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
2735
2753
|
dev_ip: { type: "string", description: "Printer IP address for LAN/local bridge methods; defaults to host when provided." },
|
|
2736
2754
|
host: { type: "string", description: "Printer host or IP address, used as dev_ip for LAN/local bridge methods." },
|
|
@@ -3159,7 +3177,7 @@ class BambuPrinterMCPServer {
|
|
|
3159
3177
|
},
|
|
3160
3178
|
try_emmc_print: { type: "boolean", description: "X2D native printing: true stores the job on internal storage (eMMC), false on the SD card or USB stick (refused unless the printer reports one ready). Omit to use the card when ready, else eMMC; BAMBU_NATIVE_TRY_EMMC_PRINT sets a server default." },
|
|
3161
3179
|
connection_type: { type: "string", enum: ["cloud", "lan"], description: "BambuNetwork connection type when connection_mode is bambu_network; cloud uses restored internet printing, lan uses local bridge printing." },
|
|
3162
|
-
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to
|
|
3180
|
+
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to start_local_print for lan, and for cloud to Bambu Studio's order: start_local_print_with_record, then start_print if that fails." },
|
|
3163
3181
|
dev_id: { type: "string", description: "Bambu device id for FULU BambuNetwork printing; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
3164
3182
|
dev_ip: { type: "string", description: "Printer IP address for FULU BambuNetwork LAN/local print methods; defaults to host when provided." },
|
|
3165
3183
|
bridge_command: { type: "string", description: "Override command for the FULU bridge host or macOS/WSL wrapper; defaults to BAMBU_NETWORK_BRIDGE_COMMAND. Per-call overrides require MCP_ALLOW_EXECUTABLE_ARG=1." },
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* slice_stl's layer_height, wall_loops and
|
|
2
|
+
* slice_stl's layer_height, wall_loops, sparse_infill_density and support arguments
|
|
3
3
|
* (PRD §8.4). They are written over the process preset the slicer already
|
|
4
4
|
* resolved, using Bambu Studio/Orca keys and their string forms ("0.2", "2",
|
|
5
5
|
* "15%"), so the machine preset and every other process value stay as resolved.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export const PROCESS_OVERRIDE_KEYS = ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"] as const;
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number], string>>;
|
|
10
|
+
|
|
11
|
+
/** Bambu Studio's and OrcaSlicer's support_type values. */
|
|
12
|
+
export const SUPPORT_TYPES = ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"] as const;
|
|
10
13
|
|
|
11
14
|
/** Validate the tool arguments; undefined when none are given. */
|
|
12
15
|
export function parseProcessOverrides(args: Record<string, unknown> | undefined, nozzleDiameter: number): ProcessOverrides | undefined {
|
|
@@ -33,6 +36,26 @@ export function parseProcessOverrides(args: Record<string, unknown> | undefined,
|
|
|
33
36
|
if (!match || Number(match[1]) > 100) throw new Error('sparse_infill_density must be a percentage from 0% to 100%, such as "15%".');
|
|
34
37
|
overrides.sparse_infill_density = `${Number(match[1])}%`;
|
|
35
38
|
}
|
|
39
|
+
const enableSupport = args?.enable_support;
|
|
40
|
+
if (enableSupport !== undefined) {
|
|
41
|
+
if (typeof enableSupport !== "boolean") throw new Error("enable_support must be true or false.");
|
|
42
|
+
overrides.enable_support = enableSupport ? "1" : "0";
|
|
43
|
+
}
|
|
44
|
+
const supportType = args?.support_type;
|
|
45
|
+
if (supportType !== undefined) {
|
|
46
|
+
if (typeof supportType !== "string" || !(SUPPORT_TYPES as readonly string[]).includes(supportType)) {
|
|
47
|
+
throw new Error(`support_type must be one of ${SUPPORT_TYPES.join(", ")}.`);
|
|
48
|
+
}
|
|
49
|
+
overrides.support_type = supportType;
|
|
50
|
+
}
|
|
51
|
+
const threshold = args?.support_threshold_angle;
|
|
52
|
+
if (threshold !== undefined) {
|
|
53
|
+
// Studio's threshold angle runs 0-90 degrees; 0 lets the slicer pick by its own rule.
|
|
54
|
+
if (typeof threshold !== "number" || !Number.isInteger(threshold) || threshold < 0 || threshold > 90) {
|
|
55
|
+
throw new Error("support_threshold_angle must be an integer number of degrees from 0 to 90.");
|
|
56
|
+
}
|
|
57
|
+
overrides.support_threshold_angle = String(threshold);
|
|
58
|
+
}
|
|
36
59
|
return Object.keys(overrides).length ? overrides : undefined;
|
|
37
60
|
}
|
|
38
61
|
|