bambu-printer-mcp 1.1.55 → 1.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.js +5 -1
- package/dist/printers/bambu.js +2 -1
- package/dist/refusal.d.ts +15 -0
- package/dist/refusal.js +17 -0
- package/dist/safety/printer-state.js +2 -1
- package/dist/slicer/print-quality.d.ts +26 -0
- package/dist/slicer/print-quality.js +53 -0
- package/package.json +1 -1
- package/src/index.ts +7 -1
- package/src/printers/bambu.ts +2 -1
- package/src/refusal.ts +18 -0
- package/src/safety/printer-state.ts +2 -1
- package/src/slicer/print-quality.ts +55 -0
package/README.md
CHANGED
|
@@ -1075,7 +1075,7 @@ If the project does not match those assumptions, the tool fails fast with a stru
|
|
|
1075
1075
|
|
|
1076
1076
|
#### Counterpart tools (`counterpart/1`)
|
|
1077
1077
|
|
|
1078
|
-
[Counterpart](https://github.com/DMontgomery40/scan-to-make) (Scan to Make) reads printers through a small contract that this server and [mcp-3D-printer-server](https://github.com/DMontgomery40/mcp-3D-printer-server) share. Each tool declares an `outputSchema` and returns `structuredContent`, plus the same JSON as text for older clients. An error is returned as text only, because MCP clients check `structuredContent` against the schema even on errors. `counterpart_printer_info` and `counterpart_print_progress` take the usual optional `host`, `bambu_serial`, `bambu_token` and `bambu_model` (default `BAMBU_MODEL`) arguments.
|
|
1078
|
+
[Counterpart](https://github.com/DMontgomery40/scan-to-make) (Scan to Make) reads printers through a small contract that this server and [mcp-3D-printer-server](https://github.com/DMontgomery40/mcp-3D-printer-server) share. Each tool declares an `outputSchema` and returns `structuredContent`, plus the same JSON as text for older clients. An error is returned as text only, because MCP clients check `structuredContent` against the schema even on errors. Other tools return an error's details in `structuredContent` (`status`, `retryable`, `suggestion`, `message`). When the printer refuses a print, it also carries a stable `code`, either `printer-command-rejected` or `printer-not-ready`, so a client can act on the code rather than the wording. `counterpart_printer_info` and `counterpart_print_progress` take the usual optional `host`, `bambu_serial`, `bambu_token` and `bambu_model` (default `BAMBU_MODEL`) arguments.
|
|
1079
1079
|
|
|
1080
1080
|
- **`counterpart_printer_info`** returns `{contract, server: {name, version}, printer: {kind: "bambu", model, serial, host}, capabilities}`. `capabilities` lists progress, layers, the camera transport (`bambu-tcp` for A1/P1, `rtsp` for X1, P2S, H2 and X2D, `none` without a model), `cameraStream: true` for supported camera models, `filaments: "ams"`, pause, resume, cancel, `print3mf` and `gcode` (false on X2D). It sends nothing to the printer and never returns the access code.
|
|
1081
1081
|
- **`counterpart_print_route`** reads or changes how prints and Stop/Pause/Resume reach the printer: `{route, mode, type, choices, savedTo}`, where `route` is `lan` (the local network, in the configured `BAMBU_DEFAULT_CONNECTION_MODE`) or `cloud` (Bambu Cloud through the [FULU bridge](docs/FULU.md)). Pass `route` to change it; the next print and control use it at once, and it is written to the `.env` in the server's working directory when one exists (`savedTo`, otherwise `null`). It is not part of the shared contract: it has no `outputSchema`, and mcp-3D-printer-server has no Bambu Cloud route.
|
|
@@ -1197,6 +1197,8 @@ When `slicer_type` is `bambustudio` (the default), these additional parameters a
|
|
|
1197
1197
|
| `min_save` | boolean | Produce smaller output 3MF (faster uploads) |
|
|
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
|
+
| `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) |
|
|
1200
1202
|
| `layer_height` | number | Layer height in mm, such as 0.28, 0.2 or 0.12; at most the nozzle diameter |
|
|
1201
1203
|
| `wall_loops` | integer | Number of walls, 0 to 1000 |
|
|
1202
1204
|
| `sparse_infill_density` | string | Sparse infill density, such as `"15%"` |
|
|
@@ -1204,7 +1206,7 @@ When `slicer_type` is `bambustudio` (the default), these additional parameters a
|
|
|
1204
1206
|
| `support_type` | string | `normal(auto)`, `tree(auto)`, `normal(manual)` or `tree(manual)` |
|
|
1205
1207
|
| `support_threshold_angle` | integer | Overhang threshold for automatic supports, 0 to 90 degrees (0 lets the slicer decide) |
|
|
1206
1208
|
|
|
1207
|
-
`layer_height`, `wall_loops`, `sparse_infill_density` and the three support arguments are written as a process override on top of the machine and process preset the tool resolves, using Bambu Studio's keys and string forms (`"0.2"`, `"2"`, `"15%"`). Every other preset value, and the machine preset, stay as resolved, and your own profile files are not changed. They work with every Bambu-compatible slicer, including remote `orca-slicer-api` slicing, and are refused for PrusaSlicer, Slic3r and Cura.
|
|
1209
|
+
`quality` and `strength` let a client send the person's choice without slicer numbers; an explicit `layer_height`, `wall_loops` or `sparse_infill_density` wins over them. `layer_height`, `wall_loops`, `sparse_infill_density` and the three support arguments are written as a process override on top of the machine and process preset the tool resolves, using Bambu Studio's keys and string forms (`"0.2"`, `"2"`, `"15%"`). Every other preset value, and the machine preset, stay as resolved, and your own profile files are not changed. They work with every Bambu-compatible slicer, including remote `orca-slicer-api` slicing, and are refused for PrusaSlicer, Slic3r and Cura.
|
|
1208
1210
|
|
|
1209
1211
|
**Example: Slice with auto-orient and 3 copies**
|
|
1210
1212
|
```json
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
|
33
33
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
34
34
|
import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
|
|
35
35
|
import { parseProcessOverrides } from "./slicer/process-overrides.js";
|
|
36
|
+
import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
|
|
37
|
+
import { PrinterRefusal } from "./refusal.js";
|
|
36
38
|
import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
|
|
37
39
|
dotenv.config();
|
|
38
40
|
const DEFAULT_HOST = process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST || "localhost";
|
|
@@ -2135,6 +2137,7 @@ class BambuPrinterMCPServer {
|
|
|
2135
2137
|
skip_modified_gcodes: { type: "boolean", description: "Strip custom start/end gcodes embedded in the 3MF. Recommended for downloaded 3MFs since custom gcodes from other users' profiles may be unsafe for your printer." },
|
|
2136
2138
|
pause_at_layers: { type: "array", items: { type: "integer", minimum: 2 }, description: "Pause before each of these layers (1-based, as Bambu Studio and OrcaSlicer number them in the preview), for example to drop in magnets or nuts. The slicer writes the printer's own pause G-code there (M400 U1 on Bambu printers); the printer stops by itself and waits for Resume. Bambu Studio or OrcaSlicer CLI only. Pauses already in a project 3MF are kept." },
|
|
2137
2139
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates for local slicers; remote slicing defaults to plate 1 and rejects 0. Use 1, 2, etc. to slice only a specific plate in multi-plate 3MF projects." },
|
|
2140
|
+
...PRINT_QUALITY_PROPERTIES,
|
|
2138
2141
|
layer_height: { type: "number", exclusiveMinimum: 0, description: "Layer height in mm, such as 0.28 (draft), 0.2 (standard) or 0.12 (fine). Written as the process preset's layer_height over the machine and process preset this tool resolves; at most the nozzle diameter. Bambu-compatible slicers only." },
|
|
2139
2142
|
wall_loops: { type: "integer", minimum: 0, maximum: 1000, description: "Number of walls (perimeters), written as the process preset's wall_loops. Bambu-compatible slicers only." },
|
|
2140
2143
|
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." },
|
|
@@ -3719,7 +3722,7 @@ class BambuPrinterMCPServer {
|
|
|
3719
3722
|
if (pauses)
|
|
3720
3723
|
sliceBambuOptions.pauseAtLayers = pauses;
|
|
3721
3724
|
}
|
|
3722
|
-
const processOverrides = parseProcessOverrides(args, Number(nozzleDiam));
|
|
3725
|
+
const processOverrides = parseProcessOverrides(withPrintQuality(args, Number(nozzleDiam)), Number(nozzleDiam));
|
|
3723
3726
|
if (processOverrides)
|
|
3724
3727
|
sliceBambuOptions.processOverrides = processOverrides;
|
|
3725
3728
|
if (sliceBambuOptions.loadFilamentIds && String(args.stl_path).toLowerCase().endsWith(".3mf")) {
|
|
@@ -4096,6 +4099,7 @@ class BambuPrinterMCPServer {
|
|
|
4096
4099
|
: `Check parameters and try again. Error: ${message}`,
|
|
4097
4100
|
message,
|
|
4098
4101
|
tool: name,
|
|
4102
|
+
...(error instanceof PrinterRefusal ? { code: error.code } : {}),
|
|
4099
4103
|
// The slicer's own result.json; the message starts with its error_string and warnings.
|
|
4100
4104
|
...(error instanceof SlicerRunError && error.slicerResult ? { slicer_result: error.slicerResult } : {}),
|
|
4101
4105
|
};
|
package/dist/printers/bambu.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrinterRefusal } from "../refusal.js";
|
|
1
2
|
import { CameraStreams } from "./camera-stream.js";
|
|
2
3
|
import { openTcpCameraSource, openRtspCameraSource } from "./camera-sources.js";
|
|
3
4
|
import { cameraNumber } from "./camera-tools.js";
|
|
@@ -1881,7 +1882,7 @@ export class BambuImplementation {
|
|
|
1881
1882
|
if (verdict === "rejected") {
|
|
1882
1883
|
// Nothing started, so there is no checked job to resume or clear later.
|
|
1883
1884
|
this.checkedJobs.delete(`${host}\n${serial}`);
|
|
1884
|
-
throw new
|
|
1885
|
+
throw new PrinterRefusal("printer-command-rejected", COMMAND_REJECTED_MESSAGE);
|
|
1885
1886
|
}
|
|
1886
1887
|
if (verdict === "cancelled" || cancelled())
|
|
1887
1888
|
throw new Error(DISPATCH_CANCELLED_MESSAGE);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
|
|
3
|
+
* such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
|
|
4
|
+
* firmware details change with the printer). Neither one starts a print.
|
|
5
|
+
*
|
|
6
|
+
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
|
+
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
|
+
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
*/
|
|
10
|
+
export declare const REFUSAL_CODES: readonly ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
|
+
export declare class PrinterRefusal extends Error {
|
|
13
|
+
readonly code: RefusalCode;
|
|
14
|
+
constructor(code: RefusalCode, message: string);
|
|
15
|
+
}
|
package/dist/refusal.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
|
|
3
|
+
* such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
|
|
4
|
+
* firmware details change with the printer). Neither one starts a print.
|
|
5
|
+
*
|
|
6
|
+
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
|
+
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
|
+
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
*/
|
|
10
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export class PrinterRefusal extends Error {
|
|
12
|
+
constructor(code, message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = "PrinterRefusal";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrinterRefusal } from "../refusal.js";
|
|
1
2
|
import { HIDDEN_HMS } from "./hidden-hms.js";
|
|
2
3
|
import { GetVersionCommand, PushAllCommand } from "bambu-node";
|
|
3
4
|
import { isDualNozzleModel, normalizeMaterial, normalizeModel } from "./limits.js";
|
|
@@ -330,7 +331,7 @@ function validateErrors(raw, requireIdle, serial, model) {
|
|
|
330
331
|
const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
|
|
331
332
|
const terminal = isCancelledX2DJob(raw, model) || isFinishedP1SJob(raw, model);
|
|
332
333
|
if (requireIdle && !["IDLE", "FINISH"].includes(state) && !terminal)
|
|
333
|
-
throw new
|
|
334
|
+
throw new PrinterRefusal("printer-not-ready", `Printer state ${state} is not safely idle.`);
|
|
334
335
|
if (!requireIdle && !["IDLE", "FINISH", "RUNNING", "PAUSE"].includes(state) && !terminal)
|
|
335
336
|
throw new Error(`Printer state ${state} is unknown or failed.`);
|
|
336
337
|
if (finiteNumber(raw.print_error) !== 0 && !isPauseNotice(raw, requireIdle))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
|
|
3
|
+
* slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PRINT_QUALITIES: readonly ["draft", "standard", "fine"];
|
|
9
|
+
export declare const PRINT_STRENGTHS: readonly ["standard", "strong", "max"];
|
|
10
|
+
export type PrintQuality = (typeof PRINT_QUALITIES)[number];
|
|
11
|
+
export type PrintStrength = (typeof PRINT_STRENGTHS)[number];
|
|
12
|
+
/** The call's arguments with `quality` and `strength` written out as slicer settings. */
|
|
13
|
+
export declare function withPrintQuality(args: Record<string, unknown>, nozzleDiameter?: number): Record<string, unknown>;
|
|
14
|
+
/** slice_stl input-schema properties for both arguments. */
|
|
15
|
+
export declare const PRINT_QUALITY_PROPERTIES: {
|
|
16
|
+
readonly quality: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly enum: readonly ["draft", "standard", "fine"];
|
|
19
|
+
readonly description: "Print quality: draft (thicker layers, faster), standard (the preset's own layer height) or fine (thinner layers). The server picks the layer height for the nozzle in use; an explicit layer_height wins.";
|
|
20
|
+
};
|
|
21
|
+
readonly strength: {
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
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.";
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
|
|
3
|
+
* slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export const PRINT_QUALITIES = ["draft", "standard", "fine"];
|
|
9
|
+
export const PRINT_STRENGTHS = ["standard", "strong", "max"];
|
|
10
|
+
/** Layer heights on the reference 0.4 mm nozzle; other nozzles scale from it. */
|
|
11
|
+
const REFERENCE_NOZZLE_MM = 0.4;
|
|
12
|
+
const LAYER_MM_ON_REFERENCE = { draft: 0.28, fine: 0.12 };
|
|
13
|
+
const STRENGTH = {
|
|
14
|
+
strong: { wall_loops: 4, sparse_infill_density: "25%" },
|
|
15
|
+
max: { wall_loops: 6, sparse_infill_density: "40%" },
|
|
16
|
+
};
|
|
17
|
+
/** The call's arguments with `quality` and `strength` written out as slicer settings. */
|
|
18
|
+
export function withPrintQuality(args, nozzleDiameter) {
|
|
19
|
+
if (args.quality === undefined && args.strength === undefined)
|
|
20
|
+
return args;
|
|
21
|
+
const quality = args.quality === undefined ? "standard" : args.quality;
|
|
22
|
+
const strength = args.strength === undefined ? "standard" : args.strength;
|
|
23
|
+
if (typeof quality !== "string" || !PRINT_QUALITIES.includes(quality)) {
|
|
24
|
+
throw new Error(`quality must be one of ${PRINT_QUALITIES.join(", ")}.`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof strength !== "string" || !PRINT_STRENGTHS.includes(strength)) {
|
|
27
|
+
throw new Error(`strength must be one of ${PRINT_STRENGTHS.join(", ")}.`);
|
|
28
|
+
}
|
|
29
|
+
const out = { ...args };
|
|
30
|
+
const scale = typeof nozzleDiameter === "number" && Number.isFinite(nozzleDiameter) && nozzleDiameter > 0 ? nozzleDiameter / REFERENCE_NOZZLE_MM : 1;
|
|
31
|
+
const layer = LAYER_MM_ON_REFERENCE[quality];
|
|
32
|
+
if (layer !== undefined && out.layer_height === undefined)
|
|
33
|
+
out.layer_height = Math.round(layer * scale * 100) / 100;
|
|
34
|
+
const walls = STRENGTH[strength];
|
|
35
|
+
if (walls) {
|
|
36
|
+
if (out.wall_loops === undefined)
|
|
37
|
+
out.wall_loops = walls.wall_loops;
|
|
38
|
+
if (out.sparse_infill_density === undefined)
|
|
39
|
+
out.sparse_infill_density = walls.sparse_infill_density;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** slice_stl input-schema properties for both arguments. */
|
|
44
|
+
export const PRINT_QUALITY_PROPERTIES = {
|
|
45
|
+
quality: {
|
|
46
|
+
type: "string", enum: [...PRINT_QUALITIES],
|
|
47
|
+
description: "Print quality: draft (thicker layers, faster), standard (the preset's own layer height) or fine (thinner layers). The server picks the layer height for the nozzle in use; an explicit layer_height wins.",
|
|
48
|
+
},
|
|
49
|
+
strength: {
|
|
50
|
+
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.",
|
|
52
|
+
},
|
|
53
|
+
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -63,6 +63,8 @@ import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
|
63
63
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
64
64
|
import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
|
|
65
65
|
import { parseProcessOverrides } from "./slicer/process-overrides.js";
|
|
66
|
+
import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
|
|
67
|
+
import { PrinterRefusal } from "./refusal.js";
|
|
66
68
|
import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
|
|
67
69
|
|
|
68
70
|
dotenv.config();
|
|
@@ -963,6 +965,8 @@ type StructuredToolError = {
|
|
|
963
965
|
suggestion: string;
|
|
964
966
|
message: string;
|
|
965
967
|
tool: string;
|
|
968
|
+
/** A stable refusal code (src/refusal.ts) when the printer refused; clients act on it, not on the words. */
|
|
969
|
+
code?: string;
|
|
966
970
|
slicer_result?: Record<string, unknown>;
|
|
967
971
|
};
|
|
968
972
|
|
|
@@ -2667,6 +2671,7 @@ class BambuPrinterMCPServer {
|
|
|
2667
2671
|
skip_modified_gcodes: { type: "boolean", description: "Strip custom start/end gcodes embedded in the 3MF. Recommended for downloaded 3MFs since custom gcodes from other users' profiles may be unsafe for your printer." },
|
|
2668
2672
|
pause_at_layers: { type: "array", items: { type: "integer", minimum: 2 }, description: "Pause before each of these layers (1-based, as Bambu Studio and OrcaSlicer number them in the preview), for example to drop in magnets or nuts. The slicer writes the printer's own pause G-code there (M400 U1 on Bambu printers); the printer stops by itself and waits for Resume. Bambu Studio or OrcaSlicer CLI only. Pauses already in a project 3MF are kept." },
|
|
2669
2673
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates for local slicers; remote slicing defaults to plate 1 and rejects 0. Use 1, 2, etc. to slice only a specific plate in multi-plate 3MF projects." },
|
|
2674
|
+
...PRINT_QUALITY_PROPERTIES,
|
|
2670
2675
|
layer_height: { type: "number", exclusiveMinimum: 0, description: "Layer height in mm, such as 0.28 (draft), 0.2 (standard) or 0.12 (fine). Written as the process preset's layer_height over the machine and process preset this tool resolves; at most the nozzle diameter. Bambu-compatible slicers only." },
|
|
2671
2676
|
wall_loops: { type: "integer", minimum: 0, maximum: 1000, description: "Number of walls (perimeters), written as the process preset's wall_loops. Bambu-compatible slicers only." },
|
|
2672
2677
|
sparse_infill_density: { type: "string", pattern: "^\\s*\\d+(\\.\\d+)?\\s*%\\s*$", description: "Sparse infill density as a percentage, such as \"15%\", written as the process preset's sparse_infill_density. Bambu-compatible slicers only." },
|
|
@@ -4359,7 +4364,7 @@ class BambuPrinterMCPServer {
|
|
|
4359
4364
|
if (args?.skip_modified_gcodes !== undefined) sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
|
|
4360
4365
|
if (args?.slice_plate !== undefined) sliceBambuOptions.slicePlate = Number(args.slice_plate);
|
|
4361
4366
|
{ const pauses = parsePauseLayers(args?.pause_at_layers); if (pauses) sliceBambuOptions.pauseAtLayers = pauses; }
|
|
4362
|
-
const processOverrides = parseProcessOverrides(args as Record<string, unknown>, Number(nozzleDiam));
|
|
4367
|
+
const processOverrides = parseProcessOverrides(withPrintQuality(args as Record<string, unknown>, Number(nozzleDiam)), Number(nozzleDiam));
|
|
4363
4368
|
if (processOverrides) sliceBambuOptions.processOverrides = processOverrides;
|
|
4364
4369
|
if (sliceBambuOptions.loadFilamentIds && String(args.stl_path).toLowerCase().endsWith(".3mf")) {
|
|
4365
4370
|
// Bambu Studio's CLI refuses --load-filament-ids for 3MF input and counts it per input file.
|
|
@@ -4853,6 +4858,7 @@ class BambuPrinterMCPServer {
|
|
|
4853
4858
|
: `Check parameters and try again. Error: ${message}`,
|
|
4854
4859
|
message,
|
|
4855
4860
|
tool: name,
|
|
4861
|
+
...(error instanceof PrinterRefusal ? { code: error.code } : {}),
|
|
4856
4862
|
// The slicer's own result.json; the message starts with its error_string and warnings.
|
|
4857
4863
|
...(error instanceof SlicerRunError && error.slicerResult ? { slicer_result: error.slicerResult } : {}),
|
|
4858
4864
|
};
|
package/src/printers/bambu.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrinterRefusal } from "../refusal.js";
|
|
1
2
|
import {CameraStreams, type FrameOptions} from "./camera-stream.js";
|
|
2
3
|
import {openTcpCameraSource, openRtspCameraSource} from "./camera-sources.js";
|
|
3
4
|
import {cameraNumber} from "./camera-tools.js";
|
|
@@ -2069,7 +2070,7 @@ export class BambuImplementation {
|
|
|
2069
2070
|
if (verdict === "rejected") {
|
|
2070
2071
|
// Nothing started, so there is no checked job to resume or clear later.
|
|
2071
2072
|
this.checkedJobs.delete(`${host}\n${serial}`);
|
|
2072
|
-
throw new
|
|
2073
|
+
throw new PrinterRefusal("printer-command-rejected", COMMAND_REJECTED_MESSAGE);
|
|
2073
2074
|
}
|
|
2074
2075
|
if (verdict === "cancelled" || cancelled()) throw new Error(DISPATCH_CANCELLED_MESSAGE);
|
|
2075
2076
|
return verdict ?? "unconfirmed";
|
package/src/refusal.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A printer refusal with a stable code, returned as structuredContent.code on the tool's error, so clients
|
|
3
|
+
* such as Counterpart act on the code instead of matching the message (whose words, HMS numbers and
|
|
4
|
+
* firmware details change with the printer). Neither one starts a print.
|
|
5
|
+
*
|
|
6
|
+
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
|
+
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
|
+
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
*/
|
|
10
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"] as const;
|
|
11
|
+
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
|
+
|
|
13
|
+
export class PrinterRefusal extends Error {
|
|
14
|
+
constructor(readonly code: RefusalCode, message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "PrinterRefusal";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrinterRefusal } from "../refusal.js";
|
|
1
2
|
import { HIDDEN_HMS } from "./hidden-hms.js";
|
|
2
3
|
import { BambuClient, GetVersionCommand, PushAllCommand } from "bambu-node";
|
|
3
4
|
import { isDualNozzleModel, normalizeMaterial, normalizeModel } from "./limits.js";
|
|
@@ -338,7 +339,7 @@ export function isPauseNotice(raw: Record<string, any>, requireIdle: boolean): b
|
|
|
338
339
|
function validateErrors(raw: Record<string,any>, requireIdle: boolean, serial: string, model: string) {
|
|
339
340
|
const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
|
|
340
341
|
const terminal = isCancelledX2DJob(raw, model) || isFinishedP1SJob(raw, model);
|
|
341
|
-
if (requireIdle && !["IDLE","FINISH"].includes(state) && !terminal) throw new
|
|
342
|
+
if (requireIdle && !["IDLE","FINISH"].includes(state) && !terminal) throw new PrinterRefusal("printer-not-ready", `Printer state ${state} is not safely idle.`);
|
|
342
343
|
if (!requireIdle && !["IDLE","FINISH","RUNNING","PAUSE"].includes(state) && !terminal) throw new Error(`Printer state ${state} is unknown or failed.`);
|
|
343
344
|
if (finiteNumber(raw.print_error) !== 0 && !isPauseNotice(raw, requireIdle)) throw new Error("Printer reports a print error or did not report its error state.");
|
|
344
345
|
if (!Array.isArray(raw.hms)) throw new Error("Printer HMS error state is missing or malformed.");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* slice_stl's `quality` and `strength` (PRD §8.4): a client's print-sheet choice, mapped here to the
|
|
3
|
+
* slicer's own numbers so no client carries layer heights, wall counts or infill. Draft and Fine set
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export const PRINT_QUALITIES = ["draft", "standard", "fine"] as const;
|
|
9
|
+
export const PRINT_STRENGTHS = ["standard", "strong", "max"] as const;
|
|
10
|
+
|
|
11
|
+
export type PrintQuality = (typeof PRINT_QUALITIES)[number];
|
|
12
|
+
export type PrintStrength = (typeof PRINT_STRENGTHS)[number];
|
|
13
|
+
|
|
14
|
+
/** Layer heights on the reference 0.4 mm nozzle; other nozzles scale from it. */
|
|
15
|
+
const REFERENCE_NOZZLE_MM = 0.4;
|
|
16
|
+
const LAYER_MM_ON_REFERENCE: Partial<Record<PrintQuality, number>> = { draft: 0.28, fine: 0.12 };
|
|
17
|
+
const STRENGTH: Partial<Record<PrintStrength, { wall_loops: number; sparse_infill_density: string }>> = {
|
|
18
|
+
strong: { wall_loops: 4, sparse_infill_density: "25%" },
|
|
19
|
+
max: { wall_loops: 6, sparse_infill_density: "40%" },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The call's arguments with `quality` and `strength` written out as slicer settings. */
|
|
23
|
+
export function withPrintQuality(args: Record<string, unknown>, nozzleDiameter?: number): Record<string, unknown> {
|
|
24
|
+
if (args.quality === undefined && args.strength === undefined) return args;
|
|
25
|
+
const quality = args.quality === undefined ? "standard" : args.quality;
|
|
26
|
+
const strength = args.strength === undefined ? "standard" : args.strength;
|
|
27
|
+
if (typeof quality !== "string" || !(PRINT_QUALITIES as readonly string[]).includes(quality)) {
|
|
28
|
+
throw new Error(`quality must be one of ${PRINT_QUALITIES.join(", ")}.`);
|
|
29
|
+
}
|
|
30
|
+
if (typeof strength !== "string" || !(PRINT_STRENGTHS as readonly string[]).includes(strength)) {
|
|
31
|
+
throw new Error(`strength must be one of ${PRINT_STRENGTHS.join(", ")}.`);
|
|
32
|
+
}
|
|
33
|
+
const out: Record<string, unknown> = { ...args };
|
|
34
|
+
const scale = typeof nozzleDiameter === "number" && Number.isFinite(nozzleDiameter) && nozzleDiameter > 0 ? nozzleDiameter / REFERENCE_NOZZLE_MM : 1;
|
|
35
|
+
const layer = LAYER_MM_ON_REFERENCE[quality as PrintQuality];
|
|
36
|
+
if (layer !== undefined && out.layer_height === undefined) out.layer_height = Math.round(layer * scale * 100) / 100;
|
|
37
|
+
const walls = STRENGTH[strength as PrintStrength];
|
|
38
|
+
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
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** slice_stl input-schema properties for both arguments. */
|
|
46
|
+
export const PRINT_QUALITY_PROPERTIES = {
|
|
47
|
+
quality: {
|
|
48
|
+
type: "string", enum: [...PRINT_QUALITIES],
|
|
49
|
+
description: "Print quality: draft (thicker layers, faster), standard (the preset's own layer height) or fine (thinner layers). The server picks the layer height for the nozzle in use; an explicit layer_height wins.",
|
|
50
|
+
},
|
|
51
|
+
strength: {
|
|
52
|
+
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.",
|
|
54
|
+
},
|
|
55
|
+
} as const;
|