bambu-printer-mcp 1.1.58 → 1.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1198,7 +1198,7 @@ When `slicer_type` is `bambustudio` (the default), these additional parameters a
1198
1198
  | `skip_modified_gcodes` | boolean | Ignore stale custom gcodes in the 3MF |
1199
1199
  | `slice_plate` | number | Which plate to slice (0 = all plates, default: 0) |
1200
1200
  | `quality` | string | `draft`, `standard` or `fine`: the server picks the layer height for the nozzle in use (0.28 and 0.12 mm on 0.4 mm; standard keeps the preset) |
1201
- | `strength` | string | `standard`, `strong` or `max`: the server picks walls and infill (4 walls at 25%, 6 at 40%; standard keeps the preset) |
1201
+ | `strength` | string | `standard`, `strong` or `max`: the server picks walls and infill (at least 4 walls and 25%, or 6 and 40%; a process that already has more keeps it; standard keeps the process as it is) |
1202
1202
  | `layer_height` | number | Layer height in mm, such as 0.28, 0.2 or 0.12; at most the nozzle diameter |
1203
1203
  | `wall_loops` | integer | Number of walls, 0 to 1000 |
1204
1204
  | `sparse_infill_density` | string | Sparse infill density, such as `"15%"` |
@@ -1,6 +1,8 @@
1
1
  import { ThreeMFData, CollarCharmAnalysis, ThreeMFAmsRequirements, ThreeMFPlateObjects } from './types.js';
2
2
  export { ThreeMFData };
3
3
  export declare function parse3MF(filePath: string): Promise<ThreeMFData>;
4
+ /** Whether a 3MF carries its own Bambu Studio/Orca process (a designer's project, not a bare mesh archive). */
5
+ export declare function hasBambuProjectSettings(filePath: string): Promise<boolean>;
4
6
  export declare function extractBambuTemplateSettings(filePath: string, outputDir: string): Promise<string>;
5
7
  export declare function analyzeCollarCharm3MF(filePath: string, plateIndex?: number): Promise<CollarCharmAnalysis>;
