bambu-printer-mcp 1.1.49 → 1.1.51
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 +11 -2
- package/dist/bambu-native.d.ts +5 -0
- package/dist/bambu-native.js +14 -4
- package/dist/counterpart/progress.js +4 -2
- package/dist/fusion-mcp-bridge.js +6 -4
- package/dist/index.js +67 -34
- package/dist/printers/bambu.d.ts +5 -0
- package/dist/printers/bambu.js +72 -16
- package/dist/stl/stl-manipulator.d.ts +37 -1
- package/dist/stl/stl-manipulator.js +203 -79
- package/dist/studio-hms-text.d.ts +2 -0
- package/dist/studio-hms-text.js +63 -0
- package/dist/studio-print-options.d.ts +57 -0
- package/dist/studio-print-options.js +179 -0
- package/package.json +2 -2
- package/src/bambu-native.ts +19 -4
- package/src/counterpart/progress.ts +4 -2
- package/src/fusion-mcp-bridge.ts +6 -4
- package/src/index.ts +67 -33
- package/src/printers/bambu.ts +70 -15
- package/src/stl/stl-manipulator.ts +240 -88
- package/src/studio-hms-text.ts +54 -0
- package/src/studio-print-options.ts +201 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The print options Bambu Studio's Send dialog sends, resolved the way it
|
|
3
|
+
* resolves them, so every print route sends what Bambu's own Print button
|
|
4
|
+
* would. Source: Bambu Studio v02.08.02.61 (commit 926a7192574b), the version
|
|
5
|
+
* the hidden-HMS and stage tables are pinned to:
|
|
6
|
+
*
|
|
7
|
+
* - SelectMachine.cpp:3344-3356 `set_print_config(bed_type,
|
|
8
|
+
* bed_leveling == "on", flow_cali == "on", false, timelapse, true,
|
|
9
|
+
* ext_change_assist, bed_leveling.getValueInt(), flow_cali.getValueInt(),
|
|
10
|
+
* nozzle_offset_cali.getValueInt(), pa_value_switch ? 0 : 1)`. Vibration
|
|
11
|
+
* calibration is always false and layer inspection always true; the
|
|
12
|
+
* parameter order is PrintJob.hpp:98-116.
|
|
13
|
+
* - SelectMachine.cpp:7318-7329 `getValueInt`: off 0, on 1, auto 2.
|
|
14
|
+
* - SelectMachine.cpp:1117-1123 `update_select_layout`: update_option_opts
|
|
15
|
+
* (which choices each option offers on this printer) runs before
|
|
16
|
+
* load_option_vals.
|
|
17
|
+
* - SelectMachine.cpp:2993-3027 `load_option_vals`: the value saved in
|
|
18
|
+
* BambuStudio.conf under the printer type, if the option offers it; else
|
|
19
|
+
* "auto" if offered; else "on". Dual-nozzle printers then set nozzle offset
|
|
20
|
+
* calibration to "auto" for a two-nozzle job and, without a filament
|
|
21
|
+
* switcher, "off" for a one-nozzle job.
|
|
22
|
+
* - SelectMachine.cpp:2586-2615 `update_option_opts`: bed leveling offers
|
|
23
|
+
* auto/on/off when the printer's support_bed_leveling is 2 and on/off when it
|
|
24
|
+
* is 1; with 0 it is hidden and keeps the auto/on/off it was built with
|
|
25
|
+
* (SelectMachine.cpp:676-691), as does flow calibration when the printer has
|
|
26
|
+
* no PA calibration. DeviceManager.cpp:1100/4441 give P-series printers
|
|
27
|
+
* (series_p1p: P1P, P1S) no PA calibration, so their flow calibration is
|
|
28
|
+
* hidden and resolves to "auto". Nozzle offset calibration always offers auto.
|
|
29
|
+
* - SelectMachine.cpp:705-707: the PA value switch starts on and is not saved,
|
|
30
|
+
* so extruder_cali_manual_mode is 0.
|
|
31
|
+
*
|
|
32
|
+
* Approximations, outside the P1P/P1S: flow calibration on other printers is
|
|
33
|
+
* shown when the printer's push status reports PA calibration (assumed here),
|
|
34
|
+
* and offers auto when support_auto_flow_calibration is true and the mapped
|
|
35
|
+
* filaments allow it (can_support_pa_auto_cali, assumed true). A filament
|
|
36
|
+
* switcher on a dual-nozzle printer is assumed absent.
|
|
37
|
+
*/
|
|
38
|
+
import fs from "node:fs";
|
|
39
|
+
import os from "node:os";
|
|
40
|
+
import path from "node:path";
|
|
41
|
+
const AUTO_ON_OFF = ["auto", "on", "off"];
|
|
42
|
+
const ON_OFF = ["on", "off"];
|
|
43
|
+
/**
|
|
44
|
+
* Studio's printer types (resources/printers/<type>.json at the pinned commit:
|
|
45
|
+
* model_id/printer_type, printer_series, support_bed_leveling,
|
|
46
|
+
* support_auto_flow_calibration), keyed by this server's model names.
|
|
47
|
+
*/
|
|
48
|
+
const STUDIO_PRINTERS = {
|
|
49
|
+
p1p: { types: ["C11"], pSeries: true, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
50
|
+
p1s: { types: ["C12"], pSeries: true, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
51
|
+
x1c: { types: ["3DPrinter-X1-Carbon"], pSeries: false, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
52
|
+
x1: { types: ["3DPrinter-X1"], pSeries: false, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
53
|
+
x1e: { types: ["C13"], pSeries: false, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
54
|
+
a1mini: { types: ["N1"], pSeries: false, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
55
|
+
a1: { types: ["N2S"], pSeries: false, bedLeveling: 1, autoFlow: false, dualNozzle: false },
|
|
56
|
+
p2s: { types: ["N7"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: false },
|
|
57
|
+
x2d: { types: ["N6"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: true },
|
|
58
|
+
h2s: { types: ["O1S"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: false },
|
|
59
|
+
h2d: { types: ["O1D"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: true },
|
|
60
|
+
h2dpro: { types: ["O1E"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: true },
|
|
61
|
+
h2c: { types: ["O1C", "O1C2"], pSeries: false, bedLeveling: 2, autoFlow: true, dualNozzle: true },
|
|
62
|
+
};
|
|
63
|
+
/** Where Studio keeps BambuStudio.conf; BAMBU_STUDIO_CONFIG overrides it (empty: none). */
|
|
64
|
+
export function studioConfigPath() {
|
|
65
|
+
const override = process.env.BAMBU_STUDIO_CONFIG;
|
|
66
|
+
if (override !== undefined)
|
|
67
|
+
return override.trim() || undefined;
|
|
68
|
+
if (process.platform === "darwin")
|
|
69
|
+
return path.join(os.homedir(), "Library", "Application Support", "BambuStudio", "BambuStudio.conf");
|
|
70
|
+
if (process.platform === "win32")
|
|
71
|
+
return process.env.APPDATA ? path.join(process.env.APPDATA, "BambuStudio", "BambuStudio.conf") : undefined;
|
|
72
|
+
return path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"), "BambuStudio", "BambuStudio.conf");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The Send dialog options Studio saved for a printer type, and nothing else:
|
|
76
|
+
* BambuStudio.conf also holds access codes, so only that one section is kept,
|
|
77
|
+
* and a parse failure is reported without any of the file's text.
|
|
78
|
+
*/
|
|
79
|
+
export function readStudioSavedOptions(printerTypes, configPath) {
|
|
80
|
+
if (!configPath)
|
|
81
|
+
return undefined;
|
|
82
|
+
let text;
|
|
83
|
+
try {
|
|
84
|
+
const stat = fs.statSync(configPath);
|
|
85
|
+
if (!stat.isFile() || stat.size > 16 * 1024 * 1024)
|
|
86
|
+
return undefined;
|
|
87
|
+
text = fs.readFileSync(configPath, "utf8");
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
let config;
|
|
93
|
+
// Studio appends "# MD5 checksum <hex>" after the JSON.
|
|
94
|
+
try {
|
|
95
|
+
config = JSON.parse(text.split("\n").filter(line => !line.trimStart().startsWith("#")).join("\n"));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (!config || typeof config !== "object")
|
|
101
|
+
return undefined;
|
|
102
|
+
for (const type of printerTypes) {
|
|
103
|
+
const section = config[type];
|
|
104
|
+
if (!section || typeof section !== "object" || Array.isArray(section))
|
|
105
|
+
continue;
|
|
106
|
+
const saved = {};
|
|
107
|
+
for (const key of ["bed_leveling", "flow_cali", "nozzle_offset_cali", "timelapse"]) {
|
|
108
|
+
const value = section[key];
|
|
109
|
+
if (typeof value === "string")
|
|
110
|
+
saved[key] = value;
|
|
111
|
+
}
|
|
112
|
+
return saved;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
function fromInt(value, label) {
|
|
117
|
+
if (value === 0)
|
|
118
|
+
return "off";
|
|
119
|
+
if (value === 1)
|
|
120
|
+
return "on";
|
|
121
|
+
if (value === 2)
|
|
122
|
+
return "auto";
|
|
123
|
+
throw new Error(`${label} must be 0 (off), 1 (on) or 2 (auto).`);
|
|
124
|
+
}
|
|
125
|
+
const toInt = (value) => value === "off" ? 0 : value === "on" ? 1 : 2;
|
|
126
|
+
/** load_option_vals for one option: saved if offered, else auto if offered, else on. */
|
|
127
|
+
function loaded(saved, offers) {
|
|
128
|
+
if (saved !== undefined && offers.includes(saved))
|
|
129
|
+
return { value: saved, source: "studio-config" };
|
|
130
|
+
return { value: offers.includes("auto") ? "auto" : "on", source: "studio-default" };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* What Studio's Send dialog would send for this model, with the caller's
|
|
134
|
+
* explicit choices taking precedence. usedNozzles is the number of nozzles the
|
|
135
|
+
* job uses, for dual-nozzle printers.
|
|
136
|
+
*/
|
|
137
|
+
export function resolveStudioPrintOptions(model, caller = {}, options = {}) {
|
|
138
|
+
const printer = STUDIO_PRINTERS[model];
|
|
139
|
+
const saved = printer ? readStudioSavedOptions(printer.types, "configPath" in options ? options.configPath : studioConfigPath()) ?? {} : {};
|
|
140
|
+
const printerType = printer?.types[0];
|
|
141
|
+
const bedOffers = !printer || printer.bedLeveling !== 1 ? AUTO_ON_OFF : ON_OFF;
|
|
142
|
+
const flowOffers = !printer || printer.pSeries || printer.autoFlow ? AUTO_ON_OFF : ON_OFF;
|
|
143
|
+
const bed = loaded(saved.bed_leveling, bedOffers);
|
|
144
|
+
const flow = loaded(saved.flow_cali, flowOffers);
|
|
145
|
+
let offset = loaded(saved.nozzle_offset_cali, AUTO_ON_OFF);
|
|
146
|
+
if (printer?.dualNozzle && options.usedNozzles !== undefined) {
|
|
147
|
+
if (options.usedNozzles >= 2)
|
|
148
|
+
offset = { value: "auto", source: "studio-default" };
|
|
149
|
+
else if (options.usedNozzles === 1)
|
|
150
|
+
offset = { value: "off", source: "studio-default" };
|
|
151
|
+
}
|
|
152
|
+
const choose = (current, auto, flag, label) => auto !== undefined ? { value: fromInt(auto, label), source: "caller" }
|
|
153
|
+
: flag !== undefined ? { value: flag ? "on" : "off", source: "caller" }
|
|
154
|
+
: current;
|
|
155
|
+
const bedLeveling = choose(bed, caller.autoBedLeveling, caller.bedLeveling, "auto_bed_leveling");
|
|
156
|
+
const flowCali = choose(flow, caller.autoFlowCali, caller.flowCalibration, "auto_flow_cali");
|
|
157
|
+
const nozzleOffset = choose(offset, caller.autoOffsetCali, undefined, "auto_offset_cali");
|
|
158
|
+
const manualMode = caller.extruderCaliManualMode ?? 0;
|
|
159
|
+
if (!Number.isInteger(manualMode) || manualMode < -1 || manualMode > 1)
|
|
160
|
+
throw new Error("extruder_cali_manual_mode must be -1, 0 or 1.");
|
|
161
|
+
return {
|
|
162
|
+
...(printerType ? { printerType } : {}),
|
|
163
|
+
values: { bed_leveling: bedLeveling.value, flow_cali: flowCali.value, nozzle_offset_cali: nozzleOffset.value },
|
|
164
|
+
sources: { bed_leveling: bedLeveling.source, flow_cali: flowCali.source, nozzle_offset_cali: nozzleOffset.source },
|
|
165
|
+
task_bed_leveling: bedLeveling.value === "on",
|
|
166
|
+
task_flow_cali: flowCali.value === "on",
|
|
167
|
+
task_vibration_cali: caller.vibrationCalibration ?? false,
|
|
168
|
+
task_layer_inspect: caller.layerInspect ?? true,
|
|
169
|
+
auto_bed_leveling: toInt(bedLeveling.value),
|
|
170
|
+
auto_flow_cali: toInt(flowCali.value),
|
|
171
|
+
auto_offset_cali: toInt(nozzleOffset.value),
|
|
172
|
+
extruder_cali_manual_mode: manualMode,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** The number of nozzles a job's used filaments print from, when the inspection knows. */
|
|
176
|
+
export function usedNozzleCount(inspection) {
|
|
177
|
+
const nozzles = inspection.usedFilamentPositions.map(position => inspection.filamentNozzleIndices?.[position]).filter((value) => Number.isInteger(value));
|
|
178
|
+
return nozzles.length === inspection.usedFilamentPositions.length && nozzles.length ? new Set(nozzles).size : undefined;
|
|
179
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bambu-printer-mcp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.51",
|
|
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": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"start:stdio": "MCP_TRANSPORT=stdio node dist/index.js",
|
|
14
14
|
"start:http": "MCP_TRANSPORT=streamable-http node dist/index.js",
|
|
15
15
|
"build": "tsc",
|
|
16
|
-
"test": "npm run build && node --test tests/*.test.mjs tests/**/*.test.mjs",
|
|
16
|
+
"test": "npm run build && node --test --import ./tests/support/isolate-studio-config.mjs tests/*.test.mjs tests/**/*.test.mjs",
|
|
17
17
|
"package:mcpb": "npm run build && node scripts/package-mcpb.mjs",
|
|
18
18
|
"version": "node scripts/sync-manifest-version.mjs",
|
|
19
19
|
"postinstall": "node scripts/install-patches.mjs",
|
package/src/bambu-native.ts
CHANGED
|
@@ -25,6 +25,11 @@ export type BambuNativePrintOptions = {
|
|
|
25
25
|
flowCalibration?: boolean;
|
|
26
26
|
vibrationCalibration?: boolean;
|
|
27
27
|
layerInspect?: boolean;
|
|
28
|
+
/** Bambu Studio's PrintParams auto_* values (0 off, 1 on, 2 auto) and extruder_cali_manual_mode. */
|
|
29
|
+
autoBedLeveling?: number;
|
|
30
|
+
autoFlowCali?: number;
|
|
31
|
+
autoOffsetCali?: number;
|
|
32
|
+
extruderCaliManualMode?: number;
|
|
28
33
|
timelapse?: boolean;
|
|
29
34
|
/** true: the SD card or USB stick; false: internal storage (eMMC); unset: BAMBU_NATIVE_TRY_EMMC_PRINT or internal. Reported as the requested storage. */
|
|
30
35
|
externalStorage?: boolean;
|
|
@@ -863,8 +868,13 @@ export async function printWithBambuNative(
|
|
|
863
868
|
BAMBU_NATIVE_NOZZLES_INFO: options.nozzlesInfo || "",
|
|
864
869
|
BAMBU_NATIVE_BED_LEVELING: boolEnv(options.bedLeveling, true),
|
|
865
870
|
BAMBU_NATIVE_FLOW_CALIBRATION: boolEnv(options.flowCalibration, true),
|
|
866
|
-
|
|
867
|
-
|
|
871
|
+
// Bambu Studio's Send dialog hard-codes these (SelectMachine.cpp:3344-3356).
|
|
872
|
+
BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, false),
|
|
873
|
+
BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, true),
|
|
874
|
+
...(options.autoBedLeveling === undefined ? {} : { BAMBU_NATIVE_AUTO_BED_LEVELING: String(options.autoBedLeveling) }),
|
|
875
|
+
...(options.autoFlowCali === undefined ? {} : { BAMBU_NATIVE_AUTO_FLOW_CALI: String(options.autoFlowCali) }),
|
|
876
|
+
...(options.autoOffsetCali === undefined ? {} : { BAMBU_NATIVE_AUTO_OFFSET_CALI: String(options.autoOffsetCali) }),
|
|
877
|
+
...(options.extruderCaliManualMode === undefined ? {} : { BAMBU_NATIVE_EXTRUDER_CALI_MANUAL_MODE: String(options.extruderCaliManualMode) }),
|
|
868
878
|
BAMBU_NATIVE_TIMELAPSE: boolEnv(options.timelapse, false),
|
|
869
879
|
...(options.externalStorage === undefined ? {} : { BAMBU_NATIVE_TRY_EMMC_PRINT: String(!options.externalStorage) }),
|
|
870
880
|
},
|
|
@@ -922,8 +932,13 @@ export async function uploadWithBambuNative(
|
|
|
922
932
|
BAMBU_NATIVE_NOZZLES_INFO: options.nozzlesInfo || "",
|
|
923
933
|
BAMBU_NATIVE_BED_LEVELING: boolEnv(options.bedLeveling, true),
|
|
924
934
|
BAMBU_NATIVE_FLOW_CALIBRATION: boolEnv(options.flowCalibration, true),
|
|
925
|
-
|
|
926
|
-
|
|
935
|
+
// Bambu Studio's Send dialog hard-codes these (SelectMachine.cpp:3344-3356).
|
|
936
|
+
BAMBU_NATIVE_VIBRATION_CALIBRATION: boolEnv(options.vibrationCalibration, false),
|
|
937
|
+
BAMBU_NATIVE_LAYER_INSPECT: boolEnv(options.layerInspect, true),
|
|
938
|
+
...(options.autoBedLeveling === undefined ? {} : { BAMBU_NATIVE_AUTO_BED_LEVELING: String(options.autoBedLeveling) }),
|
|
939
|
+
...(options.autoFlowCali === undefined ? {} : { BAMBU_NATIVE_AUTO_FLOW_CALI: String(options.autoFlowCali) }),
|
|
940
|
+
...(options.autoOffsetCali === undefined ? {} : { BAMBU_NATIVE_AUTO_OFFSET_CALI: String(options.autoOffsetCali) }),
|
|
941
|
+
...(options.extruderCaliManualMode === undefined ? {} : { BAMBU_NATIVE_EXTRUDER_CALI_MANUAL_MODE: String(options.extruderCaliManualMode) }),
|
|
927
942
|
BAMBU_NATIVE_TIMELAPSE: boolEnv(options.timelapse, false),
|
|
928
943
|
},
|
|
929
944
|
300_000,
|
|
@@ -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, type HmsText } 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, type PrintProgress, type PrintState, type Problem, type ProblemSeverity, type Temperature } from "./schemas.js";
|
|
@@ -77,7 +78,7 @@ export function bambuProblems(raw: Record<string, any>, serial: string, model: s
|
|
|
77
78
|
// 0300400C only records a cancel; it is the state, not a problem.
|
|
78
79
|
if (error !== undefined && Number.isInteger(error) && error > 0 && error <= 0xffffffff && error !== TASK_CANCELLED) {
|
|
79
80
|
const code = error.toString(16).padStart(8, "0").toUpperCase();
|
|
80
|
-
add({ code, severity: "error", message: tableText(PRINT_ERROR_MESSAGES, code, serial) ?? undocumented(code) });
|
|
81
|
+
add({ code, severity: "error", message: tableText(PRINT_ERROR_MESSAGES, code, serial) ?? studioDownloadedText("error", code, serial) ?? undocumented(code) });
|
|
81
82
|
}
|
|
82
83
|
for (const reported of Array.isArray(raw.hms) ? raw.hms : []) {
|
|
83
84
|
const entry = hmsCode(reported);
|
|
@@ -93,7 +94,8 @@ export function bambuProblems(raw: Record<string, any>, serial: string, model: s
|
|
|
93
94
|
add({
|
|
94
95
|
code,
|
|
95
96
|
severity: HMS_SEVERITIES[entry.severity] ?? "error",
|
|
96
|
-
|
|
97
|
+
// The pinned tag bundles no P1, X1 or A1 table; the user's own Studio download may have the text.
|
|
98
|
+
message: tableText(HMS_MESSAGES, entry.hex, serial) ?? studioDownloadedText("hms", entry.hex, serial) ?? undocumented(code),
|
|
97
99
|
url: hmsUrl(entry.hex),
|
|
98
100
|
});
|
|
99
101
|
}
|
package/src/fusion-mcp-bridge.ts
CHANGED
|
@@ -72,9 +72,11 @@ export const defaultFusionSystem: FusionSystem = {
|
|
|
72
72
|
/**
|
|
73
73
|
* An open port is not enough: Blender's MCP add-on defaults to
|
|
74
74
|
* localhost:9876, the add-in's own default. The add-in speaks newline-delimited JSON
|
|
75
|
-
* (addon/server/socket_server.py) and answers {"type":"ping"}
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* (addon/server/socket_server.py) and answers {"type":"ping"} without touching
|
|
76
|
+
* Fusion's API: on its fast path (event_bridge.py) with
|
|
77
|
+
* {"status":"success","result":{"ok":true,"status":"pong"}}, and through its
|
|
78
|
+
* command handler with {"pong":true}. Blender's add-on answers an unknown command
|
|
79
|
+
* with an error.
|
|
78
80
|
*/
|
|
79
81
|
addinAnswers: (host, port, timeoutMs) => new Promise(resolve => {
|
|
80
82
|
const socket = net.connect({ host, port });
|
|
@@ -96,7 +98,7 @@ export const defaultFusionSystem: FusionSystem = {
|
|
|
96
98
|
const newline = buffer.indexOf("\n");
|
|
97
99
|
try {
|
|
98
100
|
const reply = JSON.parse(newline >= 0 ? buffer.slice(0, newline) : buffer);
|
|
99
|
-
done(reply?.status === "success" && reply?.result?.pong === true);
|
|
101
|
+
done(reply?.status === "success" && (reply?.result?.status === "pong" || reply?.result?.pong === true));
|
|
100
102
|
} catch {
|
|
101
103
|
if (newline >= 0) done(false);
|
|
102
104
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
STLManipulator,
|
|
22
22
|
SLICER_TYPES,
|
|
23
23
|
normalizeSlicerType,
|
|
24
|
+
SlicerRunError,
|
|
24
25
|
type BambuSliceOptions,
|
|
25
26
|
type SlicerType,
|
|
26
27
|
} from "./stl/stl-manipulator.js";
|
|
@@ -45,6 +46,7 @@ import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, h
|
|
|
45
46
|
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
|
|
46
47
|
import type { ThreeMFAmsRequirements } from "./types.js";
|
|
47
48
|
import { BambuImplementation, assertDirectPrintSupported, checkedFile } from "./printers/bambu.js";
|
|
49
|
+
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "./studio-print-options.js";
|
|
48
50
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
49
51
|
import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
50
52
|
import { isDualNozzleModel } from "./safety/limits.js";
|
|
@@ -158,6 +160,28 @@ function assertUniformCliNozzles(args: Record<string, any>): void {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2dpro", "h2s", "h2c", "x2d"] as const;
|
|
163
|
+
|
|
164
|
+
/** The Send dialog options a caller set explicitly; the rest resolve as Bambu Studio does (studio-print-options.ts). */
|
|
165
|
+
function callerPrintOptions(args: Record<string, any> | undefined): CallerPrintOptions {
|
|
166
|
+
const flag = (value: unknown) => value === undefined ? undefined : Boolean(value);
|
|
167
|
+
const int = (value: unknown, label: string) => {
|
|
168
|
+
if (value === undefined) return undefined;
|
|
169
|
+
const number = Number(value);
|
|
170
|
+
if (!Number.isInteger(number)) throw new Error(`${label} must be an integer.`);
|
|
171
|
+
return number;
|
|
172
|
+
};
|
|
173
|
+
const options: CallerPrintOptions = {
|
|
174
|
+
bedLeveling: flag(args?.bed_leveling),
|
|
175
|
+
flowCalibration: flag(args?.flow_calibration),
|
|
176
|
+
vibrationCalibration: flag(args?.vibration_calibration),
|
|
177
|
+
layerInspect: flag(args?.layer_inspect),
|
|
178
|
+
autoBedLeveling: int(args?.auto_bed_leveling, "auto_bed_leveling"),
|
|
179
|
+
autoFlowCali: int(args?.auto_flow_cali, "auto_flow_cali"),
|
|
180
|
+
autoOffsetCali: int(args?.auto_offset_cali, "auto_offset_cali"),
|
|
181
|
+
extruderCaliManualMode: int(args?.extruder_cali_manual_mode, "extruder_cali_manual_mode"),
|
|
182
|
+
};
|
|
183
|
+
return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)) as CallerPrintOptions;
|
|
184
|
+
}
|
|
161
185
|
type BambuModel = typeof VALID_BAMBU_MODELS[number];
|
|
162
186
|
// X2D uses the same project_file/ams_mapping2 family of LAN print fields as
|
|
163
187
|
// the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
|
|
@@ -910,6 +934,7 @@ type StructuredToolError = {
|
|
|
910
934
|
suggestion: string;
|
|
911
935
|
message: string;
|
|
912
936
|
tool: string;
|
|
937
|
+
slicer_result?: Record<string, unknown>;
|
|
913
938
|
};
|
|
914
939
|
|
|
915
940
|
type UploadGcodeSource = {
|
|
@@ -1646,6 +1671,8 @@ class BambuPrinterMCPServer {
|
|
|
1646
1671
|
return withPrinterOperation(devIp, devId, assertActive => withPrintSnapshot(threeMFPath, async (snapshot, retainForDispatchedUpload) => {
|
|
1647
1672
|
const inspection = await inspectPrintFile(snapshot, { model: printModel, nozzleDiameters: printNozzles, plateIndex, bedType: printBedType });
|
|
1648
1673
|
const resumeFile = await checkedFile(inspection, snapshot);
|
|
1674
|
+
// The options Bambu Studio's Send dialog would send; explicit ones win.
|
|
1675
|
+
const studio = resolveStudioPrintOptions(printModel, callerPrintOptions(args), { usedNozzles: usedNozzleCount(inspection) });
|
|
1649
1676
|
let mapping = finalAmsMapping?.slice();
|
|
1650
1677
|
if (finalAmsSlots) {
|
|
1651
1678
|
if (finalAmsSlots.length !== inspection.usedFilamentPositions.length) throw new Error("ams_slots must supply exactly one physical tray per used filament.");
|
|
@@ -1709,18 +1736,18 @@ class BambuPrinterMCPServer {
|
|
|
1709
1736
|
use_ssl_for_mqtt: args?.use_ssl_for_mqtt !== undefined ? Boolean(args.use_ssl_for_mqtt) : true,
|
|
1710
1737
|
username: String(args?.username || "bblp"),
|
|
1711
1738
|
password,
|
|
1712
|
-
task_bed_leveling:
|
|
1713
|
-
task_flow_cali:
|
|
1714
|
-
task_vibration_cali:
|
|
1715
|
-
task_layer_inspect:
|
|
1739
|
+
task_bed_leveling: studio.task_bed_leveling,
|
|
1740
|
+
task_flow_cali: studio.task_flow_cali,
|
|
1741
|
+
task_vibration_cali: studio.task_vibration_cali,
|
|
1742
|
+
task_layer_inspect: studio.task_layer_inspect,
|
|
1716
1743
|
task_record_timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : false,
|
|
1717
1744
|
task_use_ams: useAMS,
|
|
1718
1745
|
task_bed_type: printBedType,
|
|
1719
1746
|
extra_options: stringifyBridgeJson(args?.extra_options) || "",
|
|
1720
|
-
auto_bed_leveling:
|
|
1721
|
-
auto_flow_cali:
|
|
1722
|
-
auto_offset_cali:
|
|
1723
|
-
extruder_cali_manual_mode:
|
|
1747
|
+
auto_bed_leveling: studio.auto_bed_leveling,
|
|
1748
|
+
auto_flow_cali: studio.auto_flow_cali,
|
|
1749
|
+
auto_offset_cali: studio.auto_offset_cali,
|
|
1750
|
+
extruder_cali_manual_mode: studio.extruder_cali_manual_mode,
|
|
1724
1751
|
task_ext_change_assist: args?.external_change_assist !== undefined ? Boolean(args.external_change_assist) : false,
|
|
1725
1752
|
try_emmc_print: args?.try_emmc_print !== undefined ? Boolean(args.try_emmc_print) : false,
|
|
1726
1753
|
};
|
|
@@ -1743,6 +1770,10 @@ class BambuPrinterMCPServer {
|
|
|
1743
1770
|
flowCalibration: params.task_flow_cali as boolean,
|
|
1744
1771
|
vibrationCalibration: params.task_vibration_cali as boolean,
|
|
1745
1772
|
layerInspect: params.task_layer_inspect as boolean,
|
|
1773
|
+
autoBedLeveling: studio.auto_bed_leveling,
|
|
1774
|
+
autoFlowCali: studio.auto_flow_cali,
|
|
1775
|
+
autoOffsetCali: studio.auto_offset_cali,
|
|
1776
|
+
extruderCaliManualMode: studio.extruder_cali_manual_mode,
|
|
1746
1777
|
timelapse: params.task_record_timelapse as boolean,
|
|
1747
1778
|
externalStorage,
|
|
1748
1779
|
}, native.onUpdate, { signal: native.signal, assertActive, beforeDispatch: async () => {
|
|
@@ -2511,7 +2542,7 @@ class BambuPrinterMCPServer {
|
|
|
2511
2542
|
},
|
|
2512
2543
|
{
|
|
2513
2544
|
name: "slice_stl",
|
|
2514
|
-
description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer.",
|
|
2545
|
+
description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer. The text result is the sliced file's path. When Bambu Studio or OrcaSlicer writes a result.json, structuredContent.slicer_result carries it verbatim, success or error: error_string, return_code and each sliced_plates[].warning_message, such as a floating cantilever. A failed slice's text starts with those words.",
|
|
2515
2546
|
inputSchema: {
|
|
2516
2547
|
type: "object",
|
|
2517
2548
|
properties: {
|
|
@@ -2680,10 +2711,10 @@ class BambuPrinterMCPServer {
|
|
|
2680
2711
|
ams_mapping_info: { type: "string", description: "Raw JSON string for FULU PrintParams ams_mapping_info, matching OrcaSlicer-bambulab's detailed AMS mapping field." },
|
|
2681
2712
|
nozzle_mapping: { type: "string", description: "Raw JSON string for FULU PrintParams nozzle_mapping." },
|
|
2682
2713
|
nozzles_info: { type: "string", description: "Raw JSON string for FULU PrintParams nozzles_info." },
|
|
2683
|
-
bed_leveling: { type: "boolean", description: "
|
|
2684
|
-
flow_calibration: { type: "boolean", description: "
|
|
2685
|
-
vibration_calibration: { type: "boolean", description: "
|
|
2686
|
-
layer_inspect: { type: "boolean", description: "
|
|
2714
|
+
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." },
|
|
2715
|
+
flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
|
|
2716
|
+
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
2717
|
+
layer_inspect: { type: "boolean", description: "First-layer inspection where supported (default true, as Bambu Studio sends)." },
|
|
2687
2718
|
timelapse: { type: "boolean", description: "Enable timelapse recording in FULU PrintParams (default: false)." },
|
|
2688
2719
|
use_ssl_for_ftp: { type: "boolean", description: "Whether FULU local print should use SSL for FTP (default: true)." },
|
|
2689
2720
|
use_ssl_for_mqtt: { type: "boolean", description: "Whether FULU local print should use SSL for MQTT (default: true)." },
|
|
@@ -3115,9 +3146,9 @@ class BambuPrinterMCPServer {
|
|
|
3115
3146
|
type: "boolean",
|
|
3116
3147
|
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."
|
|
3117
3148
|
},
|
|
3118
|
-
bed_leveling: { type: "boolean", description: "
|
|
3119
|
-
flow_calibration: { type: "boolean", description: "
|
|
3120
|
-
vibration_calibration: { type: "boolean", description: "
|
|
3149
|
+
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." },
|
|
3150
|
+
flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
|
|
3151
|
+
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
3121
3152
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
3122
3153
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
3123
3154
|
template_3mf_path: { type: "string", description: "Optional template 3MF whose embedded Bambu slicer settings should be reused when auto-slicing this print job." },
|
|
@@ -3151,9 +3182,9 @@ class BambuPrinterMCPServer {
|
|
|
3151
3182
|
enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
|
|
3152
3183
|
description: "Bed plate type currently installed (default: textured_plate)"
|
|
3153
3184
|
},
|
|
3154
|
-
bed_leveling: { type: "boolean", description: "
|
|
3155
|
-
flow_calibration: { type: "boolean", description: "
|
|
3156
|
-
vibration_calibration: { type: "boolean", description: "
|
|
3185
|
+
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." },
|
|
3186
|
+
flow_calibration: { type: "boolean", description: "Flow calibration on or off. Omit to send what Bambu Studio's Send dialog would (auto on P1/P1S)." },
|
|
3187
|
+
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
3157
3188
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
3158
3189
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
3159
3190
|
nozzle_diameter: { type: "string", description: "Nozzle diameter in mm for auto-slicing (default: 0.4)" }
|
|
@@ -3186,7 +3217,7 @@ class BambuPrinterMCPServer {
|
|
|
3186
3217
|
},
|
|
3187
3218
|
{
|
|
3188
3219
|
name: "lay_flat",
|
|
3189
|
-
description: "Rotate the model so
|
|
3220
|
+
description: "Rotate the model so a face rests on the bed (Z=0), choosing the orientation with the least part and support volume per mm² of bed contact. A face counts only if nothing hangs below it. Returns the new STL path; structuredContent.laid_flat is false, with the input path, when no orientation qualifies.",
|
|
3190
3221
|
inputSchema: {
|
|
3191
3222
|
type: "object",
|
|
3192
3223
|
properties: {
|
|
@@ -4240,14 +4271,16 @@ class BambuPrinterMCPServer {
|
|
|
4240
4271
|
}
|
|
4241
4272
|
}
|
|
4242
4273
|
|
|
4243
|
-
|
|
4274
|
+
const sliced = await this.stlManipulator.sliceSTLWithResult(
|
|
4244
4275
|
String(args.stl_path), slicerType, slicerPath,
|
|
4245
4276
|
activeSlicerProfile,
|
|
4246
4277
|
undefined, // progressCallback
|
|
4247
4278
|
printerPreset,
|
|
4248
4279
|
sliceBambuOptions
|
|
4249
4280
|
);
|
|
4250
|
-
|
|
4281
|
+
await progressNotifications;
|
|
4282
|
+
// The text stays the sliced file's path; slicer_result is the slicer's own result.json, verbatim.
|
|
4283
|
+
return { content: [{ type: "text", text: sliced.path }], structuredContent: sliced };
|
|
4251
4284
|
}
|
|
4252
4285
|
|
|
4253
4286
|
case "print_3mf": {
|
|
@@ -4459,10 +4492,7 @@ class BambuPrinterMCPServer {
|
|
|
4459
4492
|
amsMapping: finalAmsMapping,
|
|
4460
4493
|
amsSlots: finalAmsSlots,
|
|
4461
4494
|
bedType: printBedType,
|
|
4462
|
-
|
|
4463
|
-
flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : undefined,
|
|
4464
|
-
vibrationCalibration: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : undefined,
|
|
4465
|
-
layerInspect: args?.layer_inspect !== undefined ? Boolean(args.layer_inspect) : undefined,
|
|
4495
|
+
...callerPrintOptions(args),
|
|
4466
4496
|
timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : undefined,
|
|
4467
4497
|
});
|
|
4468
4498
|
// Report what the printer did, not merely that a command was published.
|
|
@@ -4527,9 +4557,7 @@ class BambuPrinterMCPServer {
|
|
|
4527
4557
|
useAMS: true,
|
|
4528
4558
|
amsSlots: collarAnalysis.amsSlots,
|
|
4529
4559
|
bedType: printBedType,
|
|
4530
|
-
|
|
4531
|
-
flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : true,
|
|
4532
|
-
vibrationCalibration: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : true,
|
|
4560
|
+
...callerPrintOptions(args),
|
|
4533
4561
|
timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : false,
|
|
4534
4562
|
});
|
|
4535
4563
|
|
|
@@ -4574,10 +4602,13 @@ class BambuPrinterMCPServer {
|
|
|
4574
4602
|
result = await this.stlManipulator.centerModel(String(args.stl_path));
|
|
4575
4603
|
break;
|
|
4576
4604
|
|
|
4577
|
-
case "lay_flat":
|
|
4605
|
+
case "lay_flat": {
|
|
4578
4606
|
if (!args?.stl_path) throw new Error("Missing required parameter: stl_path");
|
|
4579
|
-
|
|
4580
|
-
|
|
4607
|
+
const layFlatResult = await this.stlManipulator.layFlatWithResult(String(args.stl_path));
|
|
4608
|
+
await progressNotifications;
|
|
4609
|
+
// The text stays the STL path clients read; structuredContent says whether it was laid flat.
|
|
4610
|
+
return { content: [{ type: "text", text: layFlatResult.path }], structuredContent: layFlatResult };
|
|
4611
|
+
}
|
|
4581
4612
|
|
|
4582
4613
|
case "blender_mcp_status":
|
|
4583
4614
|
result = await this.blender.status(args ?? {}, extra.signal);
|
|
@@ -4662,12 +4693,15 @@ class BambuPrinterMCPServer {
|
|
|
4662
4693
|
: `Check parameters and try again. Error: ${message}`,
|
|
4663
4694
|
message,
|
|
4664
4695
|
tool: name,
|
|
4696
|
+
// The slicer's own result.json; the message starts with its error_string and warnings.
|
|
4697
|
+
...(error instanceof SlicerRunError && error.slicerResult ? { slicer_result: error.slicerResult } : {}),
|
|
4665
4698
|
};
|
|
4666
4699
|
|
|
4667
4700
|
// MCP clients validate structuredContent against a declared outputSchema even on
|
|
4668
4701
|
// errors (SDK 1.32 Client.callTool), so those tools return the error as text only.
|
|
4669
4702
|
return {
|
|
4670
|
-
|
|
4703
|
+
// A slicer failure leads with the slicer's own words.
|
|
4704
|
+
content: [{ type: "text", text: error instanceof SlicerRunError && error.slicerText ? message : `Error: ${message}` }],
|
|
4671
4705
|
...(OUTPUT_SCHEMA_TOOLS.has(name) ? {} : { structuredContent: structured }),
|
|
4672
4706
|
isError: true,
|
|
4673
4707
|
};
|