bambu-printer-mcp 1.0.8 → 1.1.4

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/dist/index.js CHANGED
@@ -10,30 +10,348 @@ import { createServer as createHttpServer } from "node:http";
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { STLManipulator, SLICER_TYPES, normalizeSlicerType, } from "./stl/stl-manipulator.js";
12
12
  import { BambuNetworkBridge } from "./bambu-network-bridge.js";
13
- import { parse3MF } from './3mf_parser.js';
13
+ import { hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue } from "./ams-mapping.js";
14
+ import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
14
15
  import { BambuImplementation } from "./printers/bambu.js";
15
16
  dotenv.config();
16
- const DEFAULT_HOST = process.env.PRINTER_HOST || "localhost";
17
- const DEFAULT_BAMBU_SERIAL = process.env.BAMBU_SERIAL || "";
18
- const DEFAULT_BAMBU_TOKEN = process.env.BAMBU_TOKEN || "";
17
+ const DEFAULT_HOST = process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST || "localhost";
18
+ const DEFAULT_BAMBU_SERIAL = process.env.BAMBU_PRINTER_SERIAL || process.env.BAMBU_SERIAL || "";
19
+ const DEFAULT_BAMBU_TOKEN = process.env.BAMBU_PRINTER_ACCESS_TOKEN || process.env.BAMBU_TOKEN || "";
19
20
  const DEFAULT_BAMBU_DEV_ID = process.env.BAMBU_DEV_ID || DEFAULT_BAMBU_SERIAL;
20
21
  const TEMP_DIR = process.env.TEMP_DIR || path.join(process.cwd(), "temp");
21
22
  // Printer model and bed type
22
- const DEFAULT_BAMBU_MODEL = process.env.BAMBU_MODEL?.trim().toLowerCase() || "";
23
+ const DEFAULT_BAMBU_MODEL = process.env.BAMBU_PRINTER_MODEL?.trim().toLowerCase() ||
24
+ process.env.BAMBU_MODEL?.trim().toLowerCase() ||
25
+ "";
23
26
  const DEFAULT_BED_TYPE = process.env.BED_TYPE?.trim().toLowerCase() || "textured_plate";
24
27
  const DEFAULT_NOZZLE_DIAMETER = process.env.NOZZLE_DIAMETER?.trim() || "0.4";
25
- const VALID_BAMBU_MODELS = ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"];
26
- const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate"];
28
+ const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2s", "h2c"];
29
+ const H2_BAMBU_MODELS = new Set(["h2d", "h2s", "h2c"]);
30
+ const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"];
31
+ const VALID_BAMBUSTUDIO_CLI_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate"];
27
32
  // Map model IDs to BambuStudio --load-machine preset names
28
33
  const BAMBU_MODEL_PRESETS = {
29
34
  p1s: (n) => `Bambu Lab P1S ${n} nozzle`,
30
35
  p1p: (n) => `Bambu Lab P1P ${n} nozzle`,
36
+ p2s: (n) => `Bambu Lab P2S ${n} nozzle`,
31
37
  x1c: (n) => `Bambu Lab X1 Carbon ${n} nozzle`,
32
38
  x1e: (n) => `Bambu Lab X1E ${n} nozzle`,
33
39
  a1: (n) => `Bambu Lab A1 ${n} nozzle`,
34
40
  a1mini: (n) => `Bambu Lab A1 mini ${n} nozzle`,
35
41
  h2d: (n) => `Bambu Lab H2D ${n} nozzle`,
42
+ h2s: (n) => `Bambu Lab H2S ${n} nozzle`,
43
+ h2c: (n) => `Bambu Lab H2C ${n} nozzle`,
36
44
  };