6
8
  export declare function getCollarCharmRolePolicy(): {
@@ -1,6 +1,7 @@
1
1
  import JSZip from 'jszip';
2
2
  import { parseStringPromise } from 'xml2js';
3
3
  import * as fs from 'fs/promises';
4
+ import { createHash } from 'crypto';
4
5
  // Parses Bambu Studio's JSON config data
5
6
  function parseBambuJSONConfig(jsonData) {
6
7
  const config = {};
@@ -219,6 +220,20 @@ export async function parse3MF(filePath) {
219
220
  throw new Error(`Failed to parse 3MF file: ${error.message}`);
220
221
  }
221
222
  }
223
+ /** Whether a 3MF carries its own Bambu Studio/Orca process (a designer's project, not a bare mesh archive). */
224
+ export async function hasBambuProjectSettings(filePath) {
225
+ try {
226
+ const zip = await JSZip.loadAsync(await fs.readFile(filePath));
227
+ const settings = zip.file('Metadata/project_settings.config');
228
+ if (!settings)
229
+ return false;
230
+ const parsed = JSON.parse(await settings.async('string'));
231
+ return !!parsed && typeof parsed === 'object' && !Array.isArray(parsed) && parsed.layer_height !== undefined;
232
+ }
233
+ catch {
234
+ return false;
235
+ }
236
+ }
222
237
  export async function extractBambuTemplateSettings(filePath, outputDir) {
223
238
  const data = await fs.readFile(filePath);
224
239
  const zip = await JSZip.loadAsync(data);
@@ -233,7 +248,9 @@ export async function extractBambuTemplateSettings(filePath, outputDir) {
233
248
  if (!file)
234
249
  continue;
235
250
  const content = await file.async('string');
236
- const outputPath = `${outputDir}/${name.replace(/\//g, '_')}`;
251
+ // Named by content, so two projects sliced at once never share (or overwrite) one settings file.
252
+ const digest = createHash('sha256').update(content).digest('hex').slice(0, 16);
253
+ const outputPath = `${outputDir}/${digest}_${name.replace(/\//g, '_')}`;
237
254
  await fs.writeFile(outputPath, content, 'utf8');
238
255
  return outputPath;
239
256
  }
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import { importFileViaBambuConnect } from "./bambu-connect.js";
19
19
  import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
20
20
  import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
21
21
  import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
22
- import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
22
+ import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, parse3MF } from './3mf_parser.js';
23
23
  import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
24
24
  import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-options.js";
25
25
  import { inspectPrintFile } from "./safety/print-file.js";
@@ -708,6 +708,20 @@ async function resolveTemplateSlicerProfilePath(templatePath, tempDir) {
708
708
  function hasExplicitSlicerProfile(args) {
709
709
  return typeof args?.slicer_profile === "string" && args.slicer_profile.trim().length > 0;
710
710
  }
711
+ /**
712
+ * A 3MF that carries its own process (a designer's project) as its slicing template, when the call names
713
+ * no profile or template of its own. A configured default profile or template must not replace the
714
+ * designer's layer height, walls and infill; the machine still comes from the chosen printer preset.
715
+ */
716
+ /** The template this call names: template_name (resolved by the caller) or template_3mf_path. */
717
+ function namedTemplatePath(args, fromName) {
718
+ return fromName || (typeof args?.template_3mf_path === "string" && args.template_3mf_path.trim() ? String(args.template_3mf_path) : undefined);
719
+ }
720
+ async function ownProcessTemplate(args, modelPath, requestedTemplatePath) {
721
+ if (hasExplicitSlicerProfile(args) || requestedTemplatePath || !modelPath.toLowerCase().endsWith(".3mf"))
722
+ return undefined;
723
+ return await hasBambuProjectSettings(modelPath) ? modelPath : undefined;
724
+ }
711
725
  async function resolveTemplateFirstSlicerProfilePath(args, configuredProfile, template3mfPath, tempDir) {
712
726
  if (hasExplicitSlicerProfile(args)) {
713
727
  return configuredProfile || undefined;
@@ -1167,7 +1181,9 @@ class BambuPrinterMCPServer {
1167
1181
  nozzleType: resolveNozzleType(args?.nozzle_type),
1168
1182
  nozzleVolumeType: resolveNozzleVolumeType(args?.nozzle_volume_type),
1169
1183
  };
1170
- threeMFPath = await this.stlManipulator.sliceSTL(threeMFPath, slicerType, slicerPath, slicerProfile || undefined, undefined, printPreset, autoSliceOptions);
1184
+ // A designer's project slices with its own process here too, as slice_stl and the LAN route do.
1185
+ const ownProcess = await ownProcessTemplate(args, threeMFPath, namedTemplatePath(args, typeof args?.template_name === "string" && args.template_name.trim() ? String(args.template_name) : undefined));
1186
+ threeMFPath = await this.stlManipulator.sliceSTL(threeMFPath, slicerType, slicerPath, ownProcess ? await resolveTemplateSlicerProfilePath(ownProcess, TEMP_DIR) : slicerProfile || undefined, undefined, printPreset, autoSliceOptions);
1171
1187
  console.error("Auto-sliced to: " + threeMFPath);
1172
1188
  return { threeMFPath, autoSliced: true };
1173
1189
  }
@@ -2079,7 +2095,7 @@ class BambuPrinterMCPServer {
2079
2095
  },
2080
2096
  {
2081
2097
  name: "slice_stl",
2082
- description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer. The text result is the sliced file's path. When Bambu Studio or OrcaSlicer writes a result.json, structuredContent.slicer_result carries it verbatim, success or error: error_string, return_code and each sliced_plates[].warning_message, such as a floating cantilever. A failed slice's text starts with those words.",
2098
+ description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer. The text result is the sliced file's path. When Bambu Studio or OrcaSlicer writes a result.json, structuredContent.slicer_result carries it verbatim, success or error: error_string, return_code and each sliced_plates[].warning_message, such as a floating cantilever. A failed slice's text starts with those words. A 3MF that carries its own process settings (a designer's Bambu Studio or Orca project) slices with them unless slicer_profile, template_name or template_3mf_path is given; the machine still comes from bambu_model. quality and strength adjust that process, and strength never lowers its walls or infill.",
2083
2099
  inputSchema: {
2084
2100
  type: "object",
2085
2101
  properties: {
@@ -3667,8 +3683,12 @@ class BambuPrinterMCPServer {
3667
3683
  }
3668
3684
  const sliceModel = await this.resolveBambuModel(args?.bambu_model);
3669
3685
  const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
3670
- const activeSlicerProfile = await resolveSlicerProfilePath(slicerProfile || undefined, resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined, TEMP_DIR);
3671
3686
  const explicitSlicerProfile = hasExplicitSlicerProfile(args);
3687
+ const requestedTemplatePath = namedTemplatePath(args, resolveTemplatePathFromName(["json", "config", "3mf"]));
3688
+ const ownProcess3mf = await ownProcessTemplate(args, String(args.stl_path), requestedTemplatePath);
3689
+ const activeSlicerProfile = ownProcess3mf
3690
+ ? await resolveSlicerProfilePath(undefined, ownProcess3mf, TEMP_DIR)
3691
+ : await resolveSlicerProfilePath(slicerProfile || undefined, requestedTemplatePath || explicitTemplatePath || undefined, TEMP_DIR);
3672
3692
  // Resolve printer preset for BambuStudio slicer
3673
3693
  const printerPreset = BAMBU_MODEL_PRESETS[sliceModel]?.(nozzleDiam);
3674
3694
  const sliceBambuOptions = {};
@@ -3791,7 +3811,11 @@ class BambuPrinterMCPServer {
3791
3811
  const printBedType = resolveBedType(args?.bed_type);
3792
3812
  const printNozzles = requestedPrintNozzles(args);
3793
3813
  const printNozzle = String(printNozzles?.[0] ?? DEFAULT_NOZZLE_DIAMETER);
3794
- const activeSlicerProfile = await resolveTemplateFirstSlicerProfilePath(args, slicerProfile || undefined, resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined, TEMP_DIR);
3814
+ const requestedPrintTemplate = namedTemplatePath(args, resolveTemplatePathFromName(["json", "config", "3mf"]));
3815
+ const ownPrintProcess = await ownProcessTemplate(args, String(args.three_mf_path), requestedPrintTemplate);
3816
+ const activeSlicerProfile = ownPrintProcess
3817
+ ? await resolveTemplateSlicerProfilePath(ownPrintProcess, TEMP_DIR)
3818
+ : await resolveTemplateFirstSlicerProfilePath(args, slicerProfile || undefined, requestedPrintTemplate || explicitTemplatePath || undefined, TEMP_DIR);
3795
3819
  const explicitSlicerProfile = hasExplicitSlicerProfile(args);
3796
3820
  const printPreset = BAMBU_MODEL_PRESETS[printModel]?.(printNozzle);
3797
3821
  const plateIndex = args?.plate_index !== undefined ? Number(args.plate_index) : 0;
@@ -2,8 +2,10 @@
2
2
  * slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
3
3
  * slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
4
4
  * the layer height for the nozzle in use (0.28 and 0.12 mm on a 0.4 mm nozzle, scaled with it); Strong
5
- * and Max set walls and infill. Standard sends nothing: the resolved preset decides. An explicit
6
- * layer_height, wall_loops or sparse_infill_density in the same call wins over these.
5
+ * and Max raise walls and infill to at least their values: a process that already has more (a
6
+ * designer's 3MF at 100% infill) keeps it, so a stronger choice never prints weaker. Standard sends
7
+ * nothing: the resolved process decides. An explicit layer_height, wall_loops or
8
+ * sparse_infill_density in the same call wins over these and is written as given.
7
9
  */
8
10
  export declare const PRINT_QUALITIES: readonly ["draft", "standard", "fine"];
9
11
  export declare const PRINT_STRENGTHS: readonly ["standard", "strong", "max"];
@@ -21,6 +23,6 @@ export declare const PRINT_QUALITY_PROPERTIES: {
21
23
  readonly strength: {
22
24
  readonly type: "string";
23
25
  readonly enum: readonly ["standard", "strong", "max"];
24
- readonly description: "Part strength: standard (the preset's walls and infill), strong or max (more walls and denser infill). The server picks the values; explicit wall_loops or sparse_infill_density win.";
26
+ readonly description: "Part strength: standard (the process's own walls and infill), strong or max (at least more walls and denser infill; a process that already has more keeps it). The server picks the values; explicit wall_loops or sparse_infill_density win.";
25
27
  };
26
28
  };
@@ -2,8 +2,10 @@
2
2
  * slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
3
3
  * slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
4
4
  * the layer height for the nozzle in use (0.28 and 0.12 mm on a 0.4 mm nozzle, scaled with it); Strong
5
- * and Max set walls and infill. Standard sends nothing: the resolved preset decides. An explicit
6
- * layer_height, wall_loops or sparse_infill_density in the same call wins over these.
5
+ * and Max raise walls and infill to at least their values: a process that already has more (a
6
+ * designer's 3MF at 100% infill) keeps it, so a stronger choice never prints weaker. Standard sends
7
+ * nothing: the resolved process decides. An explicit layer_height, wall_loops or
8
+ * sparse_infill_density in the same call wins over these and is written as given.
7
9
  */
8
10
  export const PRINT_QUALITIES = ["draft", "standard", "fine"];
9
11
  export const PRINT_STRENGTHS = ["standard", "strong", "max"];
@@ -34,9 +36,9 @@ export function withPrintQuality(args, nozzleDiameter) {
34
36
  const walls = STRENGTH[strength];
35
37
  if (walls) {
36
38
  if (out.wall_loops === undefined)
37
- out.wall_loops = walls.wall_loops;
39
+ out.wall_loops_floor = walls.wall_loops;
38
40
  if (out.sparse_infill_density === undefined)
39
- out.sparse_infill_density = walls.sparse_infill_density;
41
+ out.sparse_infill_density_floor = walls.sparse_infill_density;
40
42
  }
41
43
  return out;
42
44
  }
@@ -48,6 +50,6 @@ export const PRINT_QUALITY_PROPERTIES = {
48
50
  },
49
51
  strength: {
50
52
  type: "string", enum: [...PRINT_STRENGTHS],
51
- description: "Part strength: standard (the preset's walls and infill), strong or max (more walls and denser infill). The server picks the values; explicit wall_loops or sparse_infill_density win.",
53
+ description: "Part strength: standard (the process's own walls and infill), strong or max (at least more walls and denser infill; a process that already has more keeps it). The server picks the values; explicit wall_loops or sparse_infill_density win.",
52
54
  },
53
55
  };
@@ -5,7 +5,9 @@
5
5
  * "15%"), so the machine preset and every other process value stay as resolved.
6
6
  */
7
7
  export declare const PROCESS_OVERRIDE_KEYS: readonly ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"];
8
- export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number], string>>;
8
+ /** Minimums from a strength choice: the resolved process keeps its own value when it is already higher. */
9
+ export declare const PROCESS_FLOOR_KEYS: readonly ["wall_loops_floor", "sparse_infill_density_floor"];
10
+ export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number] | (typeof PROCESS_FLOOR_KEYS)[number], string>>;
9
11
  /** Bambu Studio's and OrcaSlicer's support_type values. */
10
12
  export declare const SUPPORT_TYPES: readonly ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"];
11
13
  /** Validate the tool arguments; undefined when none are given. */
@@ -5,6 +5,8 @@
5
5
  * "15%"), so the machine preset and every other process value stay as resolved.
6
6
  */
7
7
  export const PROCESS_OVERRIDE_KEYS = ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"];
8
+ /** Minimums from a strength choice: the resolved process keeps its own value when it is already higher. */
9
+ export const PROCESS_FLOOR_KEYS = ["wall_loops_floor", "sparse_infill_density_floor"];
8
10
  /** Bambu Studio's and OrcaSlicer's support_type values. */
9
11
  export const SUPPORT_TYPES = ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"];
10
12
  /** Validate the tool arguments; undefined when none are given. */
@@ -33,6 +35,11 @@ export function parseProcessOverrides(args, nozzleDiameter) {
33
35
  throw new Error('sparse_infill_density must be a percentage from 0% to 100%, such as "15%".');
34
36
  overrides.sparse_infill_density = `${Number(match[1])}%`;
35
37
  }
38
+ // Written by withPrintQuality for strong/max, never by a caller.
39
+ if (typeof args?.wall_loops_floor === "number")
40
+ overrides.wall_loops_floor = String(args.wall_loops_floor);
41
+ if (typeof args?.sparse_infill_density_floor === "string")
42
+ overrides.sparse_infill_density_floor = args.sparse_infill_density_floor;
36
43
  const enableSupport = args?.enable_support;
37
44
  if (enableSupport !== undefined) {
38
45
  if (typeof enableSupport !== "boolean")
@@ -58,5 +65,15 @@ export function parseProcessOverrides(args, nozzleDiameter) {
58
65
  }
59
66
  /** The process profile with the overrides written over its values. */
60
67
  export function applyProcessOverrides(profile, overrides) {
61
- return { ...profile, ...overrides };
68
+ const { wall_loops_floor: wallFloor, sparse_infill_density_floor: densityFloor, ...exact } = overrides;
69
+ const out = { ...profile };
70
+ const number = (value) => {
71
+ const parsed = Number.parseFloat(String(Array.isArray(value) ? value[0] : value ?? ""));
72
+ return Number.isFinite(parsed) ? parsed : undefined;
73
+ };
74
+ if (wallFloor !== undefined && (number(out.wall_loops) ?? -1) < Number(wallFloor))
75
+ out.wall_loops = wallFloor;
76
+ if (densityFloor !== undefined && (number(out.sparse_infill_density) ?? -1) < Number.parseFloat(densityFloor))
77
+ out.sparse_infill_density = densityFloor;
78
+ return { ...out, ...exact };
62
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.58",
3
+ "version": "1.1.59",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
package/src/3mf_parser.ts CHANGED
@@ -2,6 +2,7 @@ import JSZip from 'jszip';
2
2
  import { parseStringPromise } from 'xml2js';
3
3
  import { ThreeMFData, BambuSlicerConfig, ThreeMFMetadata, ThreeMFObject, ThreeMFBuildItem, AMSFilamentMapping, CollarCharmAnalysis, CollarCharmRole, ThreeMFAmsRequirements, ThreeMFPlateObjects } from './types.js';
4
4
  import * as fs from 'fs/promises';
5
+ import { createHash } from 'crypto';
5
6
 
6
7
  // Parses Bambu Studio's JSON config data
7
8
  function parseBambuJSONConfig(jsonData: any): Partial<BambuSlicerConfig> {
@@ -227,6 +228,19 @@ export async function parse3MF(filePath: string): Promise<ThreeMFData> {
227
228
  }
228
229
  }
229
230
 
231
+ /** Whether a 3MF carries its own Bambu Studio/Orca process (a designer's project, not a bare mesh archive). */
232
+ export async function hasBambuProjectSettings(filePath: string): Promise<boolean> {
233
+ try {
234
+ const zip = await JSZip.loadAsync(await fs.readFile(filePath));
235
+ const settings = zip.file('Metadata/project_settings.config');
236
+ if (!settings) return false;
237
+ const parsed = JSON.parse(await settings.async('string'));
238
+ return !!parsed && typeof parsed === 'object' && !Array.isArray(parsed) && parsed.layer_height !== undefined;
239
+ } catch {
240
+ return false;
241
+ }
242
+ }
243
+
230
244
  export async function extractBambuTemplateSettings(
231
245
  filePath: string,
232
246
  outputDir: string
@@ -245,7 +259,9 @@ export async function extractBambuTemplateSettings(
245
259
  if (!file) continue;
246
260
 
247
261
  const content = await file.async('string');
248
- const outputPath = `${outputDir}/${name.replace(/\//g, '_')}`;
262
+ // Named by content, so two projects sliced at once never share (or overwrite) one settings file.
263
+ const digest = createHash('sha256').update(content).digest('hex').slice(0, 16);
264
+ const outputPath = `${outputDir}/${digest}_${name.replace(/\//g, '_')}`;
249
265
  await fs.writeFile(outputPath, content, 'utf8');
250
266
  return outputPath;
251
267
  }
package/src/index.ts CHANGED
@@ -48,7 +48,7 @@ import { importFileViaBambuConnect } from "./bambu-connect.js";
48
48
  import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
49
49
  import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
50
50
  import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
51
- import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
51
+ import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, parse3MF } from './3mf_parser.js';
52
52
  import type { ThreeMFAmsRequirements } from "./types.js";
53
53
  import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
54
54
  import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "./studio-print-options.js";
@@ -920,6 +920,21 @@ function hasExplicitSlicerProfile(args: any): boolean {
920
920
  return typeof args?.slicer_profile === "string" && args.slicer_profile.trim().length > 0;
921
921
  }
922
922
 
923
+ /**
924
+ * A 3MF that carries its own process (a designer's project) as its slicing template, when the call names
925
+ * no profile or template of its own. A configured default profile or template must not replace the
926
+ * designer's layer height, walls and infill; the machine still comes from the chosen printer preset.
927
+ */
928
+ /** The template this call names: template_name (resolved by the caller) or template_3mf_path. */
929
+ function namedTemplatePath(args: any, fromName: string | undefined): string | undefined {
930
+ return fromName || (typeof args?.template_3mf_path === "string" && args.template_3mf_path.trim() ? String(args.template_3mf_path) : undefined);
931
+ }
932
+
933
+ async function ownProcessTemplate(args: any, modelPath: string, requestedTemplatePath: string | undefined): Promise<string | undefined> {
934
+ if (hasExplicitSlicerProfile(args) || requestedTemplatePath || !modelPath.toLowerCase().endsWith(".3mf")) return undefined;
935
+ return await hasBambuProjectSettings(modelPath) ? modelPath : undefined;
936
+ }
937
+
923
938
  async function resolveTemplateFirstSlicerProfilePath(
924
939
  args: any,
925
940
  configuredProfile: string | undefined,
@@ -1525,8 +1540,10 @@ class BambuPrinterMCPServer {
1525
1540
  nozzleType: resolveNozzleType(args?.nozzle_type),
1526
1541
  nozzleVolumeType: resolveNozzleVolumeType(args?.nozzle_volume_type),
1527
1542
  };
1543
+ // A designer's project slices with its own process here too, as slice_stl and the LAN route do.
1544
+ const ownProcess = await ownProcessTemplate(args, threeMFPath, namedTemplatePath(args, typeof args?.template_name === "string" && args.template_name.trim() ? String(args.template_name) : undefined));
1528
1545
  threeMFPath = await this.stlManipulator.sliceSTL(
1529
- threeMFPath, slicerType, slicerPath, slicerProfile || undefined,
1546
+ threeMFPath, slicerType, slicerPath, ownProcess ? await resolveTemplateSlicerProfilePath(ownProcess, TEMP_DIR) : slicerProfile || undefined,
1530
1547
  undefined,
1531
1548
  printPreset,
1532
1549
  autoSliceOptions
@@ -2613,7 +2630,7 @@ class BambuPrinterMCPServer {
2613
2630
  },
2614
2631
  {
2615
2632
  name: "slice_stl",
2616
- description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer. The text result is the sliced file's path. When Bambu Studio or OrcaSlicer writes a result.json, structuredContent.slicer_result carries it verbatim, success or error: error_string, return_code and each sliced_plates[].warning_message, such as a floating cantilever. A failed slice's text starts with those words.",
2633
+ description: "Slice an STL or 3MF file using a slicer to generate printable G-code or sliced 3MF. IMPORTANT: bambu_model must be specified to ensure the slicer generates safe G-code for the correct printer. The text result is the sliced file's path. When Bambu Studio or OrcaSlicer writes a result.json, structuredContent.slicer_result carries it verbatim, success or error: error_string, return_code and each sliced_plates[].warning_message, such as a floating cantilever. A failed slice's text starts with those words. A 3MF that carries its own process settings (a designer's Bambu Studio or Orca project) slices with them unless slicer_profile, template_name or template_3mf_path is given; the machine still comes from bambu_model. quality and strength adjust that process, and strength never lowers its walls or infill.",
2617
2634
  inputSchema: {
2618
2635
  type: "object",
2619
2636
  properties: {
@@ -4325,12 +4342,16 @@ class BambuPrinterMCPServer {
4325
4342
  }
4326
4343
  const sliceModel = await this.resolveBambuModel(args?.bambu_model as string | undefined);
4327
4344
  const nozzleDiam = String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER);
4328
- const activeSlicerProfile = await resolveSlicerProfilePath(
4329
- slicerProfile || undefined,
4330
- resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined,
4331
- TEMP_DIR
4332
- );
4333
4345
  const explicitSlicerProfile = hasExplicitSlicerProfile(args);
4346
+ const requestedTemplatePath = namedTemplatePath(args, resolveTemplatePathFromName(["json", "config", "3mf"]));
4347
+ const ownProcess3mf = await ownProcessTemplate(args, String(args.stl_path), requestedTemplatePath);
4348
+ const activeSlicerProfile = ownProcess3mf
4349
+ ? await resolveSlicerProfilePath(undefined, ownProcess3mf, TEMP_DIR)
4350
+ : await resolveSlicerProfilePath(
4351
+ slicerProfile || undefined,
4352
+ requestedTemplatePath || explicitTemplatePath || undefined,
4353
+ TEMP_DIR
4354
+ );
4334
4355
  // Resolve printer preset for BambuStudio slicer
4335
4356
  const printerPreset = BAMBU_MODEL_PRESETS[sliceModel]?.(nozzleDiam);
4336
4357
 
@@ -4454,12 +4475,16 @@ class BambuPrinterMCPServer {
4454
4475
  const printBedType = resolveBedType(args?.bed_type as string | undefined);
4455
4476
  const printNozzles = requestedPrintNozzles(args as Record<string, any>);
4456
4477
  const printNozzle = String(printNozzles?.[0] ?? DEFAULT_NOZZLE_DIAMETER);
4457
- const activeSlicerProfile = await resolveTemplateFirstSlicerProfilePath(
4458
- args,
4459
- slicerProfile || undefined,
4460
- resolveTemplatePathFromName(["json", "config", "3mf"]) || explicitTemplatePath || undefined,
4461
- TEMP_DIR
4462
- );
4478
+ const requestedPrintTemplate = namedTemplatePath(args, resolveTemplatePathFromName(["json", "config", "3mf"]));
4479
+ const ownPrintProcess = await ownProcessTemplate(args, String(args.three_mf_path), requestedPrintTemplate);
4480
+ const activeSlicerProfile = ownPrintProcess
4481
+ ? await resolveTemplateSlicerProfilePath(ownPrintProcess, TEMP_DIR)
4482
+ : await resolveTemplateFirstSlicerProfilePath(
4483
+ args,
4484
+ slicerProfile || undefined,
4485
+ requestedPrintTemplate || explicitTemplatePath || undefined,
4486
+ TEMP_DIR
4487
+ );
4463
4488
  const explicitSlicerProfile = hasExplicitSlicerProfile(args);
4464
4489
  const printPreset = BAMBU_MODEL_PRESETS[printModel]?.(printNozzle);
4465
4490
  const plateIndex = args?.plate_index !== undefined ? Number(args.plate_index) : 0;
@@ -2,8 +2,10 @@
2
2
  * slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
3
3
  * slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
4
4
  * the layer height for the nozzle in use (0.28 and 0.12 mm on a 0.4 mm nozzle, scaled with it); Strong
5
- * and Max set walls and infill. Standard sends nothing: the resolved preset decides. An explicit
6
- * layer_height, wall_loops or sparse_infill_density in the same call wins over these.
5
+ * and Max raise walls and infill to at least their values: a process that already has more (a
6
+ * designer's 3MF at 100% infill) keeps it, so a stronger choice never prints weaker. Standard sends
7
+ * nothing: the resolved process decides. An explicit layer_height, wall_loops or
8
+ * sparse_infill_density in the same call wins over these and is written as given.
7
9
  */
8
10
  export const PRINT_QUALITIES = ["draft", "standard", "fine"] as const;
9
11
  export const PRINT_STRENGTHS = ["standard", "strong", "max"] as const;
@@ -36,8 +38,8 @@ export function withPrintQuality(args: Record<string, unknown>, nozzleDiameter?:
36
38
  if (layer !== undefined && out.layer_height === undefined) out.layer_height = Math.round(layer * scale * 100) / 100;
37
39
  const walls = STRENGTH[strength as PrintStrength];
38
40
  if (walls) {
39
- if (out.wall_loops === undefined) out.wall_loops = walls.wall_loops;
40
- if (out.sparse_infill_density === undefined) out.sparse_infill_density = walls.sparse_infill_density;
41
+ if (out.wall_loops === undefined) out.wall_loops_floor = walls.wall_loops;
42
+ if (out.sparse_infill_density === undefined) out.sparse_infill_density_floor = walls.sparse_infill_density;
41
43
  }
42
44
  return out;
43
45
  }
@@ -50,6 +52,6 @@ export const PRINT_QUALITY_PROPERTIES = {
50
52
  },
51
53
  strength: {
52
54
  type: "string", enum: [...PRINT_STRENGTHS],
53
- description: "Part strength: standard (the preset's walls and infill), strong or max (more walls and denser infill). The server picks the values; explicit wall_loops or sparse_infill_density win.",
55
+ description: "Part strength: standard (the process's own walls and infill), strong or max (at least more walls and denser infill; a process that already has more keeps it). The server picks the values; explicit wall_loops or sparse_infill_density win.",
54
56
  },
55
57
  } as const;
@@ -6,7 +6,10 @@
6
6
  */
7
7
  export const PROCESS_OVERRIDE_KEYS = ["layer_height", "wall_loops", "sparse_infill_density", "enable_support", "support_type", "support_threshold_angle"] as const;
8
8
 
9
- export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number], string>>;
9
+ /** Minimums from a strength choice: the resolved process keeps its own value when it is already higher. */
10
+ export const PROCESS_FLOOR_KEYS = ["wall_loops_floor", "sparse_infill_density_floor"] as const;
11
+
12
+ export type ProcessOverrides = Partial<Record<(typeof PROCESS_OVERRIDE_KEYS)[number] | (typeof PROCESS_FLOOR_KEYS)[number], string>>;
10
13
 
11
14
  /** Bambu Studio's and OrcaSlicer's support_type values. */
12
15
  export const SUPPORT_TYPES = ["normal(auto)", "tree(auto)", "normal(manual)", "tree(manual)"] as const;
@@ -36,6 +39,9 @@ export function parseProcessOverrides(args: Record<string, unknown> | undefined,
36
39
  if (!match || Number(match[1]) > 100) throw new Error('sparse_infill_density must be a percentage from 0% to 100%, such as "15%".');
37
40
  overrides.sparse_infill_density = `${Number(match[1])}%`;
38
41
  }
42
+ // Written by withPrintQuality for strong/max, never by a caller.
43
+ if (typeof args?.wall_loops_floor === "number") overrides.wall_loops_floor = String(args.wall_loops_floor);
44
+ if (typeof args?.sparse_infill_density_floor === "string") overrides.sparse_infill_density_floor = args.sparse_infill_density_floor;
39
45
  const enableSupport = args?.enable_support;
40
46
  if (enableSupport !== undefined) {
41
47
  if (typeof enableSupport !== "boolean") throw new Error("enable_support must be true or false.");
@@ -61,5 +67,13 @@ export function parseProcessOverrides(args: Record<string, unknown> | undefined,
61
67
 
62
68
  /** The process profile with the overrides written over its values. */
63
69
  export function applyProcessOverrides(profile: Record<string, unknown>, overrides: ProcessOverrides): Record<string, unknown> {
64
- return { ...profile, ...overrides };
70
+ const { wall_loops_floor: wallFloor, sparse_infill_density_floor: densityFloor, ...exact } = overrides;
71
+ const out: Record<string, unknown> = { ...profile };
72
+ const number = (value: unknown) => {
73
+ const parsed = Number.parseFloat(String(Array.isArray(value) ? value[0] : value ?? ""));
74
+ return Number.isFinite(parsed) ? parsed : undefined;
75
+ };
76
+ if (wallFloor !== undefined && (number(out.wall_loops) ?? -1) < Number(wallFloor)) out.wall_loops = wallFloor;
77
+ if (densityFloor !== undefined && (number(out.sparse_infill_density) ?? -1) < Number.parseFloat(densityFloor)) out.sparse_infill_density = densityFloor;
78
+ return { ...out, ...exact };
65
79
  }