bambu-printer-mcp 1.1.51 → 1.1.53

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.
Files changed (57) hide show
  1. package/README.md +33 -8
  2. package/dist/ams-mapping.d.ts +19 -0
  3. package/dist/ams-mapping.js +49 -0
  4. package/dist/bambu-network-bridge.d.ts +86 -9
  5. package/dist/bambu-network-bridge.js +284 -4
  6. package/dist/control-reply.d.ts +21 -0
  7. package/dist/control-reply.js +44 -0
  8. package/dist/counterpart/info.js +1 -0
  9. package/dist/counterpart/route.d.ts +37 -0
  10. package/dist/counterpart/route.js +78 -0
  11. package/dist/counterpart/schemas.d.ts +4 -0
  12. package/dist/counterpart/schemas.js +1 -0
  13. package/dist/design-guidance.d.ts +26 -0
  14. package/dist/design-guidance.js +177 -0
  15. package/dist/fusion-mcp-bridge.d.ts +8 -4
  16. package/dist/fusion-mcp-bridge.js +36 -10
  17. package/dist/index.js +206 -51
  18. package/dist/printers/bambu.d.ts +38 -13
  19. package/dist/printers/bambu.js +204 -69
  20. package/dist/printers/camera-sources.d.ts +8 -0
  21. package/dist/printers/camera-sources.js +66 -0
  22. package/dist/printers/camera-stream.d.ts +65 -0
  23. package/dist/printers/camera-stream.js +227 -0
  24. package/dist/printers/camera-tools.d.ts +192 -0
  25. package/dist/printers/camera-tools.js +29 -0
  26. package/dist/printers/camera-wire.d.ts +7 -0
  27. package/dist/printers/camera-wire.js +40 -0
  28. package/dist/safety/print-file.d.ts +3 -0
  29. package/dist/safety/print-file.js +11 -2
  30. package/dist/safety/printer-state.d.ts +7 -0
  31. package/dist/safety/printer-state.js +11 -1
  32. package/dist/slicer/layer-pauses.d.ts +47 -0
  33. package/dist/slicer/layer-pauses.js +130 -0
  34. package/dist/stl/stl-manipulator.d.ts +3 -0
  35. package/dist/stl/stl-manipulator.js +50 -4
  36. package/dist/tool-annotations.d.ts +25 -0
  37. package/dist/tool-annotations.js +96 -0
  38. package/package.json +2 -1
  39. package/src/ams-mapping.ts +52 -0
  40. package/src/bambu-network-bridge.ts +311 -8
  41. package/src/control-reply.ts +41 -0
  42. package/src/counterpart/info.ts +1 -0
  43. package/src/counterpart/route.ts +91 -0
  44. package/src/counterpart/schemas.ts +2 -0
  45. package/src/design-guidance.ts +188 -0
  46. package/src/fusion-mcp-bridge.ts +30 -10
  47. package/src/index.ts +199 -55
  48. package/src/printers/bambu.ts +194 -60
  49. package/src/printers/camera-sources.ts +53 -0
  50. package/src/printers/camera-stream.ts +165 -0
  51. package/src/printers/camera-tools.ts +29 -0
  52. package/src/printers/camera-wire.ts +39 -0
  53. package/src/safety/print-file.ts +12 -2
  54. package/src/safety/printer-state.ts +11 -1
  55. package/src/slicer/layer-pauses.ts +143 -0
  56. package/src/stl/stl-manipulator.ts +58 -5
  57. package/src/tool-annotations.ts +126 -0
