MCP 3D Printer Server

by DMontgomery40
Verified
import EventEmitter from "node:events"; import BambuFTP from "./BambuFTP"; import BambuMQTT from "./BambuMQTT"; import type { RawPrinterState } from "../types/RawPrinterState"; import type { PrinterState } from "../types/PrinterState"; /** * A class for interfacing with a Bambu Lab printer. * @emits update - Emitted when the printer's state is updated. * @emits connect - Emitted when the printer is connected. * @emits disconnect - Emitted when the printer is disconnected. */ declare class BambuPrinter extends EventEmitter { host: string; serial: string; accessCode: string; state: RawPrinterState; hasInitialUpdate: boolean; mqtt: BambuMQTT; constructor(host: string, serial: string, accessCode: string); /** * Connect to the printer. */ connect(): Promise<void>; /** * Disconnect from the printer. */ disconnect(): Promise<void>; /** * Create a context for manipulating files on the printer's SD card. * @param callback - Callback to manipulate files within the context. */ manipulateFiles(callback: (context: BambuFTP) => Promise<void>): Promise<void>; /** * Get the raw state of the printer. * @returns The raw state of the printer. */ getRawState(): RawPrinterState; /** * Get the state of the printer. */ getState(): PrinterState; /** * Await the printer to send its initial state. * @param timeout - The maximum time to wait for the initial state. * @returns The initial state of the printer. */ awaitInitialState(timeout?: number): Promise<PrinterState>; /** * Pause the current print job. */ pause(): void; /** * Resume the current print job. */ resume(): void; /** * Stop the current print job. */ stop(): void; /** * Set the state of the printer's LED. * @param options - Options for setting the LED state. */ setLed(options: SetLedOptions): void; /** * Print a 3MF project file from the printer's SD card. * @param projectPath - The absolute path to the 3MF file on the printer's SD card. * @param file - The absolute path of the gcode file in the 3MF project to be printed (e.g. "Metadata/plate_1.gcode") * @param name - The name to use for the print job. Serves no functional purpose. * @param hash - The MD5 hash of the gcode file. * @param options - Options for the print job. */ printProjectFile(projectPath: string, file: string, name: string, hash: string, options?: PrintProjectFileOptions): void; /** * Get the current connection status. */ get isConnected(): boolean; /** * Handle the state update event. * @param state - The new state of the printer. */ private onStateUpdate; } declare interface BambuPrinter { on(event: "connect", listener: () => void): this; on(event: "disconnect", listener: () => void): this; on(event: "update", listener: (state: PrinterState) => void): this; on(event: "error", listener: (error: Error) => void): this; } interface SetLedOptions { mode: "on" | "off" | "flashing"; onTime?: number; offTime?: number; loopTimes?: number; intervalTime?: number; } interface PrintProjectFileOptions { flowCalibration?: boolean; layerInspect?: boolean; timelaspe?: boolean; vibrationCalibration?: boolean; bedLeveling?: boolean; bedType?: string; } export default BambuPrinter;