bambu-printer-mcp 1.1.73 → 1.1.74
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 +1 -1
- package/dist/printers/bambu.js +10 -3
- package/dist/printers/ftp-upload.d.ts +17 -0
- package/dist/printers/ftp-upload.js +23 -0
- package/dist/refusal.d.ts +2 -1
- package/dist/refusal.js +2 -1
- package/package.json +1 -1
- package/src/printers/bambu.ts +9 -3
- package/src/printers/ftp-upload.ts +26 -0
- package/src/refusal.ts +2 -1
package/README.md
CHANGED
|
@@ -1086,7 +1086,7 @@ If the project does not match those assumptions, the tool fails fast with a stru
|
|
|
1086
1086
|
|
|
1087
1087
|
#### Counterpart tools (`counterpart/1`)
|
|
1088
1088
|
|
|
1089
|
-
[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, the error also carries a stable `code
|
|
1089
|
+
[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, the error also carries a stable `code`: `printer-command-rejected`, `printer-not-ready`, or `printer-upload-failed` when the file didn't reach the printer and no print command was sent, so a client can act on the code rather than the wording. `counterpart_printer_info` reports `capabilities.slicing` (`supports`, `copies`, `orient`), so a client can offer those choices without knowing the slicer. `counterpart_printer_info` and `counterpart_print_progress` take the usual optional `host`, `bambu_serial`, `bambu_token` and `bambu_model` (default `BAMBU_MODEL`) arguments.
|
|
1090
1090
|
|
|
1091
1091
|
- **`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.
|
|
1092
1092
|
- **`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.
|
package/dist/printers/bambu.js
CHANGED
|
@@ -10,7 +10,6 @@ import fs from "node:fs/promises";
|
|
|
10
10
|
import { createReadStream, readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import os from "node:os";
|
|
13
|
-
import { Readable } from "node:stream";
|
|
14
13
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
15
14
|
import { inspectPrintFile } from "../safety/print-file.js";
|
|
16
15
|
import { isDualNozzleModel, normalizeModel, validateTemperature } from "../safety/limits.js";
|
|
@@ -20,6 +19,7 @@ import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRem
|
|
|
20
19
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
21
20
|
import { resolveStudioPrintOptions, usedNozzleCount } from "../studio-print-options.js";
|
|
22
21
|
import { Client as FTPClient } from "basic-ftp";
|
|
22
|
+
import { uploadBytes } from "./ftp-upload.js";
|
|
23
23
|
import * as mqtt from "mqtt";
|
|
24
24
|
import { BambuClient, GCodeFileCommand, GCodeLineCommand, PushAllCommand, UpdateFanCommand, UpdateLightCommand, } from "bambu-node";
|
|
25
25
|
/**
|
|
@@ -1088,7 +1088,13 @@ export class BambuImplementation {
|
|
|
1088
1088
|
validatePrinterState(confirmedStatus, requirements);
|
|
1089
1089
|
this.assertPrintPreflight(confirmedStatus, preflight);
|
|
1090
1090
|
assertActive();
|
|
1091
|
-
|
|
1091
|
+
try {
|
|
1092
|
+
await this.ftpUpload(host, token, options.filePath, remoteUploadPath);
|
|
1093
|
+
}
|
|
1094
|
+
catch (error) {
|
|
1095
|
+
// Nothing has been sent to the printer but (part of) a file, so the print certainly did not start.
|
|
1096
|
+
throw new PrinterRefusal("printer-upload-failed", `The print file did not reach the printer (${error instanceof Error ? error.message : String(error)}). No print was started.`);
|
|
1097
|
+
}
|
|
1092
1098
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1093
1099
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
1094
1100
|
if (legacyContainer)
|
|
@@ -2266,7 +2272,8 @@ export class BambuImplementation {
|
|
|
2266
2272
|
throw new Error(`Refusing to overwrite existing printer file ${absoluteRemote}. Choose a new filename.`);
|
|
2267
2273
|
}
|
|
2268
2274
|
const fileData = await fs.readFile(localPath);
|
|
2269
|
-
|
|
2275
|
+
// Small writes, so a multi-megabyte job on a slow SD card is not mistaken for a stall.
|
|
2276
|
+
await uploadBytes(client, fileData, absoluteRemote);
|
|
2270
2277
|
}
|
|
2271
2278
|
finally {
|
|
2272
2279
|
client.close();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Client as FTPClient } from "basic-ftp";
|
|
2
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
3
|
+
export declare const FTP_UPLOAD_CHUNK_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* Store bytes on the printer in small writes.
|
|
6
|
+
*
|
|
7
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
8
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
9
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
10
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
11
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
12
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
13
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
14
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
15
|
+
* inspected; nothing is re-read from disk.
|
|
16
|
+
*/
|
|
17
|
+
export declare function uploadBytes(client: FTPClient, bytes: Buffer, remotePath: string, chunkBytes?: number): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
3
|
+
export const FTP_UPLOAD_CHUNK_BYTES = 64 * 1024;
|
|
4
|
+
function* chunks(bytes, size) {
|
|
5
|
+
for (let offset = 0; offset < bytes.length; offset += size)
|
|
6
|
+
yield bytes.subarray(offset, offset + size);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Store bytes on the printer in small writes.
|
|
10
|
+
*
|
|
11
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
12
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
13
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
14
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
15
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
16
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
17
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
18
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
19
|
+
* inspected; nothing is re-read from disk.
|
|
20
|
+
*/
|
|
21
|
+
export async function uploadBytes(client, bytes, remotePath, chunkBytes = FTP_UPLOAD_CHUNK_BYTES) {
|
|
22
|
+
await client.uploadFrom(Readable.from(chunks(bytes, chunkBytes)), remotePath);
|
|
23
|
+
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export declare const REFUSAL_CODES: readonly ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export declare const REFUSAL_CODES: readonly ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"];
|
|
11
12
|
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
13
|
export declare class PrinterRefusal extends Error {
|
|
13
14
|
readonly code: RefusalCode;
|
package/dist/refusal.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"];
|
|
11
12
|
export class PrinterRefusal extends Error {
|
|
12
13
|
constructor(code, message) {
|
|
13
14
|
super(message);
|
package/package.json
CHANGED
package/src/printers/bambu.ts
CHANGED
|
@@ -10,7 +10,6 @@ import fs from "node:fs/promises";
|
|
|
10
10
|
import { createReadStream, readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import os from "node:os";
|
|
13
|
-
import { Readable } from "node:stream";
|
|
14
13
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
15
14
|
import { inspectPrintFile, type PrintFileInspection } from "../safety/print-file.js";
|
|
16
15
|
import { isDualNozzleModel, normalizeModel, validateTemperature } from "../safety/limits.js";
|
|
@@ -20,6 +19,7 @@ import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRem
|
|
|
20
19
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
21
20
|
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "../studio-print-options.js";
|
|
22
21
|
import { Client as FTPClient } from "basic-ftp";
|
|
22
|
+
import { uploadBytes } from "./ftp-upload.js";
|
|
23
23
|
import * as mqtt from "mqtt";
|
|
24
24
|
import {
|
|
25
25
|
BambuClient,
|
|
@@ -1256,7 +1256,12 @@ export class BambuImplementation {
|
|
|
1256
1256
|
else validatePrinterState(confirmedStatus, requirements);
|
|
1257
1257
|
this.assertPrintPreflight(confirmedStatus, preflight);
|
|
1258
1258
|
assertActive();
|
|
1259
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
await this.ftpUpload(host, token, options.filePath, remoteUploadPath);
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
// Nothing has been sent to the printer but (part of) a file, so the print certainly did not start.
|
|
1263
|
+
throw new PrinterRefusal("printer-upload-failed", `The print file did not reach the printer (${error instanceof Error ? error.message : String(error)}). No print was started.`);
|
|
1264
|
+
}
|
|
1260
1265
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1261
1266
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
1262
1267
|
if (legacyContainer) requirements = this.validateLoadedGcodeState(dispatchStatus, inspection);
|
|
@@ -2530,7 +2535,8 @@ export class BambuImplementation {
|
|
|
2530
2535
|
throw new Error(`Refusing to overwrite existing printer file ${absoluteRemote}. Choose a new filename.`);
|
|
2531
2536
|
}
|
|
2532
2537
|
const fileData = await fs.readFile(localPath);
|
|
2533
|
-
|
|
2538
|
+
// Small writes, so a multi-megabyte job on a slow SD card is not mistaken for a stall.
|
|
2539
|
+
await uploadBytes(client, fileData, absoluteRemote);
|
|
2534
2540
|
} finally {
|
|
2535
2541
|
client.close();
|
|
2536
2542
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import type { Client as FTPClient } from "basic-ftp";
|
|
3
|
+
|
|
4
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
5
|
+
export const FTP_UPLOAD_CHUNK_BYTES = 64 * 1024;
|
|
6
|
+
|
|
7
|
+
function* chunks(bytes: Buffer, size: number): Generator<Buffer> {
|
|
8
|
+
for (let offset = 0; offset < bytes.length; offset += size) yield bytes.subarray(offset, offset + size);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Store bytes on the printer in small writes.
|
|
13
|
+
*
|
|
14
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
15
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
16
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
17
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
18
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
19
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
20
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
21
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
22
|
+
* inspected; nothing is re-read from disk.
|
|
23
|
+
*/
|
|
24
|
+
export async function uploadBytes(client: FTPClient, bytes: Buffer, remotePath: string, chunkBytes = FTP_UPLOAD_CHUNK_BYTES): Promise<void> {
|
|
25
|
+
await client.uploadFrom(Readable.from(chunks(bytes, chunkBytes)), remotePath);
|
|
26
|
+
}
|
package/src/refusal.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"] as const;
|
|
11
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"] as const;
|
|
11
12
|
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
13
|
|
|
13
14
|
export class PrinterRefusal extends Error {
|