45
+ const FILAMENT_PROFILE_DIR = "/Applications/BambuStudio.app/Contents/Resources/profiles/BBL/filament";
46
+ const FILAMENT_MODEL_CODES = {
47
+ p1s: "P1S",
48
+ p1p: "P1P",
49
+ p2s: "P2S",
50
+ x1c: "X1C",
51
+ x1e: "X1E",
52
+ a1: "A1",
53
+ a1mini: "A1M",
54
+ h2d: "H2D",
55
+ h2s: "H2S",
56
+ h2c: "H2C",
57
+ };
58
+ const COLLAR_CHARM_POLICY = getCollarCharmRolePolicy();
59
+ let filamentProfileIndexCache = null;
60
+ function buildFilamentProfileIndex() {
61
+ const byName = new Map();
62
+ const baseNameByFilamentId = new Map();
63
+ if (!fs.existsSync(FILAMENT_PROFILE_DIR)) {
64
+ return { byName, baseNameByFilamentId };
65
+ }
66
+ for (const entry of fs.readdirSync(FILAMENT_PROFILE_DIR)) {
67
+ if (!entry.endsWith(".json"))
68
+ continue;
69
+ const filePath = path.join(FILAMENT_PROFILE_DIR, entry);
70
+ try {
71
+ const raw = fs.readFileSync(filePath, "utf8");
72
+ const parsed = JSON.parse(raw);
73
+ const name = typeof parsed?.name === "string" ? parsed.name.trim() : "";
74
+ const filamentId = typeof parsed?.filament_id === "string" ? parsed.filament_id.trim() : "";
75
+ if (name) {
76
+ byName.set(name, filePath);
77
+ }
78
+ if (name && filamentId) {
79
+ baseNameByFilamentId.set(filamentId, name);
80
+ }
81
+ }
82
+ catch {
83
+ // Ignore malformed or non-profile JSON files.
84
+ }
85
+ }
86
+ return { byName, baseNameByFilamentId };
87
+ }
88
+ function getFilamentProfileIndex() {
89
+ if (!filamentProfileIndexCache) {
90
+ filamentProfileIndexCache = buildFilamentProfileIndex();
91
+ }
92
+ return filamentProfileIndexCache;
93
+ }
94
+ function resolveFilamentProfileCandidates(trayInfoIdx, bambuModel, nozzleDiameter) {
95
+ const index = getFilamentProfileIndex();
96
+ const baseName = index.baseNameByFilamentId.get(trayInfoIdx) || null;
97
+ if (!baseName) {
98
+ return { baseName: null, paths: [], resolution: "unresolved" };
99
+ }
100
+ const bareName = baseName.replace(/\s*@base$/, "");
101
+ const modelCode = bambuModel ? FILAMENT_MODEL_CODES[bambuModel] : undefined;
102
+ const candidateNames = [];
103
+ if (modelCode && nozzleDiameter) {
104
+ candidateNames.push(`${bareName} @BBL ${modelCode} ${nozzleDiameter} nozzle`);
105
+ }
106
+ if (modelCode) {
107
+ candidateNames.push(`${bareName} @BBL ${modelCode}`);
108
+ }
109
+ candidateNames.push(bareName, baseName);
110
+ const resolvedPaths = [];
111
+ let resolution = "unresolved";
112
+ for (const [candidateIndex, candidateName] of candidateNames.entries()) {
113
+ const candidatePath = index.byName.get(candidateName);
114
+ if (!candidatePath || resolvedPaths.includes(candidatePath))
115
+ continue;
116
+ resolvedPaths.push(candidatePath);
117
+ if (resolution === "unresolved") {
118
+ if (candidateIndex === 0 && modelCode && nozzleDiameter) {
119
+ resolution = "exact-model-nozzle";
120
+ }
121
+ else if ((candidateIndex === 0 && modelCode && !nozzleDiameter) ||
122
+ (candidateIndex === 1 && modelCode && nozzleDiameter)) {
123
+ resolution = "model";
124
+ }
125
+ else {
126
+ resolution = "generic";
127
+ }
128
+ }
129
+ }
130
+ return { baseName, paths: resolvedPaths, resolution };
131
+ }
132
+ function parseIntegerOrNull(value) {
133
+ if (value === undefined || value === null || value === "")
134
+ return null;
135
+ const parsed = Number.parseInt(String(value), 10);
136
+ return Number.isFinite(parsed) ? parsed : null;
137
+ }
138
+ function normalizePrinterFilamentInventory(status, bambuModel, nozzleDiameter) {
139
+ const rawAms = status?.raw?.ams || status?.ams || {};
140
+ const trayNow = parseIntegerOrNull(rawAms?.tray_now);
141
+ const trays = [];
142
+ const amsArray = Array.isArray(rawAms?.ams) ? rawAms.ams : [];
143
+ for (const [amsIndex, amsUnit] of amsArray.entries()) {
144
+ const trayArray = Array.isArray(amsUnit?.tray) ? amsUnit.tray : [];
145
+ for (const [trayIndex, tray] of trayArray.entries()) {
146
+ const amsId = parseIntegerOrNull(amsUnit?.id) ?? amsIndex;
147
+ const trayId = parseIntegerOrNull(tray?.id) ?? trayIndex;
148
+ const slot = amsId !== null && trayId !== null ? amsId * 4 + trayId : null;
149
+ const state = parseIntegerOrNull(tray?.state) ?? 0;
150
+ const trayInfoIdx = typeof tray?.tray_info_idx === "string" ? tray.tray_info_idx : null;
151
+ const profileResolution = trayInfoIdx
152
+ ? resolveFilamentProfileCandidates(trayInfoIdx, bambuModel, nozzleDiameter)
153
+ : { baseName: null, paths: [], resolution: "unresolved" };
154
+ const resolvedProfilePath = profileResolution.paths[0] || null;
155
+ const matchConfidence = profileResolution.resolution === "exact-model-nozzle" ? "high" :
156
+ profileResolution.resolution === "model" ? "medium" :
157
+ profileResolution.resolution === "generic" ? "low" :
158
+ "none";
159
+ const trayType = typeof tray?.tray_type === "string" ? tray.tray_type : null;
160
+ const traySubBrands = typeof tray?.tray_sub_brands === "string" ? tray.tray_sub_brands : null;
161
+ const trayColor = typeof tray?.tray_color === "string" ? tray.tray_color : null;
162
+ const displayParts = [
163
+ traySubBrands && traySubBrands !== trayType ? traySubBrands : null,
164
+ trayType,
165
+ trayColor ? `#${normalizeRgbColor(trayColor) ?? trayColor.replace(/^#/, "").slice(0, 6)}` : null,
166
+ ].filter(Boolean);
167
+ trays.push({
168
+ ams_id: amsId,
169
+ tray_id: trayId,
170
+ slot,
171
+ state,
172
+ loaded: state !== 0 && Boolean(trayInfoIdx),
173
+ tray_info_idx: trayInfoIdx,
174
+ tray_type: trayType,
175
+ tray_sub_brands: traySubBrands,
176
+ tray_color: trayColor,
177
+ remain_percent: typeof tray?.remain === "number" && tray.remain >= 0 ? tray.remain : null,
178
+ nozzle_temp_min: parseIntegerOrNull(tray?.nozzle_temp_min),
179
+ nozzle_temp_max: parseIntegerOrNull(tray?.nozzle_temp_max),
180
+ resolved_base_profile_name: profileResolution.baseName,
181
+ resolved_profile_path: resolvedProfilePath,
182
+ profile_resolution: profileResolution.resolution,
183
+ match_confidence: matchConfidence,
184
+ display_name: displayParts.length > 0 ? displayParts.join(" ") : "empty/unknown",
185
+ profile_candidates: profileResolution.paths,
186
+ });
187
+ }
188
+ }
189
+ const loadedTrays = trays.filter((tray) => tray.loaded);
190
+ const recommendedTray = loadedTrays.find((tray) => tray.slot === trayNow && tray.resolved_profile_path) ||
191
+ loadedTrays.find((tray) => tray.resolved_profile_path) ||
192
+ null;
193
+ const recommendedReason = recommendedTray?.slot === trayNow
194
+ ? "current AMS slot with resolved slicer profile"
195
+ : recommendedTray
196
+ ? "first loaded AMS slot with resolved slicer profile"
197
+ : null;
198
+ const allProfilePaths = Array.from(new Set(loadedTrays
199
+ .map((tray) => tray.resolved_profile_path)
200
+ .filter((candidate) => Boolean(candidate))));
201
+ const emptySlots = trays.filter((tray) => !tray.loaded).length;
202
+ const resolvedProfileSlots = loadedTrays.filter((tray) => tray.resolved_profile_path).length;
203
+ return {
204
+ current_slot: trayNow !== null && trayNow >= 0 && trayNow < 254 ? trayNow : null,
205
+ current_source: trayNow === 254 ? "external" : trayNow !== null && trayNow >= 0 && trayNow < 254 ? "ams" : null,
206
+ summary: {
207
+ loaded_slots: loadedTrays.length,
208
+ resolved_profile_slots: resolvedProfileSlots,
209
+ unresolved_loaded_slots: loadedTrays.length - resolvedProfileSlots,
210
+ empty_slots: emptySlots,
211
+ current_slot: trayNow !== null && trayNow >= 0 && trayNow < 254 ? trayNow : null,
212
+ current_source: trayNow === 254 ? "external" : trayNow !== null && trayNow >= 0 && trayNow < 254 ? "ams" : null,
213
+ recommended_slot: recommendedTray?.slot ?? null,
214
+ recommended_reason: recommendedReason,
215
+ },
216
+ trays,
217
+ recommended: recommendedTray
218
+ ? {
219
+ slot: recommendedTray.slot,
220
+ tray_info_idx: recommendedTray.tray_info_idx,
221
+ tray_type: recommendedTray.tray_type,
222
+ resolved_profile_path: recommendedTray.resolved_profile_path,
223
+ load_filaments: recommendedTray.resolved_profile_path,
224
+ reason: recommendedReason ?? "resolved slicer profile",
225
+ }
226
+ : null,
227
+ load_filaments_all: allProfilePaths.length > 0 ? allProfilePaths.join(";") : null,
228
+ };
229
+ }
230
+ /**
231
+ * Normalize a hex color string to lowercase 6-char RGB (drop leading "#"
232
+ * and any trailing alpha bytes). Returns null if the input doesn't look
233
+ * like a hex color.
234
+ *
235
+ * Bambu mixes formats: 3MF project_settings stores `#FFFFFF` or
236
+ * `#FF911A80` (RGB or RGBA with leading #). AMS push_status reports
237
+ * `FFFFFFFF` (RGBA without #). Comparing alpha is risky -- the same
238
+ * filament can show up as `#000000` in one place and `000000FF` in
239
+ * another. RGB-only is the right key.
240
+ */
241
+ function normalizeRgbColor(color) {
242
+ if (!color)
243
+ return null;
244
+ const hex = color.replace(/^#/, "").toLowerCase();
245
+ if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(hex))
246
+ return null;
247
+ return hex.slice(0, 6);
248
+ }
249
+ function resolveAmsSlotsFromRequirements(requirements, inventory) {
250
+ const matches = [];
251
+ const missing = [];
252
+ const amsSlots = [];
253
+ // Track which AMS slots have already been claimed by an earlier
254
+ // requirement so two filaments with the same SKU don't collapse onto
255
+ // the same physical slot.
256
+ const claimedSlots = new Set();
257
+ for (const filament of requirements.filaments) {
258
+ if (!filament.tray_info_idx) {
259
+ missing.push({
260
+ filament_position: filament.filamentPosition,
261
+ tray_info_idx: null,
262
+ required_color: filament.color ?? null,
263
+ reason: "no_sku",
264
+ });
265
+ continue;
266
+ }
267
+ const requiredColor = normalizeRgbColor(filament.color);
268
+ // Pool of trays loaded with the required SKU that aren't already claimed.
269
+ const skuPool = inventory.trays.filter((candidate) => candidate.loaded &&
270
+ candidate.slot !== null &&
271
+ candidate.tray_info_idx === filament.tray_info_idx &&
272
+ !claimedSlots.has(candidate.slot));
273
+ if (skuPool.length === 0) {
274
+ // No trays of this SKU loaded at all (or all already claimed).
275
+ const reason = inventory.trays.some((t) => t.tray_info_idx === filament.tray_info_idx)
276
+ ? "exhausted"
277
+ : "no_loaded_match";
278
+ missing.push({
279
+ filament_position: filament.filamentPosition,
280
+ tray_info_idx: filament.tray_info_idx,
281
+ required_color: filament.color ?? null,
282
+ reason,
283
+ });
284
+ continue;
285
+ }
286
+ // Prefer an exact RGB color match. This is what disambiguates
287
+ // same-SKU different-color cases (e.g. two GFG02 PETG HF trays
288
+ // loaded -- one black, one white).
289
+ let chosen = skuPool.find((candidate) => normalizeRgbColor(candidate.tray_color) === requiredColor && requiredColor !== null);
290
+ let strategy = "color";
291
+ // Fall back to SKU-only when the requirement has no color (legacy
292
+ // 3MF) or when only one tray of this SKU is loaded (no ambiguity).
293
+ if (!chosen) {
294
+ if (!requiredColor || skuPool.length === 1) {
295
+ chosen = skuPool[0];
296
+ strategy = "sku-only";
297
+ }
298
+ else {
299
+ // Color was specified, multiple SKU candidates loaded, none
300
+ // match the requested color. Surface clearly rather than pick
301
+ // a wrong color silently.
302
+ missing.push({
303
+ filament_position: filament.filamentPosition,
304
+ tray_info_idx: filament.tray_info_idx,
305
+ required_color: filament.color ?? null,
306
+ reason: "color_mismatch",
307
+ });
308
+ continue;
309
+ }
310
+ }
311
+ if (chosen.slot === null) {
312
+ // Defensive: shouldn't happen because of the filter above, but
313
+ // keep the type contract honest.
314
+ missing.push({
315
+ filament_position: filament.filamentPosition,
316
+ tray_info_idx: filament.tray_info_idx,
317
+ required_color: filament.color ?? null,
318
+ reason: "no_loaded_match",
319
+ });
320
+ continue;
321
+ }
322
+ claimedSlots.add(chosen.slot);
323
+ amsSlots.push(chosen.slot);
324
+ matches.push({
325
+ filament_position: filament.filamentPosition,
326
+ tray_info_idx: filament.tray_info_idx,
327
+ slot: chosen.slot,
328
+ matched_color: chosen.tray_color ?? null,
329
+ match_strategy: strategy,
330
+ });
331
+ }
332
+ return { ams_slots: amsSlots, matches, missing };
333
+ }
334
+ function extractPrinterDiagnostics(status) {
335
+ const raw = status?.raw && typeof status.raw === "object" ? status.raw : {};
336
+ const diagnosticFields = {};
337
+ for (const [key, value] of Object.entries(raw)) {
338
+ if (/(hms|error|fail|warn)/i.test(key)) {
339
+ diagnosticFields[key] = value;
340
+ }
341
+ }
342
+ return {
343
+ connected: Boolean(status?.connected),
344
+ serial: status?.serial ?? null,
345
+ printer_status: status?.status ?? null,
346
+ active_error: raw.print_error ??
347
+ raw.print_error_code ??
348
+ raw.mc_print_error_code ??
349
+ raw.fail_reason ??
350
+ null,
351
+ hms: raw.hms ?? raw.hms_info ?? raw.hms_list ?? null,
352
+ diagnostic_fields: diagnosticFields,
353
+ };
354
+ }
37
355
  function validateBambuModel(model) {
38
356
  const normalized = model.trim().toLowerCase();
39
357
  if (!VALID_BAMBU_MODELS.includes(normalized)) {
@@ -48,9 +366,19 @@ function resolveBedType(argsBedType) {
48
366
  }
49
367
  return bedType;
50
368
  }
369
+ function resolveBambuStudioCliBedType(argsBedType) {
370
+ const bedType = resolveBedType(argsBedType);
371
+ if (!VALID_BAMBUSTUDIO_CLI_BED_TYPES.includes(bedType)) {
372
+ throw new Error(`BambuStudio CLI bed_type "${bedType}" is not verified. Use a pre-sliced 3MF for SuperTack, or choose one of: ${VALID_BAMBUSTUDIO_CLI_BED_TYPES.join(", ")}`);
373
+ }
374
+ return bedType;
375
+ }
51
376
  // Slicer configuration (defaults to bambustudio)
52
377
  const DEFAULT_SLICER_TYPE = process.env.SLICER_TYPE || "bambustudio";
53
- const DEFAULT_SLICER_PROFILE = process.env.SLICER_PROFILE || "";
378
+ const DEFAULT_SLICER_PROFILE = process.env.BAMBU_SLICER_PROFILE || process.env.SLICER_PROFILE || "";
379
+ const DEFAULT_TEMPLATE_3MF_PATH = process.env.BAMBU_TEMPLATE_3MF_PATH || "";
380
+ const DEFAULT_TEMPLATE_DIR = process.env.BAMBU_TEMPLATE_DIR ||
381
+ path.join(process.env.HOME || process.cwd(), "Sync", "bambu", "templates");
54
382
  const SLICER_SCHEMA_VALUES = [
55
383
  ...SLICER_TYPES,
56
384
  "fulu-orca",
@@ -76,6 +404,9 @@ function defaultSlicerPathFor(slicerType) {
76
404
  return "OrcaSlicer";
77
405
  }
78
406
  if (slicerType === "bambustudio") {
407
+ if (process.env.BAMBU_STUDIO_PATH) {
408
+ return process.env.BAMBU_STUDIO_PATH;
409
+ }
79
410
  if (process.platform === "darwin") {
80
411
  return "/Applications/BambuStudio.app/Contents/MacOS/BambuStudio";
81
412
  }
@@ -122,6 +453,37 @@ function parseCsvEnv(value) {
122
453
  return new Set();
123
454
  return new Set(value.split(",").map((e) => e.trim()).filter((e) => e.length > 0));
124
455
  }
456
+ async function resolveSlicerProfilePath(requestedProfile, templatePath, tempDir) {
457
+ if (requestedProfile) {
458
+ return requestedProfile;
459
+ }
460
+ if (templatePath) {
461
+ return resolveTemplateSlicerProfilePath(templatePath, tempDir);
462
+ }
463
+ return undefined;
464
+ }
465
+ async function resolveTemplateSlicerProfilePath(templatePath, tempDir) {
466
+ const extension = path.extname(templatePath).toLowerCase();
467
+ if (extension === ".3mf") {
468
+ return extractBambuTemplateSettings(templatePath, tempDir);
469
+ }
470
+ if (extension === ".json" || extension === ".config") {
471
+ return templatePath;
472
+ }
473
+ throw new Error(`Template profile must be a .3mf, .json, or .config file: ${templatePath}`);
474
+ }
475
+ function hasExplicitSlicerProfile(args) {
476
+ return typeof args?.slicer_profile === "string" && args.slicer_profile.trim().length > 0;
477
+ }
478
+ async function resolveTemplateFirstSlicerProfilePath(args, configuredProfile, template3mfPath, tempDir) {
479
+ if (hasExplicitSlicerProfile(args)) {
480
+ return configuredProfile || undefined;
481
+ }
482
+ if (template3mfPath) {
483
+ return resolveTemplateSlicerProfilePath(template3mfPath, tempDir);
484
+ }
485
+ return configuredProfile || undefined;
486
+ }
125
487
  function readRuntimeConfig() {
126
488
  const rawTransport = process.env.MCP_TRANSPORT?.trim().toLowerCase();
127
489
  const transport = rawTransport === "streamable-http" || rawTransport === "http"
@@ -248,6 +610,131 @@ function redactPrintParams(params) {
248
610
  password: params.password ? "[redacted]" : "",
249
611
  };
250
612
  }
613
+ function parseLooseSlicerConfig(content) {
614
+ try {
615
+ return JSON.parse(content);
616
+ }
617
+ catch {
618
+ const config = {};
619
+ for (const line of content.split(/\r?\n/)) {
620
+ const trimmed = line.trim();
621
+ if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith(";"))
622
+ continue;
623
+ const separatorIndex = trimmed.indexOf("=");
624
+ if (separatorIndex === -1)
625
+ continue;
626
+ const key = trimmed.slice(0, separatorIndex).trim();
627
+ const value = trimmed.slice(separatorIndex + 1).trim();
628
+ if (key) {
629
+ config[key] = value;
630
+ }
631
+ }
632
+ return config;
633
+ }
634
+ }
635
+ function summarizeSliceSettings(config) {
636
+ return {
637
+ printer_settings_id: typeof config.printer_settings_id === "string" ? config.printer_settings_id : null,
638
+ default_print_profile: typeof config.default_print_profile === "string" ? config.default_print_profile : null,
639
+ default_filament_profile: Array.isArray(config.default_filament_profile)
640
+ ? config.default_filament_profile
641
+ : typeof config.default_filament_profile === "string"
642
+ ? [config.default_filament_profile]
643
+ : [],
644
+ filament_settings_id: Array.isArray(config.filament_settings_id)
645
+ ? config.filament_settings_id.filter((value) => typeof value === "string" && value.length > 0)
646
+ : [],
647
+ filament_type: Array.isArray(config.filament_type)
648
+ ? config.filament_type.filter((value) => typeof value === "string" && value.length > 0)
649
+ : [],
650
+ inherits: typeof config.inherits === "string" ? config.inherits : null,
651
+ print_settings_id: typeof config.print_settings_id === "string" ? config.print_settings_id : null,
652
+ compatible_printers: Array.isArray(config.compatible_printers)
653
+ ? config.compatible_printers.filter((value) => typeof value === "string" && value.length > 0)
654
+ : [],
655
+ layer_height: config.layer_height !== undefined && config.layer_height !== null
656
+ ? Number(config.layer_height)
657
+ : null,
658
+ first_layer_height: config.initial_layer_print_height !== undefined && config.initial_layer_print_height !== null
659
+ ? Number(config.initial_layer_print_height)
660
+ : config.first_layer_height !== undefined && config.first_layer_height !== null
661
+ ? Number(config.first_layer_height)
662
+ : null,
663
+ sparse_infill_density: config.sparse_infill_density !== undefined && config.sparse_infill_density !== null
664
+ ? String(config.sparse_infill_density)
665
+ : null,
666
+ wall_loops: config.wall_loops !== undefined && config.wall_loops !== null
667
+ ? Number(config.wall_loops)
668
+ : null,
669
+ top_shell_layers: config.top_shell_layers !== undefined && config.top_shell_layers !== null
670
+ ? Number(config.top_shell_layers)
671
+ : null,
672
+ bottom_shell_layers: config.bottom_shell_layers !== undefined && config.bottom_shell_layers !== null
673
+ ? Number(config.bottom_shell_layers)
674
+ : null,
675
+ brim_width: config.brim_width !== undefined && config.brim_width !== null
676
+ ? Number(config.brim_width)
677
+ : null,
678
+ support_enabled: config.enable_support !== undefined
679
+ ? String(config.enable_support) === "1" || String(config.enable_support).toLowerCase() === "true"
680
+ : config.support_enabled !== undefined
681
+ ? Boolean(config.support_enabled)
682
+ : null,
683
+ support_type: typeof config.support_type === "string" ? config.support_type : null,
684
+ bed_type: typeof config.curr_bed_type === "string"
685
+ ? config.curr_bed_type
686
+ : typeof config.bed_type === "string"
687
+ ? config.bed_type
688
+ : null,
689
+ nozzle_temperature: Array.isArray(config.nozzle_temperature)
690
+ ? config.nozzle_temperature
691
+ : config.nozzle_temperature !== undefined
692
+ ? [config.nozzle_temperature]
693
+ : [],
694
+ };
695
+ }
696
+ function sanitizeTemplateName(templateName) {
697
+ return templateName
698
+ .trim()
699
+ .replace(/\\/g, "/")
700
+ .replace(/^\/+|\/+$/g, "")
701
+ .replace(/\s+/g, "_")
702
+ .replace(/[^A-Za-z0-9/_-]/g, "_");
703
+ }
704
+ function scanTemplateRegistry(templateDir) {
705
+ if (!fs.existsSync(templateDir)) {
706
+ return [];
707
+ }
708
+ const allowedExtensions = new Set([".3mf", ".json", ".config"]);
709
+ const entries = [];
710
+ const stack = [templateDir];
711
+ while (stack.length > 0) {
712
+ const currentDir = stack.pop();
713
+ for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
714
+ const fullPath = path.join(currentDir, entry.name);
715
+ if (entry.isDirectory()) {
716
+ stack.push(fullPath);
717
+ continue;
718
+ }
719
+ const extension = path.extname(entry.name).toLowerCase();
720
+ if (!allowedExtensions.has(extension)) {
721
+ continue;
722
+ }
723
+ const relativePath = path.relative(templateDir, fullPath);
724
+ const templateName = relativePath
725
+ .replace(/\\/g, "/")
726
+ .replace(/(\.gcode)?\.3mf$/i, "")
727
+ .replace(/\.(json|config)$/i, "");
728
+ entries.push({
729
+ name: templateName,
730
+ path: fullPath,
731
+ source_type: extension === ".3mf" ? "3mf" : extension === ".json" ? "json" : "config",
732
+ relative_path: relativePath,
733
+ });
734
+ }
735
+ }
736
+ return entries.sort((a, b) => a.name.localeCompare(b.name));
737
+ }
251
738
  if (!fs.existsSync(TEMP_DIR)) {
252
739
  fs.mkdirSync(TEMP_DIR, { recursive: true });
253
740
  }
@@ -287,7 +774,7 @@ class BambuPrinterMCPServer {
287
774
  if (fromArgs) {
288
775
  return validateBambuModel(fromArgs);
289
776
  }
290
- // No model from args or env - ask the user via elicitation
777
+ // No model from args or env — ask the user via elicitation
291
778
  try {
292
779
  const result = await this.server.elicitInput({
293
780
  mode: "form",
@@ -303,11 +790,14 @@ class BambuPrinterMCPServer {
303
790
  oneOf: [
304
791
  { const: "p1s", title: "P1S" },
305
792
  { const: "p1p", title: "P1P" },
793
+ { const: "p2s", title: "P2S" },
306
794
  { const: "x1c", title: "X1 Carbon" },
307
795
  { const: "x1e", title: "X1E" },
308
796
  { const: "a1", title: "A1" },
309
797
  { const: "a1mini", title: "A1 Mini" },
310
798
  { const: "h2d", title: "H2D" },
799
+ { const: "h2s", title: "H2S" },
800
+ { const: "h2c", title: "H2C" },
311
801
  ],
312
802
  },
313
803
  },
@@ -320,7 +810,7 @@ class BambuPrinterMCPServer {
320
810
  throw new Error("Printer model selection was cancelled. Cannot proceed without knowing the printer model.");
321
811
  }
322
812
  catch (elicitError) {
323
- // Elicitation not supported by this client - fall back to a clear error
813
+ // Elicitation not supported by this client — fall back to a clear error
324
814
  const msg = elicitError?.message || String(elicitError);
325
815
  if (elicitError?.code === -32601 || elicitError?.code === -32600 ||
326
816
  msg.includes("does not support") || msg.includes("elicitation")) {
@@ -340,7 +830,7 @@ class BambuPrinterMCPServer {
340
830
  timeoutMs: args?.timeout_ms !== undefined ? Number(args.timeout_ms) : undefined,
341
831
  };
342
832
  }
343
- async ensurePrintableThreeMFPath(args, printModel, printPreset) {
833
+ async ensurePrintableThreeMFPath(args, printModel, printPreset, bedType) {
344
834
  const { slicerType, slicerPath, slicerProfile } = resolveSlicerConfig(args);
345
835
  let threeMFPath = String(args.three_mf_path);
346
836
  const JSZip = (await import('jszip')).default;
@@ -350,53 +840,75 @@ class BambuPrinterMCPServer {
350
840
  if (hasGcode) {
351
841
  return { threeMFPath, autoSliced: false };
352
842
  }
843
+ if (bedType === "supertack_plate") {
844
+ throw new Error('BambuStudio CLI SuperTack bed type is not verified; use a pre-sliced 3MF for SuperTack or choose textured_plate, cool_plate, engineering_plate, or hot_plate.');
845
+ }
353
846
  console.log(`3MF has no gcode - auto-slicing with ${slicerType} for ${printModel}`);
354
847
  const autoSliceOptions = {
355
848
  uptodate: true,
356
849
  ensureOnBed: true,
357
850
  minSave: true,
358
851
  skipModifiedGcodes: true,
852
+ bedType: bedType ? resolveBambuStudioCliBedType(bedType) : undefined,
359
853
  };
360
854
  threeMFPath = await this.stlManipulator.sliceSTL(threeMFPath, slicerType, slicerPath, slicerProfile || undefined, undefined, printPreset, autoSliceOptions);
361
855
  console.log("Auto-sliced to: " + threeMFPath);
362
856
  return { threeMFPath, autoSliced: true };
363
857
  }
364
- async resolveAmsPrintSettings(threeMFPath, args) {
858
+ async resolveAmsPrintSettings(threeMFPath, args, host, bambuSerial, bambuToken, printModel, printNozzle) {
365
859
  const parsed3MFData = await parse3MF(threeMFPath);
366
860
  let parsedAmsMapping;
367
861
  if (parsed3MFData.slicerConfig?.ams_mapping) {
368
- const slots = Object.values(parsed3MFData.slicerConfig.ams_mapping)
369
- .filter(v => typeof v === 'number');
862
+ const slots = normalizeAmsMappingObject(parsed3MFData.slicerConfig.ams_mapping);
370
863
  if (slots.length > 0) {
371
- parsedAmsMapping = slots.sort((a, b) => a - b);
864
+ parsedAmsMapping = slots;
372
865
  }
373
866
  }
374
867
  let finalAmsMapping = parsedAmsMapping;
375
- const explicitUseAMS = args?.use_ams !== undefined;
376
- let useAMS = explicitUseAMS ? Boolean(args.use_ams) : (!!finalAmsMapping && finalAmsMapping.length > 0);
377
- if (args?.ams_mapping) {
868
+ let finalAmsSlots;
869
+ let useAMS = args?.use_ams !== undefined ? Boolean(args.use_ams) : (!!finalAmsMapping && finalAmsMapping.length > 0);
870
+ const hasUserAmsMapping = hasAmsMappingInput(args?.ams_mapping);
871
+ const hasUserAmsSlots = Array.isArray(args?.ams_slots);
872
+ if (hasUserAmsMapping) {
378
873
  let userMappingOverride;
379
874
  if (Array.isArray(args.ams_mapping)) {
380
- userMappingOverride = args.ams_mapping.filter((v) => typeof v === 'number');
875
+ userMappingOverride = args.ams_mapping.map((v, i) => normalizeBridgeAmsTrayValue(v, `ams_mapping[${i}]`));
381
876
  }
382
- else if (typeof args.ams_mapping === 'object') {
383
- userMappingOverride = Object.values(args.ams_mapping)
384
- .filter((v) => typeof v === 'number')
385
- .sort((a, b) => a - b);
877
+ else if (args.ams_mapping && typeof args.ams_mapping === 'object') {
878
+ userMappingOverride = normalizeAmsMappingObject(args.ams_mapping);
386
879
  }
387
880
  if (userMappingOverride && userMappingOverride.length > 0) {
388
881
  finalAmsMapping = userMappingOverride;
882
+ finalAmsSlots = undefined;
389
883
  useAMS = true;
390
884
  }
391
885
  }
886
+ if (!hasUserAmsMapping && hasUserAmsSlots) {
887
+ const userSlots = args.ams_slots.map((slot, i) => normalizeBridgeAmsTrayValue(slot, `ams_slots[${i}]`));
888
+ finalAmsSlots = userSlots;
889
+ finalAmsMapping = undefined;
890
+ useAMS = userSlots.length > 0;
891
+ }
892
+ if (!hasUserAmsMapping && !hasUserAmsSlots && args?.auto_match_ams) {
893
+ const requirements = await analyze3MFAmsRequirements(threeMFPath, args?.plate_index !== undefined ? Number(args.plate_index) : 0);
894
+ const inventory = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, printModel, printNozzle);
895
+ const resolved = resolveAmsSlotsFromRequirements(requirements, inventory);
896
+ if (resolved.missing.length > 0) {
897
+ throw new Error(`Could not auto-match AMS slots: ${JSON.stringify(resolved.missing)}`);
898
+ }
899
+ finalAmsSlots = resolved.ams_slots;
900
+ finalAmsMapping = undefined;
901
+ useAMS = true;
902
+ }
392
903
  if (args?.use_ams === false) {
393
904
  finalAmsMapping = undefined;
905
+ finalAmsSlots = undefined;
394
906
  useAMS = false;
395
907
  }
396
- if ((!finalAmsMapping || finalAmsMapping.length === 0) && !explicitUseAMS) {
908
+ if ((!finalAmsMapping || finalAmsMapping.length === 0) && (!finalAmsSlots || finalAmsSlots.length === 0)) {
397
909
  useAMS = false;
398
910
  }
399
- return { useAMS, finalAmsMapping };
911
+ return { useAMS, finalAmsMapping, finalAmsSlots };
400
912
  }
401
913
  async print3mfViaBambuNetwork(args, host, bambuSerial, bambuToken) {
402
914
  if (!args?.three_mf_path) {
@@ -430,13 +942,13 @@ class BambuPrinterMCPServer {
430
942
  if (isLocalBridgePrint && !password) {
431
943
  throw new Error("bambu_token/access code is required for FULU BambuNetwork LAN/local print methods.");
432
944
  }
433
- const { threeMFPath, autoSliced } = await this.ensurePrintableThreeMFPath(args, printModel, printPreset);
434
- const { useAMS, finalAmsMapping } = await this.resolveAmsPrintSettings(threeMFPath, args);
945
+ const { threeMFPath, autoSliced } = await this.ensurePrintableThreeMFPath(args, printModel, printPreset, printBedType);
946
+ const { useAMS, finalAmsMapping, finalAmsSlots } = await this.resolveAmsPrintSettings(threeMFPath, args, host, bambuSerial, bambuToken, printModel, printNozzle);
435
947
  const threeMfFilename = path.basename(threeMFPath);
436
948
  const projectName = String(args?.project_name || threeMfFilename.replace(/\.3mf$/i, ''));
437
949
  const presetName = String(args?.preset_name || `${projectName}_plate_${plateIndex + 1}`);
438
950
  const clientJobId = args?.client_job_id !== undefined ? Number(args.client_job_id) : Date.now();
439
- const amsMapping = stringifyBridgeJson(args?.ams_mapping_bridge ?? finalAmsMapping);
951
+ const amsMapping = stringifyBridgeJson(args?.ams_mapping_bridge ?? finalAmsMapping ?? finalAmsSlots);
440
952
  const params = {
441
953
  dev_id: devId,
442
954
  task_name: String(args?.task_name || projectName),
@@ -503,10 +1015,175 @@ class BambuPrinterMCPServer {
503
1015
  plateIndex,
504
1016
  bridgePlateIndex: plateIndex + 1,
505
1017
  useAMS,
506
- amsMapping: finalAmsMapping,
1018
+ amsMapping: finalAmsMapping ?? finalAmsSlots,
507
1019
  params: redactPrintParams(params),
508
1020
  };
509
1021
  }
1022
+ async getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, bambuModel, nozzleDiameter) {
1023
+ const status = await this.bambu.getStatus(host, bambuSerial, bambuToken);
1024
+ let inventory = normalizePrinterFilamentInventory(status, bambuModel, nozzleDiameter);
1025
+ // The first MQTT push from an idle printer is sparse (model/modules
1026
+ // only). AMS data arrives on a second push a short while later. If
1027
+ // we have a live connection but no loaded trays, wait for the follow-
1028
+ // up push and retry.
1029
+ if (inventory.trays.length === 0 && status.connected) {
1030
+ await new Promise((r) => setTimeout(r, 1500));
1031
+ const retryStatus = await this.bambu.getStatus(host, bambuSerial, bambuToken);
1032
+ inventory = normalizePrinterFilamentInventory(retryStatus, bambuModel, nozzleDiameter);
1033
+ }
1034
+ return inventory;
1035
+ }
1036
+ async inspectSliceSettings(sourcePath) {
1037
+ if (!fs.existsSync(sourcePath)) {
1038
+ throw new Error(`Slice settings source not found: ${sourcePath}`);
1039
+ }
1040
+ const extension = path.extname(sourcePath).toLowerCase();
1041
+ const tempDir = path.join(TEMP_DIR, "slice-settings");
1042
+ fs.mkdirSync(tempDir, { recursive: true });
1043
+ if (extension === ".3mf") {
1044
+ const parsed = await parse3MF(sourcePath);
1045
+ const extractedSettingsPath = await extractBambuTemplateSettings(sourcePath, tempDir);
1046
+ const config = (parsed.slicerConfig || {});
1047
+ return {
1048
+ source_path: sourcePath,
1049
+ source_type: "3mf",
1050
+ extracted_settings_path: extractedSettingsPath,
1051
+ object_count: parsed.objects.length,
1052
+ build_item_count: parsed.build.items.length,
1053
+ metadata_keys: Object.keys(parsed.metadata),
1054
+ summary: summarizeSliceSettings(config),
1055
+ raw_key_count: Object.keys(config).length,
1056
+ };
1057
+ }
1058
+ const content = fs.readFileSync(sourcePath, "utf8");
1059
+ const config = parseLooseSlicerConfig(content);
1060
+ return {
1061
+ source_path: sourcePath,
1062
+ source_type: extension === ".json" ? "json" : extension === ".config" ? "config" : "text",
1063
+ extracted_settings_path: sourcePath,
1064
+ summary: summarizeSliceSettings(config),
1065
+ raw_key_count: Object.keys(config).length,
1066
+ };
1067
+ }
1068
+ async resolveCollarCharmPrepared3MF(sourcePath, template3mfPath, slicerType, slicerPath, slicerProfile, printModel, printNozzle, bedType, host, bambuSerial, bambuToken) {
1069
+ if (!sourcePath.toLowerCase().endsWith(".3mf")) {
1070
+ throw new Error("print_collar_charm requires a prepared .3mf project or sliced 3MF.");
1071
+ }
1072
+ try {
1073
+ const JSZip = (await import('jszip')).default;
1074
+ const zipData = fs.readFileSync(sourcePath);
1075
+ const zip = await JSZip.loadAsync(zipData);
1076
+ const hasGcode = Object.keys(zip.files).some((fileName) => fileName.match(/Metadata\/plate_\d+\.gcode/i) || fileName.endsWith('.gcode'));
1077
+ if (hasGcode) {
1078
+ return sourcePath;
1079
+ }
1080
+ }
1081
+ catch (error) {
1082
+ throw new Error(`Failed to inspect collar charm 3MF before slicing: ${error.message}`);
1083
+ }
1084
+ const printPreset = BAMBU_MODEL_PRESETS[printModel]?.(printNozzle);
1085
+ if (bedType === "supertack_plate") {
1086
+ throw new Error('BambuStudio CLI SuperTack bed type is not verified; use a pre-sliced 3MF for SuperTack or choose textured_plate, cool_plate, engineering_plate, or hot_plate.');
1087
+ }
1088
+ const autoSliceOptions = {
1089
+ uptodate: true,
1090
+ ensureOnBed: true,
1091
+ minSave: true,
1092
+ skipModifiedGcodes: true,
1093
+ bedType,
1094
+ };
1095
+ try {
1096
+ const liveFilaments = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, printModel, printNozzle);
1097
+ if (liveFilaments.recommended?.load_filaments) {
1098
+ autoSliceOptions.loadFilaments = liveFilaments.recommended.load_filaments;
1099
+ }
1100
+ }
1101
+ catch (filamentError) {
1102
+ console.warn("Could not resolve live printer filaments for collar charm auto-slicing:", filamentError);
1103
+ }
1104
+ return this.stlManipulator.sliceSTL(sourcePath, slicerType, slicerPath, slicerProfile || template3mfPath || undefined, undefined, printPreset, autoSliceOptions);
1105
+ }
1106
+ async preflightCollarCharmPolicy(host, bambuSerial, bambuToken, bambuModel, nozzleDiameter) {
1107
+ const inventory = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, bambuModel, nozzleDiameter);
1108
+ const requiredSlots = [COLLAR_CHARM_POLICY.amsSlots.inner, COLLAR_CHARM_POLICY.amsSlots.outer];
1109
+ for (const slot of requiredSlots) {
1110
+ const tray = inventory.trays.find((candidate) => candidate.slot === slot);
1111
+ if (!tray) {
1112
+ throw new Error(`Collar charm wrapper requires AMS tray ${slot}, but that tray is not reported by the printer.`);
1113
+ }
1114
+ if (!tray.loaded) {
1115
+ throw new Error(`Collar charm wrapper requires AMS tray ${slot} to be loaded, but it is currently empty or unavailable.`);
1116
+ }
1117
+ }
1118
+ return inventory;
1119
+ }
1120
+ listTemplateRegistry(templateDir) {
1121
+ const resolvedTemplateDir = templateDir && templateDir.trim().length > 0
1122
+ ? templateDir
1123
+ : DEFAULT_TEMPLATE_DIR;
1124
+ return {
1125
+ template_dir: resolvedTemplateDir,
1126
+ templates: scanTemplateRegistry(resolvedTemplateDir),
1127
+ };
1128
+ }
1129
+ resolveTemplatePath(templateName, templateDir, sourceTypes) {
1130
+ if (!templateName || templateName.trim().length === 0) {
1131
+ return undefined;
1132
+ }
1133
+ const registry = this.listTemplateRegistry(templateDir);
1134
+ const normalizedName = sanitizeTemplateName(templateName).toLowerCase();
1135
+ const requestedName = templateName.trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "").toLowerCase();
1136
+ const nameMatches = registry.templates.filter((entry) => entry.name.toLowerCase() === requestedName ||
1137
+ sanitizeTemplateName(entry.name).toLowerCase() === normalizedName);
1138
+ const searchTypes = sourceTypes && sourceTypes.length > 0
1139
+ ? sourceTypes
1140
+ : ["3mf", "json", "config"];
1141
+ const match = searchTypes
1142
+ .map((sourceType) => nameMatches.find((entry) => entry.source_type === sourceType))
1143
+ .find((entry) => Boolean(entry));
1144
+ if (!match) {
1145
+ const typeHint = sourceTypes && sourceTypes.length > 0
1146
+ ? ` with source type ${sourceTypes.join("/")}`
1147
+ : "";
1148
+ const availableTypes = nameMatches.length > 0
1149
+ ? ` Available source types: ${Array.from(new Set(nameMatches.map((entry) => entry.source_type))).join(", ")}.`
1150
+ : "";
1151
+ throw new Error(`Template "${templateName}"${typeHint} not found in ${registry.template_dir}.${availableTypes}`);
1152
+ }
1153
+ return match.path;
1154
+ }
1155
+ saveTemplate(sourcePath, templateName, templateDir) {
1156
+ if (!fs.existsSync(sourcePath)) {
1157
+ throw new Error(`Template source not found: ${sourcePath}`);
1158
+ }
1159
+ const resolvedTemplateDir = templateDir && templateDir.trim().length > 0
1160
+ ? templateDir
1161
+ : DEFAULT_TEMPLATE_DIR;
1162
+ fs.mkdirSync(resolvedTemplateDir, { recursive: true });
1163
+ const sourceBaseName = path.basename(sourcePath);
1164
+ const extension = path.extname(sourceBaseName).toLowerCase();
1165
+ if (![".3mf", ".json", ".config"].includes(extension)) {
1166
+ throw new Error("Templates must be .3mf, .json, or .config files.");
1167
+ }
1168
+ const baseName = templateName && templateName.trim().length > 0
1169
+ ? sanitizeTemplateName(templateName)
1170
+ : sanitizeTemplateName(sourceBaseName
1171
+ .replace(/(\.gcode)?\.3mf$/i, "")
1172
+ .replace(/\.(json|config)$/i, ""));
1173
+ const destinationPath = path.join(resolvedTemplateDir, `${baseName}${extension}`);
1174
+ fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
1175
+ fs.copyFileSync(sourcePath, destinationPath);
1176
+ const sourceType = extension === ".3mf" ? "3mf" : extension === ".json" ? "json" : "config";
1177
+ const registryEntry = this.resolveTemplatePath(baseName, resolvedTemplateDir, [sourceType]);
1178
+ return {
1179
+ saved: true,
1180
+ template_name: baseName,
1181
+ source_path: sourcePath,
1182
+ destination_path: destinationPath,
1183
+ template_dir: resolvedTemplateDir,
1184
+ resolved_path: registryEntry,
1185
+ };
1186
+ }
510
1187
  setupResourceHandlers() {
511
1188
  this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
512
1189
  return {
@@ -522,6 +1199,12 @@ class BambuPrinterMCPServer {
522
1199
  name: "Bambu Printer Files",
523
1200
  mimeType: "application/json",
524
1201
  description: "List of files on the Bambu Lab printer"
1202
+ },
1203
+ {
1204
+ uri: `printer://${DEFAULT_HOST}/hms`,
1205
+ name: "Bambu Printer HMS Diagnostics",
1206
+ mimeType: "application/json",
1207
+ description: "HMS and error-related fields from the latest printer status"
525
1208
  }
526
1209
  ],
527
1210
  templates: [
@@ -534,6 +1217,11 @@ class BambuPrinterMCPServer {
534
1217
  uriTemplate: "printer://{host}/files",
535
1218
  name: "Bambu Printer Files",
536
1219
  mimeType: "application/json"
1220
+ },
1221
+ {
1222
+ uriTemplate: "printer://{host}/hms",
1223
+ name: "Bambu Printer HMS Diagnostics",
1224
+ mimeType: "application/json"
537
1225
  }
538
1226
  ]
539
1227
  };
@@ -554,6 +1242,20 @@ class BambuPrinterMCPServer {
554
1242
  else if (resource === "files") {
555
1243
  content = await this.bambu.getFiles(host || DEFAULT_HOST, bambuSerial, bambuToken);
556
1244
  }
1245
+ else if (resource === "hms") {
1246
+ const status = await this.bambu.getStatus(host || DEFAULT_HOST, bambuSerial, bambuToken);
1247
+ let diagnostics = extractPrinterDiagnostics(status);
1248
+ // The first MQTT status push may not include HMS data — the printer
1249
+ // sends basic state first, then pushes HMS/error fields on a subsequent
1250
+ // report. If we got a connection but no HMS data, wait briefly and
1251
+ // retry so the incremental merge has time to arrive.
1252
+ if (!diagnostics.hms && status.connected) {
1253
+ await new Promise((r) => setTimeout(r, 1500));
1254
+ const retryStatus = await this.bambu.getStatus(host || DEFAULT_HOST, bambuSerial, bambuToken);
1255
+ diagnostics = extractPrinterDiagnostics(retryStatus);
1256
+ }
1257
+ content = diagnostics;
1258
+ }
557
1259
  else {
558
1260
  throw new McpError(ErrorCode.InvalidRequest, `Unknown resource: ${resource}`);
559
1261
  }
@@ -593,6 +1295,69 @@ class BambuPrinterMCPServer {
593
1295
  }
594
1296
  }
595
1297
  },
1298
+ {
1299
+ name: "get_printer_filaments",
1300
+ description: "Get the live AMS/external filament inventory from the printer over MQTT, including loaded/empty slot summary, resolved slicer profile paths, match confidence, and recommended load_filaments when the printer model is known.",
1301
+ inputSchema: {
1302
+ type: "object",
1303
+ properties: {
1304
+ host: {
1305
+ type: "string",
1306
+ description: "Hostname or IP address of the printer (default: value from env)"
1307
+ },
1308
+ bambu_serial: {
1309
+ type: "string",
1310
+ description: "Serial number for the Bambu Lab printer (default: value from env)"
1311
+ },
1312
+ bambu_token: {
1313
+ type: "string",
1314
+ description: "Access token for the Bambu Lab printer (default: value from env)"
1315
+ },
1316
+ bambu_model: {
1317
+ type: "string",
1318
+ enum: [...VALID_BAMBU_MODELS],
1319
+ description: "Optional model hint used to resolve Bambu/Orca filament profile JSONs for each tray."
1320
+ },
1321
+ nozzle_diameter: {
1322
+ type: "string",
1323
+ description: "Optional nozzle diameter used when resolving model-specific filament profile JSONs (default: 0.4)."
1324
+ }
1325
+ }
1326
+ }
1327
+ },
1328
+ {
1329
+ name: "resolve_3mf_ams_slots",
1330
+ description: "Inspect a sliced 3MF and match its tray_info_idx filament requirements against the live AMS inventory. Does not upload or start a print.",
1331
+ inputSchema: {
1332
+ type: "object",
1333
+ properties: {
1334
+ three_mf_path: { type: "string", description: "Path to a sliced 3MF/.gcode.3mf file" },
1335
+ plate_index: { type: "number", description: "0-based plate index to inspect (default: 0)" },
1336
+ bambu_model: {
1337
+ type: "string",
1338
+ enum: [...VALID_BAMBU_MODELS],
1339
+ description: "Optional model hint used to resolve Bambu/Orca filament profile JSONs for each tray."
1340
+ },
1341
+ nozzle_diameter: { type: "string", description: "Nozzle diameter in mm (default: 0.4)" },
1342
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1343
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1344
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1345
+ },
1346
+ required: ["three_mf_path"]
1347
+ }
1348
+ },
1349
+ {
1350
+ name: "list_3mf_plate_objects",
1351
+ description: "List object IDs from a sliced 3MF plate. Use these IDs with skip_objects during a running print.",
1352
+ inputSchema: {
1353
+ type: "object",
1354
+ properties: {
1355
+ three_mf_path: { type: "string", description: "Path to a sliced 3MF/.gcode.3mf file" },
1356
+ plate_index: { type: "number", description: "0-based plate index to inspect (default: 0)" }
1357
+ },
1358
+ required: ["three_mf_path"]
1359
+ }
1360
+ },
596
1361
  {
597
1362
  name: "extend_stl_base",
598
1363
  description: "Extend the base of an STL file by a specified amount",
@@ -644,6 +1409,110 @@ class BambuPrinterMCPServer {
644
1409
  required: ["stl_path"]
645
1410
  }
646
1411
  },
1412
+ {
1413
+ name: "list_templates",
1414
+ description: "List saved slicing templates from the local template registry directory.",
1415
+ inputSchema: {
1416
+ type: "object",
1417
+ properties: {
1418
+ template_dir: {
1419
+ type: "string",
1420
+ description: "Optional template directory override. Defaults to BAMBU_TEMPLATE_DIR or the server's configured local template registry."
1421
+ }
1422
+ }
1423
+ }
1424
+ },
1425
+ {
1426
+ name: "save_template",
1427
+ description: "Copy a 3MF, JSON, or config file into the local template registry and register it under a template name.",
1428
+ inputSchema: {
1429
+ type: "object",
1430
+ properties: {
1431
+ source_path: {
1432
+ type: "string",
1433
+ description: "Path to a local .3mf, .json, or .config file to save into the template registry."
1434
+ },
1435
+ template_name: {
1436
+ type: "string",
1437
+ description: "Optional template name. Defaults to the source filename without extension."
1438
+ },
1439
+ template_dir: {
1440
+ type: "string",
1441
+ description: "Optional template directory override. Defaults to BAMBU_TEMPLATE_DIR or the server's configured local template registry."
1442
+ }
1443
+ },
1444
+ required: ["source_path"]
1445
+ }
1446
+ },
1447
+ {
1448
+ name: "get_slice_settings",
1449
+ description: "Inspect slicer settings from a saved 3MF template or a JSON/config slicer profile without slicing anything.",
1450
+ inputSchema: {
1451
+ type: "object",
1452
+ properties: {
1453
+ source_path: {
1454
+ type: "string",
1455
+ description: "Path to a 3MF template, extracted project_settings.config, or slicer profile JSON."
1456
+ },
1457
+ template_name: {
1458
+ type: "string",
1459
+ description: "Optional named template from the local registry. If provided, resolves source_path automatically."
1460
+ },
1461
+ template_dir: {
1462
+ type: "string",
1463
+ description: "Optional template directory override when resolving template_name."
1464
+ }
1465
+ }
1466
+ }
1467
+ },
1468
+ {
1469
+ name: "slice_with_template",
1470
+ description: "Slice an STL or 3MF using a named template from the local registry. This is a higher-level wrapper around slice_stl for template-based workflows.",
1471
+ inputSchema: {
1472
+ type: "object",
1473
+ properties: {
1474
+ stl_path: { type: "string", description: "Path to the STL or 3MF file to slice" },
1475
+ template_name: { type: "string", description: "Named template from the local registry." },
1476
+ template_dir: { type: "string", description: "Optional template directory override when resolving template_name." },
1477
+ bambu_model: {
1478
+ type: "string",
1479
+ enum: [...VALID_BAMBU_MODELS],
1480
+ description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
1481
+ },
1482
+ slicer_type: {
1483
+ type: "string",
1484
+ enum: SLICER_SCHEMA_VALUES,
1485
+ description: "Type of slicer to use. Bambu-compatible choices (bambustudio, orcaslicer, orcaslicer-bambulab) export sliced 3MF; aliases such as fulu-orca and orca-studio are accepted."
1486
+ },
1487
+ slicer_path: { type: "string", description: "Path to the slicer executable (default: value from env)" },
1488
+ slicer_profile: { type: "string", description: "Explicit slicer profile/config file. Overrides the named template only when provided in the tool call." },
1489
+ nozzle_diameter: { type: "string", description: "Nozzle diameter in mm (default: 0.4)" },
1490
+ bed_type: {
1491
+ type: "string",
1492
+ enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
1493
+ description: "Bed plate type for slicing (default: textured_plate). SuperTack is accepted only for pre-sliced print jobs until the BambuStudio CLI identifier is verified."
1494
+ },
1495
+ use_printer_filaments: { type: "boolean", description: "When true, and no explicit slicer profile or load_filaments override is provided, use the printer's current or first loaded AMS filament as the slicer filament profile." },
1496
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1497
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1498
+ bambu_token: { type: "string", description: "Access token (default: value from env)" },
1499
+ load_filaments: { type: "string", description: "Override filament profiles. Semicolon-separated paths to filament JSON configs." },
1500
+ load_filament_ids: { type: "string", description: "Optional filament-to-object mapping string." },
1501
+ ensure_on_bed: { type: "boolean", description: "Lift floating models onto the bed." },
1502
+ arrange: { type: "boolean", description: "Auto-arrange objects on the build plate." },
1503
+ orient: { type: "boolean", description: "Auto-orient model for optimal printability." },
1504
+ repetitions: { type: "number", description: "Number of copies to print." },
1505
+ scale: { type: "number", description: "Uniform scale factor." },
1506
+ rotate: { type: "number", description: "Z-axis rotation in degrees." },
1507
+ rotate_x: { type: "number", description: "X-axis rotation in degrees." },
1508
+ rotate_y: { type: "number", description: "Y-axis rotation in degrees." },
1509
+ min_save: { type: "boolean", description: "Produce smaller output 3MF." },
1510
+ skip_modified_gcodes: { type: "boolean", description: "Ignore stale custom gcodes in the 3MF." },
1511
+ slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates." }
1512
+ },
1513
+ required: ["stl_path", "template_name", "bambu_model"]
1514
+ }
1515
+ },
647
1516
  {
648
1517
  name: "slice_stl",
649
1518
  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.",
@@ -653,7 +1522,7 @@ class BambuPrinterMCPServer {
653
1522
  stl_path: { type: "string", description: "Path to the STL or 3MF file to slice" },
654
1523
  bambu_model: {
655
1524
  type: "string",
656
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
1525
+ enum: [...VALID_BAMBU_MODELS],
657
1526
  description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
658
1527
  },
659
1528
  slicer_type: {
@@ -661,10 +1530,19 @@ class BambuPrinterMCPServer {
661
1530
  enum: SLICER_SCHEMA_VALUES,
662
1531
  description: "Type of slicer to use. Bambu-compatible choices (bambustudio, orcaslicer, orcaslicer-bambulab) export sliced 3MF; aliases such as fulu-orca and orca-studio are accepted."
663
1532
  },
664
- slicer_path: { type: "string", description: "Path to the slicer executable (default: value from env or a platform default)" },
1533
+ slicer_path: { type: "string", description: "Path to the slicer executable (default: value from env)" },
665
1534
  slicer_profile: { type: "string", description: "Path to the slicer profile/config file (optional, overrides bambu_model preset)" },
1535
+ template_3mf_path: { type: "string", description: "Optional template 3MF whose embedded Bambu slicer settings should be reused when slicing a new STL or 3MF." },
1536
+ template_name: { type: "string", description: "Optional named template from the local registry. Resolves to template_3mf_path automatically." },
1537
+ template_dir: { type: "string", description: "Optional template directory override when resolving template_name." },
666
1538
  nozzle_diameter: { type: "string", description: "Nozzle diameter in mm (default: 0.4)" },
667
- uptodate: { type: "boolean", description: "Refresh 3MF preset configs to match the latest Bambu-compatible slicer presets. Use when slicing downloaded or older 3MF files to prevent stale-config failures." },
1539
+ bed_type: {
1540
+ type: "string",
1541
+ enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
1542
+ description: "Bed plate type for slicing (default: textured_plate). SuperTack is accepted only for pre-sliced print jobs until the BambuStudio CLI identifier is verified."
1543
+ },
1544
+ use_printer_filaments: { type: "boolean", description: "When true, and no explicit slicer profile or load_filaments override is provided, use the printer's current or first loaded AMS filament as the slicer filament profile. Template 3MF process settings can still be used at the same time." },
1545
+ uptodate: { type: "boolean", description: "Refresh 3MF preset configs to match the latest BambuStudio version. Use when slicing downloaded or older 3MF files to prevent stale-config failures." },
668
1546
  repetitions: { type: "number", description: "Print N identical copies of the model. Each copy gets its own plate placement. Example: 3 prints three copies." },
669
1547
  orient: { type: "boolean", description: "Auto-orient the model for optimal printability (minimize supports, maximize bed adhesion). Recommended for raw STL imports that lack a pre-set orientation." },
670
1548
  arrange: { type: "boolean", description: "Auto-arrange all objects on the build plate with optimal spacing. Recommended when importing STLs or adding multiple objects. Set false to preserve existing plate layout." },
@@ -672,7 +1550,7 @@ class BambuPrinterMCPServer {
672
1550
  clone_objects: { type: "string", description: "Duplicate specific objects on the plate. Comma-separated clone counts per object index, e.g. '1,3,1,10' clones object 0 once, object 1 three times, etc." },
673
1551
  skip_objects: { type: "string", description: "Skip specific objects during slicing by index. Comma-separated, e.g. '3,5,10'. Useful for multi-object 3MFs where you only want to print some parts." },
674
1552
  load_filaments: { type: "string", description: "Override filament profiles. Semicolon-separated paths to filament JSON configs, e.g. 'pla_basic.json;petg_cf.json'." },
675
- filament_profile: { type: "string", description: "Compatibility alias for load_filaments. Semicolon-separated Orca/Bambu filament profile JSON paths; flat self-contained profiles are safest because Orca does not resolve every inherited system filament setting from arbitrary file paths." },
1553
+ filament_profile: { type: "string", description: "Compatibility alias for load_filaments. Semicolon-separated Orca/Bambu filament profile JSON paths." },
676
1554
  load_filament_ids: { type: "string", description: "Map filaments to objects/parts. Comma-separated IDs matching load_filaments order, e.g. '1,2,3,1' assigns filament 1 to objects 0 and 3." },
677
1555
  enable_timelapse: { type: "boolean", description: "Insert timelapse parking moves into gcode. The toolhead parks at a fixed position each layer for camera capture. Adds ~10% print time." },
678
1556
  allow_mix_temp: { type: "boolean", description: "Allow filaments with different temperature requirements on the same plate. Required for multi-material prints mixing e.g. PLA and PETG." },
@@ -741,7 +1619,7 @@ class BambuPrinterMCPServer {
741
1619
  three_mf_path: { type: "string", description: "Path to the 3MF file to print; unsliced 3MFs are auto-sliced before sending." },
742
1620
  bambu_model: {
743
1621
  type: "string",
744
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
1622
+ enum: [...VALID_BAMBU_MODELS],
745
1623
  description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
746
1624
  },
747
1625
  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." },
@@ -753,7 +1631,7 @@ class BambuPrinterMCPServer {
753
1631
  bambu_token: { type: "string", description: "Printer access code/password for LAN/local bridge methods." },
754
1632
  username: { type: "string", description: "Printer username for LAN/local bridge methods; defaults to bblp." },
755
1633
  password: { type: "string", description: "Printer password/access code override for LAN/local bridge methods." },
756
- bed_type: { type: "string", enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate"], description: "Bed plate type currently installed (default: textured_plate)." },
1634
+ bed_type: { type: "string", enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"], description: "Bed plate type currently installed (default: textured_plate)." },
757
1635
  plate_index: { type: "number", description: "Zero-based plate index to print from the sliced 3MF; converted to FULU's one-based PrintParams plate_index." },
758
1636
  project_name: { type: "string", description: "Optional project name sent in FULU PrintParams; defaults to the 3MF filename without extension." },
759
1637
  preset_name: { type: "string", description: "Optional preset name sent in FULU PrintParams; defaults to project plus one-based plate index." },
@@ -770,6 +1648,7 @@ class BambuPrinterMCPServer {
770
1648
  nozzle_diameter: { type: "string", description: "Nozzle diameter in mm for auto-slicing (default: 0.4)." },
771
1649
  use_ams: { type: "boolean", description: "Whether to use the AMS; defaults to auto-detect from the 3MF mapping." },
772
1650
  ams_mapping: { type: "array", description: "AMS slot mapping array used by both local MCP printing and FULU PrintParams.", items: { type: "number" } },
1651
+ ams_slots: { type: "array", description: "Per-used-filament AMS slot list, matching the local LAN print path.", items: { type: "number" } },
773
1652
  ams_mapping_bridge: { type: "string", description: "Raw JSON string override for FULU PrintParams ams_mapping when the automatic array is not enough." },
774
1653
  ams_mapping2: { type: "string", description: "Raw JSON string for FULU PrintParams ams_mapping2, matching OrcaSlicer-bambulab's v1 AMS mapping field." },
775
1654
  ams_mapping_info: { type: "string", description: "Raw JSON string for FULU PrintParams ams_mapping_info, matching OrcaSlicer-bambulab's detailed AMS mapping field." },
@@ -791,38 +1670,72 @@ class BambuPrinterMCPServer {
791
1670
  }
792
1671
  },
793
1672
  {
794
- name: "upload_gcode",
795
- description: "Upload a G-code file to the Bambu Lab printer",
1673
+ name: "camera_snapshot",
1674
+ description: "Capture a single JPEG frame from the printer's chamber camera. A1/P1 use TCP-on-6000; X1/P2S/H2 use RTSP via ffmpeg. Returns JPEG as base64; pass save_path to also write the bytes to disk.",
796
1675
  inputSchema: {
797
1676
  type: "object",
798
1677
  properties: {
799
- filename: { type: "string", description: "Name for the file on the printer" },
800
- gcode: { type: "string", description: "G-code content to upload, or a readable local .gcode path. For large files, prefer gcode_path." },
801
- gcode_path: { type: "string", description: "Local path to a .gcode file to upload. This avoids sending large G-code bodies through the MCP request." },
1678
+ save_path: { type: "string", description: "Optional absolute path to write the JPEG to disk. If omitted, only the base64 payload is returned." },
1679
+ timeout_ms: { type: "number", description: "Max ms to wait for a full frame (default 8000). Camera may take a few seconds on cold start." },
1680
+ bambu_model: { type: "string", description: "Printer model. Used to route to the correct protocol or fail fast on unsupported models. Defaults to BAMBU_MODEL." },
1681
+ experimental: { type: "boolean", description: "Deprecated and ignored. Earlier this flag let callers probe H2 series via the A1/P1 TCP-on-6000 path; live testing on an H2S confirmed H2 uses RTSP instead, so the flag has no effect now." },
1682
+ ffmpeg_path: { type: "string", description: "Override path to the ffmpeg binary used by the RTSP path. Defaults to ffmpeg via $PATH. Required only for the RTSP transport (X1, P2S, H2 series)." },
802
1683
  host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
803
1684
  bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
804
1685
  bambu_token: { type: "string", description: "Access token (default: value from env)" }
805
- },
806
- required: ["filename"],
807
- anyOf: [
808
- { required: ["gcode"] },
809
- { required: ["gcode_path"] }
810
- ]
1686
+ }
811
1687
  }
812
1688
  },
813
1689
  {
814
- name: "upload_file",
815
- description: "Upload a local file to the Bambu Lab printer",
1690
+ name: "delete_printer_file",
1691
+ description: "Delete a file from the Bambu Lab printer's SD card via FTPS. Destructive: requires confirm:true. Restricted to cache/, timelapse/, and logs/ directories. Path traversal segments (..) are rejected.",
816
1692
  inputSchema: {
817
1693
  type: "object",
818
1694
  properties: {
819
- file_path: { type: "string", description: "Local path to the file to upload" },
820
- filename: { type: "string", description: "Name for the file on the printer" },
821
- print: { type: "boolean", description: "Start printing after upload (default: false)" },
822
- bambu_model: {
1695
+ filename: {
823
1696
  type: "string",
824
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
825
- description: "Required when print is true. Bambu Lab printer model used as a safety confirmation before starting the uploaded file."
1697
+ description: "File to delete. Bare names default to cache/<name>; pass a relative path like timelapse/foo.mp4 to target other allowed directories."
1698
+ },
1699
+ confirm: {
1700
+ type: "boolean",
1701
+ description: "Must be true to actually delete. When false or omitted the call returns without sending an FTP request."
1702
+ },
1703
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1704
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1705
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1706
+ },
1707
+ required: ["filename"]
1708
+ }
1709
+ },
1710
+ {
1711
+ name: "upload_gcode",
1712
+ description: "Upload a G-code file to the Bambu Lab printer",
1713
+ inputSchema: {
1714
+ type: "object",
1715
+ properties: {
1716
+ filename: { type: "string", description: "Name for the file on the printer" },
1717
+ gcode: { type: "string", description: "G-code content to upload, or a readable local .gcode path. Required unless gcode_path is provided. For large files, prefer gcode_path." },
1718
+ gcode_path: { type: "string", description: "Local path to a .gcode file to upload. Required unless gcode is provided. This avoids sending large G-code bodies through the MCP request." },
1719
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1720
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1721
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1722
+ },
1723
+ required: ["filename"]
1724
+ }
1725
+ },
1726
+ {
1727
+ name: "upload_file",
1728
+ description: "Upload a local file to the Bambu Lab printer",
1729
+ inputSchema: {
1730
+ type: "object",
1731
+ properties: {
1732
+ file_path: { type: "string", description: "Local path to the file to upload" },
1733
+ filename: { type: "string", description: "Name for the file on the printer" },
1734
+ print: { type: "boolean", description: "Start printing after upload (default: false)" },
1735
+ bambu_model: {
1736
+ type: "string",
1737
+ enum: [...VALID_BAMBU_MODELS],
1738
+ description: "Required when print is true. Bambu Lab printer model used as a safety confirmation before starting the uploaded file."
826
1739
  },
827
1740
  host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
828
1741
  bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
@@ -840,7 +1753,7 @@ class BambuPrinterMCPServer {
840
1753
  filename: { type: "string", description: "Name of the file to print" },
841
1754
  bambu_model: {
842
1755
  type: "string",
843
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
1756
+ enum: [...VALID_BAMBU_MODELS],
844
1757
  description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Starting G-code for the wrong model can damage the printer."
845
1758
  },
846
1759
  host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
@@ -859,7 +1772,7 @@ class BambuPrinterMCPServer {
859
1772
  filename: { type: "string", description: "Name of the file to print" },
860
1773
  bambu_model: {
861
1774
  type: "string",
862
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
1775
+ enum: [...VALID_BAMBU_MODELS],
863
1776
  description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Starting G-code for the wrong model can damage the printer."
864
1777
  },
865
1778
  host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
@@ -881,6 +1794,93 @@ class BambuPrinterMCPServer {
881
1794
  }
882
1795
  }
883
1796
  },
1797
+ {
1798
+ name: "pause_print",
1799
+ description: "Pause the current print job on the Bambu Lab printer (resumable via resume_print)",
1800
+ inputSchema: {
1801
+ type: "object",
1802
+ properties: {
1803
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1804
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1805
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1806
+ }
1807
+ }
1808
+ },
1809
+ {
1810
+ name: "resume_print",
1811
+ description: "Resume a paused print job on the Bambu Lab printer",
1812
+ inputSchema: {
1813
+ type: "object",
1814
+ properties: {
1815
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1816
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1817
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1818
+ }
1819
+ }
1820
+ },
1821
+ {
1822
+ name: "clear_hms_errors",
1823
+ description: "Clear HMS or print error state on the Bambu Lab printer using the clean_print_error MQTT command.",
1824
+ inputSchema: {
1825
+ type: "object",
1826
+ properties: {
1827
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1828
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1829
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1830
+ }
1831
+ }
1832
+ },
1833
+ {
1834
+ name: "set_print_speed",
1835
+ description: "Set the active print speed mode: silent, standard, sport, or ludicrous.",
1836
+ inputSchema: {
1837
+ type: "object",
1838
+ properties: {
1839
+ mode: {
1840
+ type: "string",
1841
+ enum: ["silent", "standard", "sport", "ludicrous", "1", "2", "3", "4"],
1842
+ description: "Speed mode to apply: silent/1, standard/2, sport/3, or ludicrous/4"
1843
+ },
1844
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1845
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1846
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1847
+ },
1848
+ required: ["mode"]
1849
+ }
1850
+ },
1851
+ {
1852
+ name: "set_airduct_mode",
1853
+ description: "Set H2/P2 airduct mode to cooling or heating.",
1854
+ inputSchema: {
1855
+ type: "object",
1856
+ properties: {
1857
+ mode: {
1858
+ type: "string",
1859
+ enum: ["cooling", "heating"],
1860
+ description: "Airduct mode to apply"
1861
+ },
1862
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1863
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1864
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1865
+ },
1866
+ required: ["mode"]
1867
+ }
1868
+ },
1869
+ {
1870
+ name: "reread_ams_rfid",
1871
+ description: "Trigger a Bambu AMS RFID re-read for one AMS slot. This can move AMS filament; use only when the printer is idle and unloaded.",
1872
+ inputSchema: {
1873
+ type: "object",
1874
+ properties: {
1875
+ ams_id: { type: "number", description: "AMS unit index from 0 to 3" },
1876
+ slot_id: { type: "number", description: "Slot index within that AMS, from 0 to 3" },
1877
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1878
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1879
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1880
+ },
1881
+ required: ["ams_id", "slot_id"]
1882
+ }
1883
+ },
884
1884
  {
885
1885
  name: "set_temperature",
886
1886
  description: "Set the temperature of a printer component (bed, nozzle)",
@@ -896,6 +1896,86 @@ class BambuPrinterMCPServer {
896
1896
  required: ["component", "temperature"]
897
1897
  }
898
1898
  },
1899
+ {
1900
+ name: "set_fan_speed",
1901
+ description: "Set a Bambu printer fan speed percentage using the printer's MQTT fan command",
1902
+ inputSchema: {
1903
+ type: "object",
1904
+ properties: {
1905
+ fan: {
1906
+ type: "string",
1907
+ description: "Fan to control: part, auxiliary, chamber, 1, 2, or 3"
1908
+ },
1909
+ speed: { type: "number", description: "Fan speed percentage from 0 to 100" },
1910
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1911
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1912
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1913
+ },
1914
+ required: ["fan", "speed"]
1915
+ }
1916
+ },
1917
+ {
1918
+ name: "set_light",
1919
+ description: "Set a Bambu printer light node mode using the printer's MQTT LED command",
1920
+ inputSchema: {
1921
+ type: "object",
1922
+ properties: {
1923
+ light: {
1924
+ type: "string",
1925
+ description: "Light node to control, for example chamber_light"
1926
+ },
1927
+ mode: {
1928
+ type: "string",
1929
+ enum: ["on", "off", "flashing"],
1930
+ description: "Light mode to apply"
1931
+ },
1932
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1933
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1934
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1935
+ },
1936
+ required: ["light", "mode"]
1937
+ }
1938
+ },
1939
+ {
1940
+ name: "skip_objects",
1941
+ description: "Skip specific object IDs during a running multi-object print using the printer's MQTT skip_objects command",
1942
+ inputSchema: {
1943
+ type: "object",
1944
+ properties: {
1945
+ object_ids: {
1946
+ type: "array",
1947
+ description: "Object IDs to skip. Use list_3mf_plate_objects on the sliced 3MF to find IDs.",
1948
+ items: { type: "number" }
1949
+ },
1950
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1951
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1952
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1953
+ },
1954
+ required: ["object_ids"]
1955
+ }
1956
+ },
1957
+ {
1958
+ name: "set_ams_drying",
1959
+ description: "Start or stop the AMS filament drying cycle. Available on AMS units with heating capability (AMS Pro / AMS-HT). Sends an ams_control MQTT command to the printer.",
1960
+ inputSchema: {
1961
+ type: "object",
1962
+ properties: {
1963
+ action: {
1964
+ type: "string",
1965
+ enum: ["start", "stop"],
1966
+ description: "Whether to start or stop the drying cycle"
1967
+ },
1968
+ ams_id: {
1969
+ type: "number",
1970
+ description: "AMS unit index from 0 to 3"
1971
+ },
1972
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
1973
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
1974
+ bambu_token: { type: "string", description: "Access token (default: value from env)" }
1975
+ },
1976
+ required: ["action", "ams_id"]
1977
+ }
1978
+ },
899
1979
  {
900
1980
  name: "print_3mf",
901
1981
  description: "Print a 3MF file on a Bambu Lab printer. Auto-slices if the 3MF has no gcode. IMPORTANT: bambu_model must be specified to ensure safe printer operation.",
@@ -905,13 +1985,13 @@ class BambuPrinterMCPServer {
905
1985
  three_mf_path: { type: "string", description: "Path to the 3MF file to print" },
906
1986
  bambu_model: {
907
1987
  type: "string",
908
- enum: ["p1s", "p1p", "x1c", "x1e", "a1", "a1mini", "h2d"],
1988
+ enum: [...VALID_BAMBU_MODELS],
909
1989
  description: "REQUIRED: Bambu Lab printer model. Ask the user if not known. Using the wrong model can damage the printer."
910
1990
  },
911
1991
  connection_mode: {
912
1992
  type: "string",
913
1993
  enum: ["lan_mqtt_ftps", "bambu_network"],
914
- description: "Print path to use: lan_mqtt_ftps uses this MCP's direct local MQTT/FTPS path; bambu_network uses FULU OrcaSlicer-bambulab's restored BambuNetwork bridge."
1994
+ description: "Print path to use: lan_mqtt_ftps uses this MCP's direct local MQTT/FTPS path; bambu_network uses the restored FULU BambuNetwork bridge."
915
1995
  },
916
1996
  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." },
917
1997
  bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to start_print for cloud and start_local_print for lan." },
@@ -923,36 +2003,79 @@ class BambuPrinterMCPServer {
923
2003
  user_info: { type: "string", description: "Optional BambuNetwork user_info JSON string passed to net.change_user for the FULU bridge." },
924
2004
  bed_type: {
925
2005
  type: "string",
926
- enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate"],
2006
+ enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
927
2007
  description: "Bed plate type currently installed (default: textured_plate)"
928
2008
  },
929
- plate_index: { type: "number", description: "Zero-based plate index to print from the sliced 3MF (default: 0)" },
930
2009
  host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
931
2010
  bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
932
2011
  bambu_token: { type: "string", description: "Access token (default: value from env)" },
2012
+ plate_index: { type: "number", description: "Zero-based plate index to print from the sliced 3MF (default: 0)" },
933
2013
  slicer_type: {
934
2014
  type: "string",
935
2015
  enum: SLICER_SCHEMA_VALUES,
936
- description: "Slicer to use only if auto-slicing an unsliced 3MF. Use orcaslicer-bambulab for FULU's OrcaSlicer-bambulab fork; aliases such as fulu-orca and orca-studio are accepted."
2016
+ description: "Slicer to use only if auto-slicing an unsliced 3MF. Bambu-compatible slicer aliases such as fulu-orca and orca-studio are accepted."
937
2017
  },
938
2018
  slicer_path: { type: "string", description: "Path to the slicer executable for auto-slicing (default: value from env or a platform default)" },
939
- slicer_profile: { type: "string", description: "Path to an optional slicer profile/config file for auto-slicing" },
940
2019
  use_ams: { type: "boolean", description: "Whether to use the AMS (default: auto-detect from 3MF)" },
941
2020
  ams_mapping: {
942
2021
  type: "array",
943
- description: "AMS slot mapping array, e.g. [0, 2] maps filaments to AMS slots 0 and 2",
2022
+ description: "Project-level AMS mapping array. Position = project filament index, value = absolute AMS tray (0-3=AMS 0, 4-7=AMS 1, 8-11=AMS 2, 128+=AMS-HT, 254=external, -1=unused). Prefer ams_slots unless you know the project-level layout.",
944
2023
  items: { type: "number" }
945
2024
  },
2025
+ ams_slots: {
2026
+ type: "array",
2027
+ description: "Preferred AMS input: one absolute tray index per USED filament in plate order, e.g. [1] for a single-filament print pulling from AMS 0 slot 1. Expanded to project-level ams_mapping automatically from the 3MF's plate_N.json and gcode header.",
2028
+ items: { type: "number" }
2029
+ },
2030
+ auto_match_ams: {
2031
+ type: "boolean",
2032
+ 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."
2033
+ },
946
2034
  bed_leveling: { type: "boolean", description: "Enable auto bed leveling (default: true)" },
947
2035
  flow_calibration: { type: "boolean", description: "Enable flow calibration (default: true)" },
948
2036
  vibration_calibration: { type: "boolean", description: "Enable vibration calibration (default: true)" },
949
- layer_inspect: { type: "boolean", description: "Enable first-layer inspection where supported (default: printer/profile behavior)" },
950
2037
  timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
2038
+ slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
2039
+ template_3mf_path: { type: "string", description: "Optional template 3MF whose embedded Bambu slicer settings should be reused when auto-slicing this print job." },
2040
+ template_name: { type: "string", description: "Optional named template from the local registry. Resolves to template_3mf_path automatically." },
2041
+ template_dir: { type: "string", description: "Optional template directory override when resolving template_name." },
951
2042
  nozzle_diameter: { type: "string", description: "Nozzle diameter in mm for auto-slicing (default: 0.4)" }
952
2043
  },
953
2044
  required: ["three_mf_path", "bambu_model"]
954
2045
  }
955
2046
  },
2047
+ {
2048
+ name: "print_collar_charm",
2049
+ description: "Print a prepared two-part dog collar charm project using the fixed tray policy: inner/smaller object -> black on AMS 1 slot 1, outer/larger object -> white on AMS 2 slot 1.",
2050
+ inputSchema: {
2051
+ type: "object",
2052
+ properties: {
2053
+ source_path: { type: "string", description: "Path to a prepared collar charm .3mf project or sliced 3MF. Required unless template_name is provided." },
2054
+ template_name: { type: "string", description: "Named collar charm template from the local registry. Required unless source_path is provided; resolves source_path automatically." },
2055
+ template_dir: { type: "string", description: "Optional template directory override when resolving template_name." },
2056
+ bambu_model: {
2057
+ type: "string",
2058
+ enum: [...VALID_BAMBU_MODELS],
2059
+ description: "REQUIRED: Bambu Lab printer model. H2D, H2S, and H2C are the primary intended paths."
2060
+ },
2061
+ host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
2062
+ bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
2063
+ bambu_token: { type: "string", description: "Access token (default: value from env)" },
2064
+ bed_type: {
2065
+ type: "string",
2066
+ enum: ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"],
2067
+ description: "Bed plate type currently installed (default: textured_plate)"
2068
+ },
2069
+ bed_leveling: { type: "boolean", description: "Enable auto bed leveling (default: true)" },
2070
+ flow_calibration: { type: "boolean", description: "Enable flow calibration (default: true)" },
2071
+ vibration_calibration: { type: "boolean", description: "Enable vibration calibration (default: true)" },
2072
+ timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
2073
+ slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
2074
+ nozzle_diameter: { type: "string", description: "Nozzle diameter in mm for auto-slicing (default: 0.4)" }
2075
+ },
2076
+ required: ["bambu_model"]
2077
+ }
2078
+ },
956
2079
  {
957
2080
  name: "merge_vertices",
958
2081
  description: "Merge vertices in an STL file closer than the specified tolerance",
@@ -1013,12 +2136,60 @@ class BambuPrinterMCPServer {
1013
2136
  const host = String(args?.host || DEFAULT_HOST);
1014
2137
  const bambuSerial = String(args?.bambu_serial || DEFAULT_BAMBU_SERIAL);
1015
2138
  const bambuToken = String(args?.bambu_token || DEFAULT_BAMBU_TOKEN);
2139
+ const requestedTemplateDir = typeof args?.template_dir === "string" && args.template_dir.trim().length > 0
2140
+ ? String(args.template_dir)
2141
+ : undefined;
2142
+ const requestedTemplateName = typeof args?.template_name === "string" ? String(args.template_name) : undefined;
2143
+ const resolveTemplatePathFromName = (sourceTypes) => this.resolveTemplatePath(requestedTemplateName, requestedTemplateDir, sourceTypes);
2144
+ const explicitTemplatePath = String(args?.template_3mf_path || DEFAULT_TEMPLATE_3MF_PATH);
1016
2145
  try {
1017
2146
  let result;
1018
2147
  switch (name) {
1019
2148
  case "get_printer_status":
1020
2149
  result = await this.bambu.getStatus(host, bambuSerial, bambuToken);
1021
2150
  break;
2151
+ case "get_printer_filaments": {
2152
+ const requestedModel = (String(args?.bambu_model ?? DEFAULT_BAMBU_MODEL ?? "")).trim().toLowerCase();
2153
+ const normalizedModel = requestedModel ? validateBambuModel(requestedModel) : undefined;
2154
+ const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2155
+ result = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, normalizedModel, nozzleDiam);
2156
+ break;
2157
+ }
2158
+ case "resolve_3mf_ams_slots": {
2159
+ if (!args?.three_mf_path) {
2160
+ throw new Error("Missing required parameter: three_mf_path");
2161
+ }
2162
+ const requestedModel = (String(args?.bambu_model ?? DEFAULT_BAMBU_MODEL ?? "")).trim().toLowerCase();
2163
+ const normalizedModel = requestedModel ? validateBambuModel(requestedModel) : undefined;
2164
+ const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2165
+ const requirements = await analyze3MFAmsRequirements(String(args.three_mf_path), args?.plate_index !== undefined ? Number(args.plate_index) : 0);
2166
+ const inventory = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, normalizedModel, nozzleDiam);
2167
+ const resolved = resolveAmsSlotsFromRequirements(requirements, inventory);
2168
+ result = {
2169
+ status: resolved.missing.length === 0 ? "matched" : "missing",
2170
+ requirements,
2171
+ ams_slots: resolved.ams_slots,
2172
+ matches: resolved.matches,
2173
+ missing: resolved.missing,
2174
+ };
2175
+ break;
2176
+ }
2177
+ case "list_3mf_plate_objects": {
2178
+ if (!args?.three_mf_path) {
2179
+ throw new Error("Missing required parameter: three_mf_path");
2180
+ }
2181
+ result = await analyze3MFPlateObjects(String(args.three_mf_path), args?.plate_index !== undefined ? Number(args.plate_index) : 0);
2182
+ break;
2183
+ }
2184
+ case "list_templates":
2185
+ result = this.listTemplateRegistry(requestedTemplateDir);
2186
+ break;
2187
+ case "save_template":
2188
+ if (!args?.source_path) {
2189
+ throw new Error("Missing required parameter: source_path");
2190
+ }
2191
+ result = this.saveTemplate(String(args.source_path), typeof args?.template_name === "string" ? String(args.template_name) : undefined, requestedTemplateDir);
2192
+ break;
1022
2193
  case "list_printer_files":
1023
2194
  result = await this.bambu.getFiles(host, bambuSerial, bambuToken);
1024
2195
  break;
@@ -1055,6 +2226,23 @@ class BambuPrinterMCPServer {
1055
2226
  result = await this.print3mfViaBambuNetwork(args, host, bambuSerial, bambuToken);
1056
2227
  break;
1057
2228
  }
2229
+ case "camera_snapshot": {
2230
+ const snapshotModel = args?.bambu_model ?? process.env.BAMBU_MODEL ?? process.env.BAMBU_PRINTER_MODEL;
2231
+ result = await this.bambu.cameraSnapshot(host, bambuSerial, bambuToken, {
2232
+ savePath: args?.save_path ? String(args.save_path) : undefined,
2233
+ timeoutMs: args?.timeout_ms !== undefined ? Number(args.timeout_ms) : undefined,
2234
+ bambuModel: snapshotModel ? String(snapshotModel) : undefined,
2235
+ experimental: Boolean(args?.experimental),
2236
+ ffmpegPath: args?.ffmpeg_path ? String(args.ffmpeg_path) : undefined,
2237
+ });
2238
+ break;
2239
+ }
2240
+ case "delete_printer_file":
2241
+ if (!args?.filename) {
2242
+ throw new Error("Missing required parameter: filename");
2243
+ }
2244
+ result = await this.bambu.deleteFile(host, bambuSerial, bambuToken, String(args.filename), args.confirm);
2245
+ break;
1058
2246
  case "upload_gcode": {
1059
2247
  if (!args?.filename) {
1060
2248
  throw new Error("Missing required parameter: filename");
@@ -1090,12 +2278,63 @@ class BambuPrinterMCPServer {
1090
2278
  case "cancel_print":
1091
2279
  result = await this.bambu.cancelJob(host, bambuSerial, bambuToken);
1092
2280
  break;
2281
+ case "pause_print":
2282
+ result = await this.bambu.pauseJob(host, bambuSerial, bambuToken);
2283
+ break;
2284
+ case "resume_print":
2285
+ result = await this.bambu.resumeJob(host, bambuSerial, bambuToken);
2286
+ break;
2287
+ case "clear_hms_errors":
2288
+ result = await this.bambu.clearHmsErrors(host, bambuSerial, bambuToken);
2289
+ break;
2290
+ case "set_print_speed":
2291
+ if (!args?.mode) {
2292
+ throw new Error("Missing required parameter: mode");
2293
+ }
2294
+ result = await this.bambu.setPrintSpeed(host, bambuSerial, bambuToken, String(args.mode));
2295
+ break;
2296
+ case "set_airduct_mode":
2297
+ if (!args?.mode) {
2298
+ throw new Error("Missing required parameter: mode");
2299
+ }
2300
+ result = await this.bambu.setAirductMode(host, bambuSerial, bambuToken, String(args.mode));
2301
+ break;
2302
+ case "reread_ams_rfid":
2303
+ if (args?.ams_id === undefined || args?.slot_id === undefined) {
2304
+ throw new Error("Missing required parameters: ams_id and slot_id");
2305
+ }
2306
+ result = await this.bambu.rereadAmsRfid(host, bambuSerial, bambuToken, Number(args.ams_id), Number(args.slot_id));
2307
+ break;
1093
2308
  case "set_temperature":
1094
2309
  if (!args?.component || args?.temperature === undefined) {
1095
2310
  throw new Error("Missing required parameters: component and temperature");
1096
2311
  }
1097
2312
  result = await this.bambu.setTemperature(host, bambuSerial, bambuToken, String(args.component), Number(args.temperature));
1098
2313
  break;
2314
+ case "set_fan_speed":
2315
+ if (!args?.fan || args?.speed === undefined) {
2316
+ throw new Error("Missing required parameters: fan and speed");
2317
+ }
2318
+ result = await this.bambu.setFanSpeed(host, bambuSerial, bambuToken, String(args.fan), Number(args.speed));
2319
+ break;
2320
+ case "set_light":
2321
+ if (!args?.light || !args?.mode) {
2322
+ throw new Error("Missing required parameters: light and mode");
2323
+ }
2324
+ result = await this.bambu.setLight(host, bambuSerial, bambuToken, String(args.light), String(args.mode));
2325
+ break;
2326
+ case "skip_objects":
2327
+ if (!Array.isArray(args?.object_ids)) {
2328
+ throw new Error("Missing required parameter: object_ids");
2329
+ }
2330
+ result = await this.bambu.skipObjects(host, bambuSerial, bambuToken, args.object_ids.map((id) => Number(id)));
2331
+ break;
2332
+ case "set_ams_drying":
2333
+ if (!args?.action || args?.ams_id === undefined) {
2334
+ throw new Error("Missing required parameters: action and ams_id");
2335
+ }
2336
+ result = await this.bambu.setAmsDrying(host, bambuSerial, bambuToken, String(args.action), Number(args.ams_id));
2337
+ break;
1099
2338
  case "extend_stl_base":
1100
2339
  if (!args?.stl_path || args?.extension_height === undefined) {
1101
2340
  throw new Error("Missing required parameters: stl_path and extension_height");
@@ -1128,6 +2367,91 @@ class BambuPrinterMCPServer {
1128
2367
  }
1129
2368
  result = await this.stlManipulator.getSTLInfo(String(args.stl_path));
1130
2369
  break;
2370
+ case "get_slice_settings":
2371
+ if (!args?.source_path && !args?.template_name) {
2372
+ throw new Error("Missing required parameter: source_path or template_name");
2373
+ }
2374
+ result = await this.inspectSliceSettings(String(args?.source_path || resolveTemplatePathFromName(["3mf", "json", "config"])));
2375
+ break;
2376
+ case "slice_with_template": {
2377
+ if (!args?.stl_path) {
2378
+ throw new Error("Missing required parameter: stl_path");
2379
+ }
2380
+ if (!args?.template_name) {
2381
+ throw new Error("Missing required parameter: template_name");
2382
+ }
2383
+ const { slicerType, slicerPath, slicerProfile } = resolveSlicerConfig(args);
2384
+ const sliceModel = await this.resolveBambuModel(args?.bambu_model);
2385
+ const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2386
+ const activeSlicerProfile = await resolveTemplateFirstSlicerProfilePath(args, slicerProfile || undefined, resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined, TEMP_DIR);
2387
+ const explicitSlicerProfile = hasExplicitSlicerProfile(args);
2388
+ const printerPreset = BAMBU_MODEL_PRESETS[sliceModel]?.(nozzleDiam);
2389
+ const sliceBambuOptions = {};
2390
+ if (args?.uptodate !== undefined)
2391
+ sliceBambuOptions.uptodate = Boolean(args.uptodate);
2392
+ if (args?.repetitions !== undefined)
2393
+ sliceBambuOptions.repetitions = Number(args.repetitions);
2394
+ if (args?.orient !== undefined)
2395
+ sliceBambuOptions.orient = Boolean(args.orient);
2396
+ if (args?.arrange !== undefined)
2397
+ sliceBambuOptions.arrange = Boolean(args.arrange);
2398
+ if (args?.ensure_on_bed !== undefined)
2399
+ sliceBambuOptions.ensureOnBed = Boolean(args.ensure_on_bed);
2400
+ if (args?.clone_objects !== undefined)
2401
+ sliceBambuOptions.cloneObjects = String(args.clone_objects);
2402
+ if (args?.skip_objects !== undefined)
2403
+ sliceBambuOptions.skipObjects = String(args.skip_objects);
2404
+ if (args?.load_filaments !== undefined &&
2405
+ args?.filament_profile !== undefined &&
2406
+ String(args.load_filaments) !== String(args.filament_profile)) {
2407
+ throw new Error("Provide either load_filaments or filament_profile, not conflicting values.");
2408
+ }
2409
+ if (args?.load_filaments !== undefined) {
2410
+ sliceBambuOptions.loadFilaments = String(args.load_filaments);
2411
+ }
2412
+ else if (args?.filament_profile !== undefined) {
2413
+ sliceBambuOptions.loadFilaments = String(args.filament_profile);
2414
+ }
2415
+ if (args?.load_filament_ids !== undefined)
2416
+ sliceBambuOptions.loadFilamentIds = String(args.load_filament_ids);
2417
+ sliceBambuOptions.bedType = resolveBambuStudioCliBedType(args?.bed_type);
2418
+ if (args?.enable_timelapse !== undefined)
2419
+ sliceBambuOptions.enableTimelapse = Boolean(args.enable_timelapse);
2420
+ if (args?.allow_mix_temp !== undefined)
2421
+ sliceBambuOptions.allowMixTemp = Boolean(args.allow_mix_temp);
2422
+ if (args?.scale !== undefined)
2423
+ sliceBambuOptions.scale = Number(args.scale);
2424
+ if (args?.rotate !== undefined)
2425
+ sliceBambuOptions.rotate = Number(args.rotate);
2426
+ if (args?.rotate_x !== undefined)
2427
+ sliceBambuOptions.rotateX = Number(args.rotate_x);
2428
+ if (args?.rotate_y !== undefined)
2429
+ sliceBambuOptions.rotateY = Number(args.rotate_y);
2430
+ if (args?.min_save !== undefined)
2431
+ sliceBambuOptions.minSave = Boolean(args.min_save);
2432
+ if (args?.skip_modified_gcodes !== undefined)
2433
+ sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
2434
+ if (args?.slice_plate !== undefined)
2435
+ sliceBambuOptions.slicePlate = Number(args.slice_plate);
2436
+ const usePrinterFilaments = args?.use_printer_filaments !== undefined ? Boolean(args.use_printer_filaments) : true;
2437
+ if (usePrinterFilaments &&
2438
+ !explicitSlicerProfile &&
2439
+ !sliceBambuOptions.loadFilaments &&
2440
+ bambuSerial &&
2441
+ bambuToken) {
2442
+ try {
2443
+ const liveFilaments = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, sliceModel, nozzleDiam);
2444
+ if (liveFilaments.recommended?.load_filaments) {
2445
+ sliceBambuOptions.loadFilaments = liveFilaments.recommended.load_filaments;
2446
+ }
2447
+ }
2448
+ catch (filamentError) {
2449
+ console.warn("Could not resolve live printer filaments for slicing:", filamentError);
2450
+ }
2451
+ }
2452
+ result = await this.stlManipulator.sliceSTL(String(args.stl_path), slicerType, slicerPath, activeSlicerProfile, undefined, printerPreset, sliceBambuOptions);
2453
+ break;
2454
+ }
1131
2455
  case "slice_stl": {
1132
2456
  if (!args?.stl_path) {
1133
2457
  throw new Error("Missing required parameter: stl_path");
@@ -1135,6 +2459,8 @@ class BambuPrinterMCPServer {
1135
2459
  const { slicerType, slicerPath, slicerProfile } = resolveSlicerConfig(args);
1136
2460
  const sliceModel = await this.resolveBambuModel(args?.bambu_model);
1137
2461
  const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2462
+ const activeSlicerProfile = await resolveSlicerProfilePath(slicerProfile || undefined, resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined, TEMP_DIR);
2463
+ const explicitSlicerProfile = hasExplicitSlicerProfile(args);
1138
2464
  // Resolve printer preset for BambuStudio slicer
1139
2465
  const printerPreset = BAMBU_MODEL_PRESETS[sliceModel]?.(nozzleDiam);
1140
2466
  const sliceBambuOptions = {};
@@ -1165,6 +2491,7 @@ class BambuPrinterMCPServer {
1165
2491
  }
1166
2492
  if (args?.load_filament_ids !== undefined)
1167
2493
  sliceBambuOptions.loadFilamentIds = String(args.load_filament_ids);
2494
+ sliceBambuOptions.bedType = resolveBambuStudioCliBedType(args?.bed_type);
1168
2495
  if (args?.enable_timelapse !== undefined)
1169
2496
  sliceBambuOptions.enableTimelapse = Boolean(args.enable_timelapse);
1170
2497
  if (args?.allow_mix_temp !== undefined)
@@ -1183,7 +2510,23 @@ class BambuPrinterMCPServer {
1183
2510
  sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
1184
2511
  if (args?.slice_plate !== undefined)
1185
2512
  sliceBambuOptions.slicePlate = Number(args.slice_plate);
1186
- result = await this.stlManipulator.sliceSTL(String(args.stl_path), slicerType, slicerPath, slicerProfile || undefined, undefined, // progressCallback
2513
+ const usePrinterFilaments = args?.use_printer_filaments !== undefined ? Boolean(args.use_printer_filaments) : true;
2514
+ if (usePrinterFilaments &&
2515
+ !explicitSlicerProfile &&
2516
+ !sliceBambuOptions.loadFilaments &&
2517
+ bambuSerial &&
2518
+ bambuToken) {
2519
+ try {
2520
+ const liveFilaments = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, sliceModel, nozzleDiam);
2521
+ if (liveFilaments.recommended?.load_filaments) {
2522
+ sliceBambuOptions.loadFilaments = liveFilaments.recommended.load_filaments;
2523
+ }
2524
+ }
2525
+ catch (filamentError) {
2526
+ console.warn("Could not resolve live printer filaments for slicing:", filamentError);
2527
+ }
2528
+ }
2529
+ result = await this.stlManipulator.sliceSTL(String(args.stl_path), slicerType, slicerPath, activeSlicerProfile, undefined, // progressCallback
1187
2530
  printerPreset, sliceBambuOptions);
1188
2531
  break;
1189
2532
  }
@@ -1202,6 +2545,8 @@ class BambuPrinterMCPServer {
1202
2545
  const printModel = await this.resolveBambuModel(args?.bambu_model);
1203
2546
  const printBedType = resolveBedType(args?.bed_type);
1204
2547
  const printNozzle = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2548
+ const activeSlicerProfile = await resolveTemplateFirstSlicerProfilePath(args, slicerProfile || undefined, resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined, TEMP_DIR);
2549
+ const explicitSlicerProfile = hasExplicitSlicerProfile(args);
1205
2550
  const printPreset = BAMBU_MODEL_PRESETS[printModel]?.(printNozzle);
1206
2551
  const plateIndex = args?.plate_index !== undefined ? Number(args.plate_index) : 0;
1207
2552
  if (!Number.isInteger(plateIndex) || plateIndex < 0) {
@@ -1215,53 +2560,104 @@ class BambuPrinterMCPServer {
1215
2560
  const zip = await JSZip.loadAsync(zipData);
1216
2561
  const hasGcode = Object.keys(zip.files).some(f => f.match(/Metadata\/plate_\d+\.gcode/i) || f.endsWith('.gcode'));
1217
2562
  if (!hasGcode) {
1218
- console.log(`3MF has no gcode - auto-slicing with ${slicerType} for ${printModel}`);
2563
+ if (printBedType === "supertack_plate") {
2564
+ throw new Error('BambuStudio CLI SuperTack bed type is not verified; use a pre-sliced 3MF for SuperTack or choose textured_plate, cool_plate, engineering_plate, or hot_plate.');
2565
+ }
2566
+ console.log(`3MF has no gcode — auto-slicing with ${slicerType} for ${printModel}`);
1219
2567
  const autoSliceOptions = {
1220
2568
  uptodate: true,
1221
2569
  ensureOnBed: true,
1222
2570
  minSave: true,
1223
2571
  skipModifiedGcodes: true,
2572
+ bedType: printBedType,
1224
2573
  };
1225
- threeMFPath = await this.stlManipulator.sliceSTL(threeMFPath, slicerType, slicerPath, slicerProfile || undefined, undefined, // progressCallback
2574
+ if (!explicitSlicerProfile) {
2575
+ try {
2576
+ const liveFilaments = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, printModel, printNozzle);
2577
+ if (liveFilaments.recommended?.load_filaments) {
2578
+ autoSliceOptions.loadFilaments = liveFilaments.recommended.load_filaments;
2579
+ }
2580
+ }
2581
+ catch (filamentError) {
2582
+ console.warn("Could not resolve live printer filaments for auto-slicing:", filamentError);
2583
+ }
2584
+ }
2585
+ threeMFPath = await this.stlManipulator.sliceSTL(threeMFPath, slicerType, slicerPath, activeSlicerProfile, undefined, // progressCallback
1226
2586
  printPreset, autoSliceOptions);
1227
2587
  console.log("Auto-sliced to: " + threeMFPath);
1228
2588
  }
1229
2589
  }
1230
2590
  catch (sliceCheckErr) {
2591
+ if (String(sliceCheckErr?.message || "").includes("SuperTack")) {
2592
+ throw sliceCheckErr;
2593
+ }
1231
2594
  console.warn("Could not check/slice 3MF, proceeding with original:", sliceCheckErr.message);
1232
2595
  }
1233
2596
  const parsed3MFData = await parse3MF(threeMFPath);
2597
+ const isH2Print = H2_BAMBU_MODELS.has(printModel);
1234
2598
  let parsedAmsMapping;
1235
- if (parsed3MFData.slicerConfig?.ams_mapping) {
1236
- const slots = Object.values(parsed3MFData.slicerConfig.ams_mapping)
1237
- .filter(v => typeof v === 'number');
2599
+ if (!isH2Print && parsed3MFData.slicerConfig?.ams_mapping) {
2600
+ const slots = normalizeAmsMappingObject(parsed3MFData.slicerConfig.ams_mapping);
1238
2601
  if (slots.length > 0) {
1239
- parsedAmsMapping = slots.sort((a, b) => a - b);
2602
+ parsedAmsMapping = slots;
1240
2603
  }
1241
2604
  }
1242
2605
  let finalAmsMapping = parsedAmsMapping;
1243
- const explicitUseAMS = args?.use_ams !== undefined;
1244
- let useAMS = explicitUseAMS ? Boolean(args.use_ams) : (!!finalAmsMapping && finalAmsMapping.length > 0);
1245
- if (args?.ams_mapping) {
2606
+ let finalAmsSlots;
2607
+ let useAMS = args?.use_ams !== undefined ? Boolean(args.use_ams) : (!!finalAmsMapping && finalAmsMapping.length > 0);
2608
+ const hasUserAmsMapping = hasAmsMappingInput(args?.ams_mapping);
2609
+ const hasUserAmsSlots = Array.isArray(args?.ams_slots);
2610
+ if (hasUserAmsMapping) {
1246
2611
  let userMappingOverride;
1247
2612
  if (Array.isArray(args.ams_mapping)) {
1248
- userMappingOverride = args.ams_mapping.filter((v) => typeof v === 'number');
2613
+ userMappingOverride = args.ams_mapping.map((v, i) => normalizeBridgeAmsTrayValue(v, `ams_mapping[${i}]`));
1249
2614
  }
1250
- else if (typeof args.ams_mapping === 'object') {
1251
- userMappingOverride = Object.values(args.ams_mapping)
1252
- .filter((v) => typeof v === 'number')
1253
- .sort((a, b) => a - b);
2615
+ else if (args.ams_mapping && typeof args.ams_mapping === 'object') {
2616
+ userMappingOverride = normalizeAmsMappingObject(args.ams_mapping);
1254
2617
  }
1255
2618
  if (userMappingOverride && userMappingOverride.length > 0) {
1256
2619
  finalAmsMapping = userMappingOverride;
1257
2620
  useAMS = true;
1258
2621
  }
1259
2622
  }
2623
+ if (hasUserAmsSlots) {
2624
+ const userSlots = args.ams_slots.filter((v) => typeof v === 'number');
2625
+ if (userSlots.length > 0) {
2626
+ finalAmsSlots = userSlots;
2627
+ finalAmsMapping = undefined;
2628
+ useAMS = true;
2629
+ }
2630
+ }
2631
+ if (!hasUserAmsMapping && !hasUserAmsSlots && args?.auto_match_ams === true && args?.use_ams !== false) {
2632
+ const requirements = await analyze3MFAmsRequirements(threeMFPath, plateIndex);
2633
+ const inventory = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, printModel, printNozzle);
2634
+ const resolved = resolveAmsSlotsFromRequirements(requirements, inventory);
2635
+ if (resolved.missing.length > 0) {
2636
+ throw new Error(`auto_match_ams could not find loaded AMS trays for: ${resolved.missing
2637
+ .map((missing) => missing.tray_info_idx || `filament position ${missing.filament_position}`)
2638
+ .join(", ")}`);
2639
+ }
2640
+ finalAmsMapping = undefined;
2641
+ finalAmsSlots = resolved.ams_slots;
2642
+ useAMS = finalAmsSlots.length > 0;
2643
+ }
2644
+ if (isH2Print &&
2645
+ !hasUserAmsMapping &&
2646
+ !hasUserAmsSlots &&
2647
+ args?.auto_match_ams !== true &&
2648
+ (!finalAmsMapping || finalAmsMapping.length === 0) &&
2649
+ (!finalAmsSlots || finalAmsSlots.length === 0)) {
2650
+ const requirements = await analyze3MFAmsRequirements(threeMFPath, plateIndex);
2651
+ if (requirements.usedFilamentPositions.length > 0) {
2652
+ throw new Error(`H2 ${printModel.toUpperCase()} pre-sliced jobs with declared filaments require ams_slots, ams_mapping, or auto_match_ams: true. Plate uses project filament positions ${JSON.stringify(requirements.usedFilamentPositions)}; pass one physical tray per used filament, for example ams_slots: [0] for AMS 0 slot 0 or [1] for AMS 0 slot 1.`);
2653
+ }
2654
+ }
1260
2655
  if (args?.use_ams === false) {
1261
2656
  finalAmsMapping = undefined;
2657
+ finalAmsSlots = undefined;
1262
2658
  useAMS = false;
1263
2659
  }
1264
- if ((!finalAmsMapping || finalAmsMapping.length === 0) && !explicitUseAMS) {
2660
+ if ((!finalAmsMapping || finalAmsMapping.length === 0) && (!finalAmsSlots || finalAmsSlots.length === 0)) {
1265
2661
  useAMS = false;
1266
2662
  }
1267
2663
  const threeMfFilename = path.basename(threeMFPath);
@@ -1269,9 +2665,11 @@ class BambuPrinterMCPServer {
1269
2665
  result = await this.bambu.print3mf(host, bambuSerial, bambuToken, {
1270
2666
  projectName,
1271
2667
  filePath: threeMFPath,
2668
+ bambuModel: printModel,
1272
2669
  plateIndex,
1273
2670
  useAMS: useAMS,
1274
2671
  amsMapping: finalAmsMapping,
2672
+ amsSlots: finalAmsSlots,
1275
2673
  bedType: printBedType,
1276
2674
  bedLeveling: args?.bed_leveling !== undefined ? Boolean(args.bed_leveling) : undefined,
1277
2675
  flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : undefined,
@@ -1282,6 +2680,64 @@ class BambuPrinterMCPServer {
1282
2680
  result = `Print command for ${threeMfFilename} sent successfully.`;
1283
2681
  break;
1284
2682
  }
2683
+ case "print_collar_charm": {
2684
+ const resolvedTemplateSourcePath = resolveTemplatePathFromName(["3mf"]);
2685
+ const resolvedSourcePath = String(resolvedTemplateSourcePath || args?.source_path || "");
2686
+ if (!resolvedSourcePath) {
2687
+ throw new Error("Missing required parameter: source_path or template_name");
2688
+ }
2689
+ if (!bambuSerial || !bambuToken) {
2690
+ throw new Error("Bambu serial number and access token are required for print_collar_charm.");
2691
+ }
2692
+ const { slicerType, slicerPath, slicerProfile } = resolveSlicerConfig(args);
2693
+ const printModel = await this.resolveBambuModel(args?.bambu_model);
2694
+ const printBedType = resolveBedType(args?.bed_type);
2695
+ const printNozzle = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
2696
+ const activeSlicerProfile = await resolveTemplateFirstSlicerProfilePath(args, slicerProfile || undefined, resolvedTemplateSourcePath || explicitTemplatePath || undefined, TEMP_DIR);
2697
+ const preparedThreeMFPath = await this.resolveCollarCharmPrepared3MF(resolvedSourcePath, resolvedTemplateSourcePath || explicitTemplatePath || undefined, slicerType, slicerPath, activeSlicerProfile || undefined, printModel, printNozzle, printBedType, host, bambuSerial, bambuToken);
2698
+ const collarAnalysis = await analyzeCollarCharm3MF(preparedThreeMFPath, 0);
2699
+ const inventory = await this.preflightCollarCharmPolicy(host, bambuSerial, bambuToken, printModel, printNozzle);
2700
+ const projectName = path.basename(preparedThreeMFPath).replace(/\.3mf$/i, '');
2701
+ result = await this.bambu.print3mf(host, bambuSerial, bambuToken, {
2702
+ projectName,
2703
+ filePath: preparedThreeMFPath,
2704
+ bambuModel: printModel,
2705
+ plateIndex: collarAnalysis.plateIndex,
2706
+ useAMS: true,
2707
+ amsSlots: collarAnalysis.amsSlots,
2708
+ bedType: printBedType,
2709
+ bedLeveling: args?.bed_leveling !== undefined ? Boolean(args.bed_leveling) : true,
2710
+ flowCalibration: args?.flow_calibration !== undefined ? Boolean(args.flow_calibration) : true,
2711
+ vibrationCalibration: args?.vibration_calibration !== undefined ? Boolean(args.vibration_calibration) : true,
2712
+ timelapse: args?.timelapse !== undefined ? Boolean(args.timelapse) : false,
2713
+ });
2714
+ result = {
2715
+ ...result,
2716
+ source_path: resolvedSourcePath,
2717
+ prepared_three_mf_path: preparedThreeMFPath,
2718
+ tray_policy: {
2719
+ inner: {
2720
+ color: COLLAR_CHARM_POLICY.colors.inner,
2721
+ absolute_tray: COLLAR_CHARM_POLICY.amsSlots.inner,
2722
+ },
2723
+ outer: {
2724
+ color: COLLAR_CHARM_POLICY.colors.outer,
2725
+ absolute_tray: COLLAR_CHARM_POLICY.amsSlots.outer,
2726
+ },
2727
+ },
2728
+ collar_roles: collarAnalysis.roles,
2729
+ inventory_slots_checked: inventory.trays
2730
+ .filter((tray) => tray.slot === COLLAR_CHARM_POLICY.amsSlots.inner || tray.slot === COLLAR_CHARM_POLICY.amsSlots.outer)
2731
+ .map((tray) => ({
2732
+ slot: tray.slot,
2733
+ loaded: tray.loaded,
2734
+ tray_color: tray.tray_color,
2735
+ tray_type: tray.tray_type,
2736
+ tray_info_idx: tray.tray_info_idx,
2737
+ })),
2738
+ };
2739
+ break;
2740
+ }
1285
2741
  case "merge_vertices":
1286
2742
  if (!args?.stl_path)
1287
2743
  throw new Error("Missing required parameter: stl_path");