@@ -0,0 +1,130 @@
1
+ import fs from "node:fs";
2
+ import JSZip from "jszip";
3
+ /**
4
+ * Pause-at-layer for Bambu-compatible slicer CLIs ("Add pause" in Bambu Studio
5
+ * and OrcaSlicer). The slicer writes the machine's own machine_pause_gcode
6
+ * (M400 U1 on Bambu printers) before the chosen layer, so the printer pauses
7
+ * by itself there and waits for Resume; no remote command is involved.
8
+ *
9
+ * The CLI takes these as --load-custom-gcodes <json> (CustomGCode::Info). It
10
+ * does not apply the pauses a project 3MF already carries in
11
+ * Metadata/custom_gcode_per_print_z.xml, so those are read here and passed the
12
+ * same way. A pause's print_z must be the exact top of its layer: a height
13
+ * between layers lands on the layer below.
14
+ */
15
+ /** CustomGCode::Type, in the order bbs_3mf.cpp writes it as an integer. */
16
+ const CUSTOM_GCODE_TYPES = ["ColorChange", "PausePrint", "ToolChange", "Template", "Custom", "Unknown"];
17
+ /** 1-based layer numbers, as Bambu Studio's and OrcaSlicer's preview slider count them. */
18
+ export function parsePauseLayers(value) {
19
+ if (value === undefined || value === null || value === "")
20
+ return undefined;
21
+ const raw = Array.isArray(value) ? value : String(value).split(/[\s,;]+/).filter(Boolean);
22
+ const layers = raw.map(entry => Number(entry));
23
+ for (const layer of layers) {
24
+ if (!Number.isInteger(layer) || layer < 2) {
25
+ throw new Error(`pause_at_layers takes whole layer numbers of 2 or more (the printer cannot pause before layer 1), not ${JSON.stringify(value)}.`);
26
+ }
27
+ }
28
+ const unique = [...new Set(layers)].sort((a, b) => a - b);
29
+ return unique.length ? unique : undefined;
30
+ }
31
+ function xmlAttr(tag, name) {
32
+ const match = new RegExp(`\\b${name}="([^"]*)"`).exec(tag);
33
+ return match ? match[1].replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&") : undefined;
34
+ }
35
+ /**
36
+ * The custom G-codes (pauses, colour changes, ...) a project 3MF stores for
37
+ * one plate (1-based), as Bambu Studio and OrcaSlicer save them.
38
+ */
39
+ export async function readProjectCustomGcodes(threeMfPath, plate = 1) {
40
+ let zip;
41
+ try {
42
+ zip = await JSZip.loadAsync(await fs.promises.readFile(threeMfPath));
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ const file = zip.file(/^Metadata\/custom_gcode_per_print_z\.xml$/i)[0];
48
+ if (!file)
49
+ return undefined;
50
+ const xml = await file.async("string");
51
+ for (const block of xml.match(/<plate>[\s\S]*?<\/plate>/g) ?? []) {
52
+ const info = /<plate_info\b[^>]*>/.exec(block)?.[0];
53
+ if (Number(info ? xmlAttr(info, "id") : NaN) !== plate)
54
+ continue;
55
+ const gcodes = [];
56
+ for (const tag of block.match(/<layer\b[^>]*>/g) ?? []) {
57
+ const type = CUSTOM_GCODE_TYPES[Number(xmlAttr(tag, "type"))] ?? "Unknown";
58
+ const printZ = Number(xmlAttr(tag, "top_z"));
59
+ if (!Number.isFinite(printZ))
60
+ continue;
61
+ gcodes.push({
62
+ type,
63
+ print_z: printZ,
64
+ color: xmlAttr(tag, "color") ?? "",
65
+ extruder: Number(xmlAttr(tag, "extruder") ?? 1) || 1,
66
+ // Template and Custom keep their G-code text in "extra" (CustomGCode.hpp).
67
+ extra: xmlAttr(tag, "extra") ?? "",
68
+ });
69
+ }
70
+ const modeTag = /<mode\b[^>]*>/.exec(block)?.[0];
71
+ return { mode: (modeTag && xmlAttr(modeTag, "value")) || "SingleExtruder", gcodes };
72
+ }
73
+ return undefined;
74
+ }
75
+ /** The plate's G-code text inside a sliced 3MF. */
76
+ export async function readPlateGcode(threeMfPath, plate = 1) {
77
+ const zip = await JSZip.loadAsync(await fs.promises.readFile(threeMfPath));
78
+ const exact = zip.file(`Metadata/plate_${plate}.gcode`);
79
+ const file = exact ?? zip.file(/^Metadata\/plate_\d+\.gcode$/)[0];
80
+ return file ? file.async("string") : undefined;
81
+ }
82
+ /** Each layer's top Z in order, from the slicer's "; Z_HEIGHT:" markers. */
83
+ export function layerTops(gcode) {
84
+ const tops = [];
85
+ for (const match of gcode.matchAll(/^; Z_HEIGHT: ([0-9.]+)\s*$/gm))
86
+ tops.push(Number(match[1]));
87
+ return tops;
88
+ }
89
+ /**
90
+ * The 1-based layers whose block holds a pause: the slicer's "; PAUSE_PRINTING"
91
+ * marker or the machine's pause G-code on its own line.
92
+ */
93
+ export function pausedLayers(gcode, pauseGcode = "M400 U1") {
94
+ const lines = gcode.split(/\r?\n/);
95
+ const paused = new Set();
96
+ let layer = 0;
97
+ const pauseLine = pauseGcode.trim();
98
+ for (const line of lines) {
99
+ if (line.startsWith("; Z_HEIGHT:")) {
100
+ layer += 1;
101
+ continue;
102
+ }
103
+ if (layer === 0)
104
+ continue;
105
+ const trimmed = line.trim();
106
+ if (trimmed === "; PAUSE_PRINTING" || (pauseLine && trimmed === pauseLine))
107
+ paused.add(layer);
108
+ }
109
+ return [...paused].sort((a, b) => a - b);
110
+ }
111
+ /** The machine_pause_gcode a sliced file was made with (its config block), else Bambu's M400 U1. */
112
+ export function machinePauseGcode(gcode) {
113
+ const match = /^; machine_pause_gcode = (.*)$/m.exec(gcode);
114
+ const value = match?.[1]?.split("\\n")[0]?.trim();
115
+ return value || "M400 U1";
116
+ }
117
+ /** Project custom G-codes plus a pause before each requested layer, at that layer's exact top. */
118
+ export function customGcodesWithPauses(tops, layers, project) {
119
+ const total = tops.length;
120
+ const beyond = layers.filter(layer => layer > total);
121
+ if (beyond.length) {
122
+ throw new Error(`This print has ${total} layers, so it cannot pause before layer ${beyond.join(", ")}.`);
123
+ }
124
+ const pauses = layers.map(layer => ({ type: "PausePrint", print_z: tops[layer - 1], color: "", extruder: 1, extra: "" }));
125
+ const kept = (project?.gcodes ?? []).filter(item => !(item.type === "PausePrint" && pauses.some(p => Math.abs(p.print_z - item.print_z) < 1e-4)));
126
+ return {
127
+ mode: project?.mode || "SingleExtruder",
128
+ gcodes: [...kept, ...pauses].sort((a, b) => a.print_z - b.print_z),
129
+ };
130
+ }
@@ -51,6 +51,8 @@ export interface BambuSliceOptions {
51
51
  skipModifiedGcodes?: boolean;
52
52
  slicePlate?: number;
53
53
  processOverrides?: ProcessOverrides;
54
+ pauseAtLayers?: number[];
55
+ customGcodesFile?: string;
54
56
  }
55
57
  /** Bambu Studio's or OrcaSlicer's own result.json, parsed verbatim. */
56
58
  export type SlicerResult = Record<string, unknown>;
@@ -194,6 +196,7 @@ export declare class STLManipulator extends EventEmitter {
194
196
  * error_string and plate warnings.
195
197
  */
196
198
  sliceSTLWithResult(stlFilePath: string, slicerType: SlicerType, slicerPath: string, slicerProfile?: string, progressCallback?: ProgressCallback, printerPreset?: string, bambuOptions?: BambuSliceOptions): Promise<SliceOutput>;
199
+ private sliceSTLOnce;
197
200
  /**
198
201
  * Enhanced version of confirmTemperatures with better error handling
199
202
  * @param gcodePath Path to the G-code file
@@ -1,3 +1,4 @@
1
+ import { customGcodesWithPauses, layerTops, machinePauseGcode, pausedLayers, readPlateGcode, readProjectCustomGcodes } from "../slicer/layer-pauses.js";
1
2
  import * as THREE from 'three';
2
3
  import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
3
4
  import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js';
@@ -1345,6 +1346,48 @@ export class STLManipulator extends EventEmitter {
1345
1346
  * error_string and plate warnings.
1346
1347
  */
1347
1348
  async sliceSTLWithResult(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, bambuOptions) {
1349
+ const once = (options) => this.sliceSTLOnce(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, options);
1350
+ const layers = bambuOptions?.pauseAtLayers?.length ? bambuOptions.pauseAtLayers : undefined;
1351
+ const cli = slicerType === 'bambustudio' || slicerType === 'orcaslicer' || slicerType === 'orcaslicer-bambulab';
1352
+ const plate = bambuOptions?.slicePlate && bambuOptions.slicePlate > 0 ? bambuOptions.slicePlate : 1;
1353
+ // The CLI drops a project's own pauses and colour changes; carry them over.
1354
+ const project = cli && /\.3mf$/i.test(stlFilePath) ? await readProjectCustomGcodes(stlFilePath, plate) : undefined;
1355
+ if (!layers && !project?.gcodes.length)
1356
+ return once(bambuOptions);
1357
+ if (layers && !cli) {
1358
+ throw new Error(`Pausing at a layer needs the Bambu Studio or OrcaSlicer CLI, not ${slicerType}.`);
1359
+ }
1360
+ const customGcodesFile = path.join(this.tempDir, `custom-gcodes-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
1361
+ try {
1362
+ let tops = [];
1363
+ if (layers) {
1364
+ // A pause sits at its layer's exact top Z; learn the tops from a slice without pauses.
1365
+ if (progressCallback)
1366
+ progressCallback(10, `Finding layer heights for the pause before layer ${layers.join(", ")}`);
1367
+ const plain = await once({ ...bambuOptions, pauseAtLayers: undefined, customGcodesFile: undefined });
1368
+ const gcode = await readPlateGcode(plain.path, plate);
1369
+ if (!gcode)
1370
+ throw new Error('The slicer wrote no plate G-code, so the pause layers cannot be placed.');
1371
+ tops = layerTops(gcode);
1372
+ }
1373
+ const info = layers ? customGcodesWithPauses(tops, layers, project) : project;
1374
+ await fs.promises.writeFile(customGcodesFile, JSON.stringify(info));
1375
+ const result = await once({ ...bambuOptions, customGcodesFile });
1376
+ if (layers) {
1377
+ const gcode = await readPlateGcode(result.path, plate);
1378
+ const placed = gcode ? pausedLayers(gcode, machinePauseGcode(gcode)) : [];
1379
+ const missing = layers.filter(layer => !placed.includes(layer));
1380
+ if (!gcode || missing.length || layerTops(gcode).length !== tops.length) {
1381
+ throw new Error(`The slicer did not place the pause before layer ${(missing.length ? missing : layers).join(", ")}. Nothing was sent to the printer.`);
1382
+ }
1383
+ }
1384
+ return result;
1385
+ }
1386
+ finally {
1387
+ await fs.promises.rm(customGcodesFile, { force: true });
1388
+ }
1389
+ }
1390
+ async sliceSTLOnce(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, bambuOptions) {
1348
1391
  const operationId = this.generateOperationId();
1349
1392
  this.activeOperations.set(operationId, true);
1350
1393
  if (slicerType !== 'orca-slicer-api' && isPathLikeExecutable(slicerPath) && !fs.existsSync(slicerPath)) {
@@ -1493,8 +1536,8 @@ export class STLManipulator extends EventEmitter {
1493
1536
  throw new Error("OrcaSlicer's CLI crashes when scale above 1, rotate_x or rotate_y moves a 3MF object below the bed while arranging. " +
1494
1537
  "Set arrange to false, or apply the transform in the slicer and export the project.");
1495
1538
  }
1496
- if (orcaCli && !is3mf && bambuOptions?.repetitions !== undefined && bambuOptions.cloneObjects) {
1497
- throw new Error("Use either repetitions or clone_objects for an STL with OrcaSlicer, not both.");
1539
+ if (!is3mf && bambuOptions?.repetitions !== undefined && bambuOptions.cloneObjects) {
1540
+ throw new Error("Use either repetitions or clone_objects for an STL, not both.");
1498
1541
  }
1499
1542
  const inputPath = meshTransform ? await this.transformMeshForCli(stlFilePath, bambuOptions) : stlFilePath;
1500
1543
  if (inputPath !== stlFilePath)
@@ -1534,8 +1577,9 @@ export class STLManipulator extends EventEmitter {
1534
1577
  if (bambuOptions?.arrange !== undefined)
1535
1578
  args.push('--arrange', bambuOptions.arrange ? '1' : '0');
1536
1579
  if (bambuOptions?.repetitions !== undefined) {
1537
- // OrcaSlicer counts copies of a single loaded STL with --clone-objects.
1538
- if (orcaCli && !is3mf)
1580
+ // Both Bambu Studio and Orca count STL copies with --clone-objects.
1581
+ // --repetitions > 1 requires a selected existing plate and rejects --slice 0.
1582
+ if (!is3mf)
1539
1583
  args.push('--clone-objects', String(bambuOptions.repetitions));
1540
1584
  else
1541
1585
  args.push('--repetitions', String(bambuOptions.repetitions));
@@ -1560,6 +1604,8 @@ export class STLManipulator extends EventEmitter {
1560
1604
  }
1561
1605
  if (bambuOptions?.loadFilamentIds)
1562
1606
  args.push('--load-filament-ids', bambuOptions.loadFilamentIds);
1607
+ if (bambuOptions?.customGcodesFile)
1608
+ args.push('--load-custom-gcodes', path.resolve(bambuOptions.customGcodesFile));
1563
1609
  args.push(path.resolve(inputPath));
1564
1610
  // Override outputFilePath for bambustudio since it produces 3MF, not gcode
1565
1611
  outputFilePath = bambuOutputPath;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * MCP tool annotations (spec 2025-03-26 and later), one entry per tool, chosen from
3
+ * what the tool's handler actually does. Clients and Counterpart's remote endpoint
4
+ * read them to decide which tools a device may call, so every listed tool must have
5
+ * one (tests/tool-annotations.test.mjs).
6
+ *
7
+ * readOnlyHint: changes nothing outside this server (printer, files, other apps).
8
+ * destructiveHint: may delete, overwrite, end or irreversibly change something.
9
+ * idempotentHint: repeating the call with the same arguments has no further effect.
10
+ * openWorldHint: reaches something outside this server and its files: the printer,
11
+ * Bambu Cloud, a remote slicer, or another application (Blender, Fusion, Bambu Connect).
12
+ */
13
+ export interface ToolAnnotations {
14
+ readOnlyHint: boolean;
15
+ destructiveHint: boolean;
16
+ idempotentHint: boolean;
17
+ openWorldHint: boolean;
18
+ }
19
+ export declare const TOOL_ANNOTATIONS: Record<string, ToolAnnotations>;
20
+ /** The tool with its annotations. */
21
+ export declare function withAnnotations<T extends {
22
+ name: string;
23
+ }>(tool: T): T & {
24
+ annotations: ToolAnnotations;
25
+ };
@@ -0,0 +1,96 @@
1
+ const hints = (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) => ({ readOnlyHint, destructiveHint, idempotentHint, openWorldHint });
2
+ /** Reads the printer or another outside system; changes nothing. */
3
+ const READ_OUTSIDE = hints(true, false, true, true);
4
+ /** Reads local files or this server's configuration only. */
5
+ const READ_LOCAL = hints(true, false, true, false);
6
+ /** Writes a fixed-name output into this server's temporary directory, replacing an earlier output of that name; inputs untouched. */
7
+ const LOCAL_OUTPUT = hints(false, true, true, false);
8
+ /** Sets a printer setting to a given value; setting it again changes nothing. */
9
+ const SET_PRINTER = hints(false, false, true, true);
10
+ /** Starts a print job: adds a job, removes nothing, but a repeat would start another. */
11
+ const START_PRINT = hints(false, false, false, true);
12
+ /** Starts a print, auto-slicing an unsliced project first, which replaces an earlier slice output of that name. */
13
+ const SLICE_AND_PRINT = hints(false, true, false, true);
14
+ export const TOOL_ANNOTATIONS = {
15
+ // Printer and cloud reads
16
+ get_printer_status: READ_OUTSIDE,
17
+ get_printer_filaments: READ_OUTSIDE,
18
+ resolve_3mf_ams_slots: READ_OUTSIDE, // reads the live AMS inventory
19
+ list_printer_files: READ_OUTSIDE,
20
+ counterpart_print_progress: READ_OUTSIDE,
21
+ // connect: true starts the bridge agent, which writes its configuration and device identity and can replace certificates.
22
+ bambu_network_bridge_status: hints(false, true, true, true),
23
+ camera_frame: READ_OUTSIDE,
24
+ // Open (or renew) and close the one camera connection all viewers of this printer share; no printer motion or commands.
25
+ camera_stream_start: hints(false, false, true, true),
26
+ camera_stream_stop: hints(false, false, true, true),
27
+ // Writes save_path, overwriting an existing file there; every call takes a new frame.
28
+ camera_snapshot: hints(false, true, false, true),
29
+ // Local reads
30
+ inspect_print_file: READ_LOCAL,
31
+ list_3mf_plate_objects: READ_LOCAL,
32
+ get_stl_info: READ_LOCAL,
33
+ list_templates: READ_LOCAL,
34
+ get_slice_settings: LOCAL_OUTPUT, // a 3MF's settings are extracted to a fixed file in the temporary directory
35
+ counterpart_printer_info: READ_LOCAL, // configuration and capabilities; sends nothing to the printer
36
+ // Local outputs in the server's temporary directory
37
+ extend_stl_base: LOCAL_OUTPUT,
38
+ scale_stl: LOCAL_OUTPUT,
39
+ rotate_stl: LOCAL_OUTPUT,
40
+ merge_vertices: LOCAL_OUTPUT,
41
+ center_model: LOCAL_OUTPUT,
42
+ lay_flat: LOCAL_OUTPUT,
43
+ // Same, but a configured orca-slicer-api slices on a remote service, a new job and output each call.
44
+ slice_stl: hints(false, true, false, true),
45
+ slice_with_template: hints(false, true, false, true),
46
+ // New 3MF at a caller-chosen path; never overwrites, so a repeat fails and changes nothing.
47
+ counterpart_make_3mf: hints(false, false, true, false),
48
+ // Copies into the template registry, replacing a template of the same name.
49
+ save_template: hints(false, true, true, false),
50
+ // Replaces BAMBU_DEFAULT_CONNECTION_MODE/TYPE in .env and in this process.
51
+ counterpart_print_route: hints(false, true, true, false),
52
+ // Print starts
53
+ start_print: START_PRINT,
54
+ start_print_job: START_PRINT,
55
+ print_3mf: SLICE_AND_PRINT,
56
+ print_3mf_bambu_network: SLICE_AND_PRINT,
57
+ print_collar_charm: SLICE_AND_PRINT,
58
+ upload_file: START_PRINT, // print: true starts the uploaded G-code; uploads never overwrite (unique names)
59
+ upload_gcode: hints(false, false, false, true), // a uniquely named new copy per call
60
+ // Print controls
61
+ pause_print: SET_PRINTER,
62
+ resume_print: SET_PRINTER,
63
+ cancel_print: hints(false, true, true, true), // ends the job; it cannot be resumed
64
+ skip_objects: hints(false, true, true, true), // skipped objects are not printed and cannot be restored
65
+ // Printer settings
66
+ set_print_speed: SET_PRINTER,
67
+ set_airduct_mode: SET_PRINTER,
68
+ set_temperature: SET_PRINTER,
69
+ set_fan_speed: SET_PRINTER,
70
+ set_light: SET_PRINTER,
71
+ set_ams_drying: SET_PRINTER,
72
+ reread_ams_rfid: hints(false, false, false, true), // moves AMS filament on every call
73
+ // Replaces stored AMS metadata or the calibration selection on an X2D.
74
+ x2d_native_control: hints(false, true, true, true),
75
+ clear_hms_errors: hints(false, true, true, true), // clears the printer's error record
76
+ delete_printer_file: hints(false, true, true, true),
77
+ // Only handshake and sign-in reads are allowed, but with_agent (the default) starts the bridge agent like the status probe.
78
+ bambu_network_call: hints(false, true, true, true),
79
+ // Opens the file in the Bambu Connect app; does not print.
80
+ bambu_connect_import_file: hints(false, false, false, true),
81
+ // Blender and Fusion
82
+ blender_mcp_status: READ_OUTSIDE, // connects and lists tools; edits nothing
83
+ blender_mcp_call: hints(false, true, false, true), // any Blender tool, including execute_blender_code
84
+ // The standard route preserves scene objects and needs a new output path; a configured legacy bridge promises neither.
85
+ blender_mcp_edit_model: hints(false, true, false, true),
86
+ fusion_mcp_status: hints(false, false, true, true), // launch: true starts Fusion on this computer
87
+ fusion_mcp_call: hints(false, true, false, true), // any Fusion tool, including execute_code
88
+ fusion_mcp_new_design: hints(false, false, false, true), // opens another new document
89
+ fusion_mcp_export: hints(false, false, true, true), // never overwrites; a repeat fails and changes nothing
90
+ };
91
+ /** Assumed for a tool missing from the table (a bug the tests catch): the least a client should trust it. */
92
+ const UNKNOWN = hints(false, true, false, true);
93
+ /** The tool with its annotations. */
94
+ export function withAnnotations(tool) {
95
+ return { ...tool, annotations: TOOL_ANNOTATIONS[tool.name] ?? UNKNOWN };
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.51",
3
+ "version": "1.1.53",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -55,6 +55,7 @@
55
55
  "jszip": "^3.10.2",
56
56
  "mqtt": "^5.16.1",
57
57
  "patch-package": "8.0.1",
58
+ "sharp": "0.35.5",
58
59
  "three": "^0.173.0",
59
60
  "xml2js": "^0.6.2"
60
61
  },
@@ -78,3 +78,55 @@ export function bridgeAmsMapping2Entry(value: number, dualNozzle = false): { ams
78
78
  if (value >= 128) return { ams_id: 128, slot_id: value - 128 };
79
79
  return { ams_id: Math.floor(value / 4), slot_id: value % 4 };
80
80
  }
81
+
82
+ /** A project filament as the sliced 3MF's Metadata/project_settings.config declares it. */
83
+ export interface ProjectFilament { type: string; filamentId: string; colour: string; nozzle?: number }
84
+
85
+ /** Read every project filament (not just the plate's used ones) from project_settings.config. */
86
+ export function projectFilaments(projectSettings: Record<string, unknown>): ProjectFilament[] {
87
+ const list = (key: string): string[] => Array.isArray(projectSettings[key]) ? (projectSettings[key] as unknown[]).map(String) : [];
88
+ const types = list("filament_type"), ids = list("filament_ids"), colours = list("filament_colour"), nozzles = list("filament_map");
89
+ return types.map((type, index) => ({
90
+ type, filamentId: ids[index] ?? "", colour: colours[index] ?? "",
91
+ ...(nozzles[index] !== undefined && Number.isInteger(Number(nozzles[index])) ? { nozzle: Number(nozzles[index]) } : {}),
92
+ }));
93
+ }
94
+
95
+ /** The colour the printer reports for an absolute tray value (AMS, AMS-HT or external spool). */
96
+ export function trayColour(rawStatus: any, tray: number): string | undefined {
97
+ const units: any[] = Array.isArray(rawStatus?.ams?.ams) ? rawStatus.ams.ams : [];
98
+ let colour: unknown;
99
+ if (tray === 254 || tray === 255) {
100
+ const slots: any[] = Array.isArray(rawStatus?.vir_slot) ? rawStatus.vir_slot : [];
101
+ colour = slots.find(slot => Number(slot?.id) === tray)?.tray_color ?? (tray === 254 ? rawStatus?.vt_tray?.tray_color : undefined);
102
+ } else if (tray >= 128) {
103
+ colour = units.find(unit => Number(unit?.id) === tray)?.tray?.[0]?.tray_color;
104
+ } else if (tray >= 0) {
105
+ const unit = units.find(candidate => Number(candidate?.id) === Math.floor(tray / 4));
106
+ colour = (Array.isArray(unit?.tray) ? unit.tray : []).find((slot: any) => Number(slot?.id) === tray % 4)?.tray_color;
107
+ }
108
+ return typeof colour === "string" ? colour : undefined;
109
+ }
110
+
111
+ /**
112
+ * PrintParams.ams_mapping_info exactly as Bambu Studio and FULU's slicer build it
113
+ * (SelectMachineDialog::get_ams_mapping_result) and send it with every print: one entry per
114
+ * project filament. A mapped filament names its tray, its filament id and type, its colour as
115
+ * #RRGGBBAA and the tray's colour as the printer reports it; an unmapped one carries ams -1.
116
+ * Filament-map nozzle 1 (left) is cloud nozzle 1 and 2 (right) is 0 (CloudTaskNozzleId).
117
+ */
118
+ export function studioAmsMappingInfo(filaments: ProjectFilament[], mapping: number[], colourOfTray: (tray: number) => string | undefined): Array<Record<string, unknown>> {
119
+ return filaments.map((filament, position) => {
120
+ const tray = mapping[position];
121
+ if (tray === undefined || tray < 0) return { ams: -1, targetColor: "", filamentId: "", filamentType: "" };
122
+ const hex = filament.colour.replace(/^#/, "").toUpperCase();
123
+ return {
124
+ ams: tray,
125
+ targetColor: colourOfTray(tray) ?? "",
126
+ filamentId: filament.filamentId,
127
+ filamentType: filament.type,
128
+ ...(filament.nozzle === 1 ? { nozzleId: 1 } : filament.nozzle === 2 ? { nozzleId: 0 } : {}),
129
+ sourceColor: /^[0-9A-F]{6}$/.test(hex) ? `#${hex}FF` : /^[0-9A-F]{8}$/.test(hex) ? `#${hex}` : "",
130
+ };
131
+ });
132
+ }