bambu-printer-mcp 1.1.50 → 1.1.52
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 +33 -8
- package/dist/ams-mapping.d.ts +19 -0
- package/dist/ams-mapping.js +49 -0
- package/dist/bambu-network-bridge.d.ts +86 -9
- package/dist/bambu-network-bridge.js +284 -4
- package/dist/control-reply.d.ts +21 -0
- package/dist/control-reply.js +44 -0
- package/dist/counterpart/info.js +1 -0
- package/dist/counterpart/route.d.ts +37 -0
- package/dist/counterpart/route.js +78 -0
- package/dist/counterpart/schemas.d.ts +4 -0
- package/dist/counterpart/schemas.js +1 -0
- package/dist/design-guidance.d.ts +26 -0
- package/dist/design-guidance.js +177 -0
- package/dist/fusion-mcp-bridge.d.ts +8 -4
- package/dist/fusion-mcp-bridge.js +36 -10
- package/dist/index.js +219 -54
- package/dist/printers/bambu.d.ts +38 -13
- package/dist/printers/bambu.js +204 -69
- package/dist/printers/camera-sources.d.ts +8 -0
- package/dist/printers/camera-sources.js +66 -0
- package/dist/printers/camera-stream.d.ts +65 -0
- package/dist/printers/camera-stream.js +227 -0
- package/dist/printers/camera-tools.d.ts +192 -0
- package/dist/printers/camera-tools.js +29 -0
- package/dist/printers/camera-wire.d.ts +7 -0
- package/dist/printers/camera-wire.js +40 -0
- package/dist/safety/print-file.d.ts +3 -0
- package/dist/safety/print-file.js +11 -2
- package/dist/safety/printer-state.d.ts +7 -0
- package/dist/safety/printer-state.js +11 -1
- package/dist/slicer/layer-pauses.d.ts +47 -0
- package/dist/slicer/layer-pauses.js +130 -0
- package/dist/stl/stl-manipulator.d.ts +40 -1
- package/dist/stl/stl-manipulator.js +253 -83
- package/package.json +2 -1
- package/src/ams-mapping.ts +52 -0
- package/src/bambu-network-bridge.ts +311 -8
- package/src/control-reply.ts +41 -0
- package/src/counterpart/info.ts +1 -0
- package/src/counterpart/route.ts +91 -0
- package/src/counterpart/schemas.ts +2 -0
- package/src/design-guidance.ts +188 -0
- package/src/fusion-mcp-bridge.ts +30 -10
- package/src/index.ts +213 -57
- package/src/printers/bambu.ts +194 -60
- package/src/printers/camera-sources.ts +53 -0
- package/src/printers/camera-stream.ts +165 -0
- package/src/printers/camera-tools.ts +29 -0
- package/src/printers/camera-wire.ts +39 -0
- package/src/safety/print-file.ts +12 -2
- package/src/safety/printer-state.ts +11 -1
- package/src/slicer/layer-pauses.ts +143 -0
- package/src/stl/stl-manipulator.ts +298 -93
package/dist/index.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { CAMERA_STREAM_TOOLS } from "./printers/camera-tools.js";
|
|
2
3
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
5
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
5
|
-
import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
6
7
|
import dotenv from "dotenv";
|
|
8
|
+
import { PRINT_ROUTES, connectionForRoute, ownLocalOf, routeOf, routeOptions, writeEnvValues } from "./counterpart/route.js";
|
|
7
9
|
import fs from "fs";
|
|
8
10
|
import os from "node:os";
|
|
9
11
|
import path from "path";
|
|
10
12
|
import { createServer as createHttpServer } from "node:http";
|
|
11
13
|
import { randomUUID } from "node:crypto";
|
|
12
|
-
import { STLManipulator, SLICER_TYPES, normalizeSlicerType, } from "./stl/stl-manipulator.js";
|
|
14
|
+
import { STLManipulator, SLICER_TYPES, normalizeSlicerType, SlicerRunError, } from "./stl/stl-manipulator.js";
|
|
13
15
|
import { BambuNetworkBridge, describeBambuNetworkPrintError } from "./bambu-network-bridge.js";
|
|
14
16
|
import { assertBambuNativeAvailable, bambuNativeControlsAvailable, bambuNativeUnavailableReason, interruptNativeOperations, validateBambuNativeMetadata, buildBambuNativeFanCommand, buildBambuNativeTemperatureCommand, printWithBambuNative, sendCommandWithBambuNative, uploadWithBambuNative, } from "./bambu-native.js";
|
|
15
17
|
import { importFileViaBambuConnect } from "./bambu-connect.js";
|
|
16
18
|
import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
|
|
17
|
-
import {
|
|
18
|
-
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue } from "./ams-mapping.js";
|
|
19
|
+
import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
|
|
20
|
+
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
|
|
19
21
|
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
|
|
20
|
-
import { BambuImplementation, assertDirectPrintSupported, checkedFile } from "./printers/bambu.js";
|
|
22
|
+
import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
|
|
21
23
|
import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-options.js";
|
|
22
24
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
23
25
|
import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
@@ -25,10 +27,12 @@ import { isDualNozzleModel } from "./safety/limits.js";
|
|
|
25
27
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName } from "./safety/artifact.js";
|
|
26
28
|
import { detectProfilesRoot } from "./slicer/profile-flatten.js";
|
|
27
29
|
import { bambuPrinterInfo } from "./counterpart/info.js";
|
|
30
|
+
import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_CAPABILITY_URI, SERVER_INSTRUCTIONS } from "./design-guidance.js";
|
|
28
31
|
import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
29
32
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
30
33
|
import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
|
|
31
34
|
import { parseProcessOverrides } from "./slicer/process-overrides.js";
|
|
35
|
+
import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
|
|
32
36
|
dotenv.config();
|
|
33
37
|
const DEFAULT_HOST = process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST || "localhost";
|
|
34
38
|
const DEFAULT_BAMBU_SERIAL = process.env.BAMBU_PRINTER_SERIAL || process.env.BAMBU_SERIAL || "";
|
|
@@ -59,7 +63,28 @@ if (AUTOMATIC_TEMP_DIR) {
|
|
|
59
63
|
const DEFAULT_BAMBU_MODEL = process.env.BAMBU_PRINTER_MODEL?.trim().toLowerCase() ||
|
|
60
64
|
process.env.BAMBU_MODEL?.trim().toLowerCase() ||
|
|
61
65
|
"";
|
|
62
|
-
|
|
66
|
+
// counterpart_print_route changes these at run time (and in the .env file they came from).
|
|
67
|
+
let DEFAULT_BAMBU_CONNECTION_MODE = process.env.BAMBU_DEFAULT_CONNECTION_MODE?.trim().toLowerCase() || "";
|
|
68
|
+
let DEFAULT_BAMBU_CONNECTION_TYPE = process.env.BAMBU_DEFAULT_CONNECTION_TYPE?.trim().toLowerCase() || "";
|
|
69
|
+
/** The connection configured at start, before counterpart_print_route changes it: its own local route is kept. */
|
|
70
|
+
const CONFIGURED_CONNECTION = { mode: DEFAULT_BAMBU_CONNECTION_MODE, type: DEFAULT_BAMBU_CONNECTION_TYPE };
|
|
71
|
+
const CONNECTION_MODES = ["lan_mqtt_ftps", "bambu_native", "bambu_network", "bambu_connect"];
|
|
72
|
+
/**
|
|
73
|
+
* The one route decision for a printer: print_3mf and every print control
|
|
74
|
+
* (cancel, pause, resume) resolve it here, so a job is never controlled over a
|
|
75
|
+
* different connection than the one that started it. Arguments override the
|
|
76
|
+
* server's configured defaults; without either, X2D uses its native route and
|
|
77
|
+
* every other model direct LAN MQTT/FTPS.
|
|
78
|
+
*/
|
|
79
|
+
function resolveConnection(args, model) {
|
|
80
|
+
const mode = String(args?.connection_mode || DEFAULT_BAMBU_CONNECTION_MODE || (model === "x2d" ? "bambu_native" : "lan_mqtt_ftps")).trim().toLowerCase();
|
|
81
|
+
if (!CONNECTION_MODES.includes(mode))
|
|
82
|
+
throw new Error("Unsupported connection_mode.");
|
|
83
|
+
const type = String(args?.connection_type || DEFAULT_BAMBU_CONNECTION_TYPE || "cloud").trim().toLowerCase();
|
|
84
|
+
if (!["cloud", "lan"].includes(type))
|
|
85
|
+
throw new Error('connection_type must be "cloud" or "lan".');
|
|
86
|
+
return { mode, type };
|
|
87
|
+
}
|
|
63
88
|
const DEFAULT_BED_TYPE = process.env.BED_TYPE?.trim().toLowerCase() || "textured_plate";
|
|
64
89
|
const DEFAULT_NOZZLE_DIAMETER = process.env.NOZZLE_DIAMETER?.trim() || "0.4";
|
|
65
90
|
/** MCP initialize name/version; counterpart_printer_info reports the same values. */
|
|
@@ -70,7 +95,8 @@ const SERVER_INFO = {
|
|
|
70
95
|
/** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
|
|
71
96
|
const OUTPUT_SCHEMA_TOOLS = new Set([
|
|
72
97
|
"counterpart_printer_info", "counterpart_print_progress", "counterpart_make_3mf",
|
|
73
|
-
"fusion_mcp_status", "
|
|
98
|
+
"fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
|
|
99
|
+
"camera_stream_start", "camera_frame", "camera_stream_stop",
|
|
74
100
|
]);
|
|
75
101
|
/** Bound for each Linux X2D emergency MQTT send (BAMBU_EMERGENCY_MQTT_TIMEOUT_MS, 1–60000 ms). */
|
|
76
102
|
function withEmergencyMqttTimeout(send) {
|
|
@@ -959,9 +985,11 @@ class BambuPrinterMCPServer {
|
|
|
959
985
|
this.runtimeConfig = readRuntimeConfig();
|
|
960
986
|
this.server = new Server(SERVER_INFO, {
|
|
961
987
|
capabilities: {
|
|
988
|
+
prompts: {},
|
|
962
989
|
resources: {},
|
|
963
990
|
tools: {}
|
|
964
|
-
}
|
|
991
|
+
},
|
|
992
|
+
instructions: SERVER_INSTRUCTIONS
|
|
965
993
|
});
|
|
966
994
|
this.bambu = new BambuImplementation(async (message) => {
|
|
967
995
|
try {
|
|
@@ -984,11 +1012,11 @@ class BambuPrinterMCPServer {
|
|
|
984
1012
|
throw new Error(`No hardware confirmation within ${describeDuration(this.confirmationTimeoutMs)}; nothing was sent to the printer. Retry when someone can check the printer, or raise BAMBU_CONFIRMATION_TIMEOUT_MS.`);
|
|
985
1013
|
}
|
|
986
1014
|
if (isElicitationUnsupported(error)) {
|
|
987
|
-
throw new Error("Human hardware confirmation requires an MCP client with elicitation support.
|
|
1015
|
+
throw new Error("Human hardware confirmation requires an MCP client with elicitation support. Only clearing hardware errors, the first print after a clear, and resuming a file that could not be re-read ask.");
|
|
988
1016
|
}
|
|
989
1017
|
throw new Error(`Human hardware confirmation failed: ${error?.message ?? error}. Nothing was sent to the printer.`);
|
|
990
1018
|
}
|
|
991
|
-
});
|
|
1019
|
+
}, { resumeStateDir: defaultResumeStateDir() });
|
|
992
1020
|
this.bambuNetwork = new BambuNetworkBridge();
|
|
993
1021
|
this.stlManipulator = new STLManipulator(TEMP_DIR);
|
|
994
1022
|
this.setupHandlers();
|
|
@@ -1001,6 +1029,7 @@ class BambuPrinterMCPServer {
|
|
|
1001
1029
|
}
|
|
1002
1030
|
setupHandlers() {
|
|
1003
1031
|
this.setupResourceHandlers();
|
|
1032
|
+
this.setupPromptHandlers();
|
|
1004
1033
|
this.setupToolHandlers();
|
|
1005
1034
|
}
|
|
1006
1035
|
/**
|
|
@@ -1216,10 +1245,7 @@ class BambuPrinterMCPServer {
|
|
|
1216
1245
|
if (!Number.isInteger(plateIndex) || plateIndex < 0) {
|
|
1217
1246
|
throw new Error("plate_index must be a non-negative integer.");
|
|
1218
1247
|
}
|
|
1219
|
-
const connectionType =
|
|
1220
|
-
if (!["cloud", "lan"].includes(connectionType)) {
|
|
1221
|
-
throw new Error('connection_type must be "cloud" or "lan".');
|
|
1222
|
-
}
|
|
1248
|
+
const connectionType = resolveConnection(args).type;
|
|
1223
1249
|
const bridgePrintMethod = resolveBambuNetworkPrintMethod(args?.bambu_network_method !== undefined ? String(args.bambu_network_method) : undefined, connectionType);
|
|
1224
1250
|
const bridgeMethod = toBridgeMethod(bridgePrintMethod);
|
|
1225
1251
|
const isLocalBridgePrint = bridgePrintMethod !== "start_print";
|
|
@@ -1306,7 +1332,10 @@ class BambuPrinterMCPServer {
|
|
|
1306
1332
|
nozzle_mapping: stringifyBridgeJson(args?.nozzle_mapping) || "",
|
|
1307
1333
|
ams_mapping: amsMapping || "",
|
|
1308
1334
|
ams_mapping2: nativeAmsMapping2(mapping, isDualNozzleModel(printModel)) || "",
|
|
1309
|
-
|
|
1335
|
+
// Bambu Studio and FULU's slicer send this with every job (get_ams_mapping_result).
|
|
1336
|
+
ams_mapping_info: mapping && inspection.projectFilaments?.length
|
|
1337
|
+
? JSON.stringify(studioAmsMappingInfo(inspection.projectFilaments, mapping, tray => trayColour(confirmedStatus.raw, tray)))
|
|
1338
|
+
: "",
|
|
1310
1339
|
nozzles_info: stringifyBridgeJson(args?.nozzles_info) || "",
|
|
1311
1340
|
connection_type: connectionType,
|
|
1312
1341
|
comments: String(args?.comments || ""),
|
|
@@ -1395,7 +1424,7 @@ class BambuPrinterMCPServer {
|
|
|
1395
1424
|
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startLocalPrint({ devId, devIp, username: String(params.username), password, useSsl: params.use_ssl_for_mqtt }, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1396
1425
|
}
|
|
1397
1426
|
else {
|
|
1398
|
-
bridgeResult = await this.bambuNetwork.
|
|
1427
|
+
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1399
1428
|
}
|
|
1400
1429
|
if (typeof bridgeResult === "object" && bridgeResult !== null && bridgeResult.ok === false) {
|
|
1401
1430
|
throw new Error(`FULU BambuNetwork bridge method ${bridgeMethod} failed: ${String(bridgeResult.error || "unknown bridge error")}`);
|
|
@@ -1669,6 +1698,21 @@ class BambuPrinterMCPServer {
|
|
|
1669
1698
|
resolved_path: registryEntry,
|
|
1670
1699
|
};
|
|
1671
1700
|
}
|
|
1701
|
+
/** The FDM design guidance as MCP prompts: the client decides when to attach each one. */
|
|
1702
|
+
setupPromptHandlers() {
|
|
1703
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
1704
|
+
prompts: DESIGN_PROMPTS.map(({ name, title, description }) => ({ name, title, description })),
|
|
1705
|
+
}));
|
|
1706
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
1707
|
+
const prompt = DESIGN_PROMPTS.find(item => item.name === request.params.name);
|
|
1708
|
+
if (!prompt)
|
|
1709
|
+
throw new McpError(ErrorCode.InvalidParams, `Unknown prompt: ${request.params.name}`);
|
|
1710
|
+
return {
|
|
1711
|
+
description: prompt.description,
|
|
1712
|
+
messages: [{ role: "user", content: { type: "text", text: prompt.text } }],
|
|
1713
|
+
};
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1672
1716
|
setupResourceHandlers() {
|
|
1673
1717
|
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
1674
1718
|
return {
|
|
@@ -1690,7 +1734,8 @@ class BambuPrinterMCPServer {
|
|
|
1690
1734
|
name: "Bambu Printer HMS Diagnostics",
|
|
1691
1735
|
mimeType: "application/json",
|
|
1692
1736
|
description: "HMS and error-related fields from the latest printer status"
|
|
1693
|
-
}
|
|
1737
|
+
},
|
|
1738
|
+
FDM_CAPABILITY_RESOURCE
|
|
1694
1739
|
],
|
|
1695
1740
|
templates: [
|
|
1696
1741
|
{
|
|
@@ -1713,6 +1758,9 @@ class BambuPrinterMCPServer {
|
|
|
1713
1758
|
});
|
|
1714
1759
|
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
1715
1760
|
const uri = request.params.uri;
|
|
1761
|
+
if (uri === FDM_CAPABILITY_URI) {
|
|
1762
|
+
return { contents: [{ uri, mimeType: FDM_CAPABILITY_RESOURCE.mimeType, text: FDM_CAPABILITY_GUIDANCE }] };
|
|
1763
|
+
}
|
|
1716
1764
|
const match = uri.match(/^printer:\/\/([^\/]+)\/(.+)$/);
|
|
1717
1765
|
if (!match) {
|
|
1718
1766
|
throw new McpError(ErrorCode.InvalidRequest, `Invalid resource URI: ${uri}`);
|
|
@@ -1997,13 +2045,14 @@ class BambuPrinterMCPServer {
|
|
|
1997
2045
|
ensure_on_bed: { type: "boolean", description: "Lift floating models onto the bed." },
|
|
1998
2046
|
arrange: { type: "boolean", description: "Auto-arrange objects on the build plate." },
|
|
1999
2047
|
orient: { type: "boolean", description: "Auto-orient model for optimal printability." },
|
|
2000
|
-
repetitions: { type: "number", description: "
|
|
2048
|
+
repetitions: { type: "number", description: "Total copies of an STL, using clone_objects internally. Do not also pass clone_objects. The slicer may place copies on multiple plates; print_3mf prints one selected plate per call. For 3MF input, select slice_plate explicitly." },
|
|
2001
2049
|
scale: { type: "number", description: "Uniform scale factor." },
|
|
2002
2050
|
rotate: { type: "number", description: "Z-axis rotation in degrees." },
|
|
2003
2051
|
rotate_x: { type: "number", description: "X-axis rotation in degrees." },
|
|
2004
2052
|
rotate_y: { type: "number", description: "Y-axis rotation in degrees." },
|
|
2005
2053
|
min_save: { type: "boolean", description: "Produce smaller output 3MF." },
|
|
2006
2054
|
skip_modified_gcodes: { type: "boolean", description: "Ignore stale custom gcodes in the 3MF." },
|
|
2055
|
+
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." },
|
|
2007
2056
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates." }
|
|
2008
2057
|
},
|
|
2009
2058
|
required: ["stl_path", "template_name", "bambu_model"]
|
|
@@ -2011,7 +2060,7 @@ class BambuPrinterMCPServer {
|
|
|
2011
2060
|
},
|
|
2012
2061
|
{
|
|
2013
2062
|
name: "slice_stl",
|
|
2014
|
-
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.",
|
|
2063
|
+
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.",
|
|
2015
2064
|
inputSchema: {
|
|
2016
2065
|
type: "object",
|
|
2017
2066
|
properties: {
|
|
@@ -2049,7 +2098,7 @@ class BambuPrinterMCPServer {
|
|
|
2049
2098
|
},
|
|
2050
2099
|
use_printer_filaments: { type: "boolean", description: "When true, and no explicit slicer profile or load_filaments override is provided, use the printer's current or first loaded AMS filament as the slicer filament profile. Template 3MF process settings can still be used at the same time." },
|
|
2051
2100
|
uptodate: { type: "boolean", description: "Refresh 3MF preset configs to match the latest BambuStudio version. Use when slicing downloaded or older 3MF files to prevent stale-config failures." },
|
|
2052
|
-
repetitions: { type: "number", description: "
|
|
2101
|
+
repetitions: { type: "number", description: "Slice N identical copies of the model. Bambu Studio and OrcaSlicer copy an STL with --clone-objects; do not also pass clone_objects. Copies may need multiple plates; print_3mf prints one selected plate per call. For 3MF input, select slice_plate explicitly." },
|
|
2053
2102
|
orient: { type: "boolean", description: "Auto-orient the model for optimal printability (minimize supports, maximize bed adhesion). Recommended for raw STL imports that lack a pre-set orientation." },
|
|
2054
2103
|
arrange: { type: "boolean", description: "Auto-arrange all objects on the build plate with optimal spacing; STL input is arranged by default. Set false only to keep a 3MF's existing layout: an STL that is not already on the plate then fails to slice." },
|
|
2055
2104
|
ensure_on_bed: { type: "boolean", description: "Detect models floating above the bed and lower them onto the build surface. Safety net for imported models with incorrect Z origins." },
|
|
@@ -2067,6 +2116,7 @@ class BambuPrinterMCPServer {
|
|
|
2067
2116
|
rotate_y: { type: "number", description: "Rotate the model around the Y-axis by this many degrees before slicing. Useful for reorienting prints for better layer adhesion." },
|
|
2068
2117
|
min_save: { type: "boolean", description: "Write a smaller output 3MF by omitting non-essential metadata. Reduces file size for faster FTP upload to the printer." },
|
|
2069
2118
|
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." },
|
|
2119
|
+
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." },
|
|
2070
2120
|
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." },
|
|
2071
2121
|
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." },
|
|
2072
2122
|
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." },
|
|
@@ -2195,6 +2245,7 @@ class BambuPrinterMCPServer {
|
|
|
2195
2245
|
required: ["three_mf_path", "bambu_model"]
|
|
2196
2246
|
}
|
|
2197
2247
|
},
|
|
2248
|
+
...CAMERA_STREAM_TOOLS,
|
|
2198
2249
|
{
|
|
2199
2250
|
name: "camera_snapshot",
|
|
2200
2251
|
description: "Capture a single JPEG frame from the printer's chamber camera. A1/P1 use TCP-on-6000; X1/P2S/H2/X2D use RTSP via ffmpeg. Returns JPEG as base64; pass save_path to also write the bytes to disk.",
|
|
@@ -2326,7 +2377,9 @@ class BambuPrinterMCPServer {
|
|
|
2326
2377
|
properties: {
|
|
2327
2378
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2328
2379
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2329
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2380
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2381
|
+
connection_mode: { type: "string", enum: ["lan_mqtt_ftps", "bambu_network", "bambu_native"], description: "The connection the print used. Defaults to BAMBU_DEFAULT_CONNECTION_MODE, the same default print_3mf uses, else the model's route." },
|
|
2382
|
+
connection_type: { type: "string", enum: ["lan", "cloud"], description: "FULU BambuNetwork connection type the print used. Defaults to BAMBU_DEFAULT_CONNECTION_TYPE, as for print_3mf. Authenticated controls support lan." }
|
|
2330
2383
|
}
|
|
2331
2384
|
}
|
|
2332
2385
|
},
|
|
@@ -2338,19 +2391,23 @@ class BambuPrinterMCPServer {
|
|
|
2338
2391
|
properties: {
|
|
2339
2392
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2340
2393
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2341
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2394
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2395
|
+
connection_mode: { type: "string", enum: ["lan_mqtt_ftps", "bambu_network", "bambu_native"], description: "The connection the print used. Defaults to BAMBU_DEFAULT_CONNECTION_MODE, the same default print_3mf uses, else the model's route." },
|
|
2396
|
+
connection_type: { type: "string", enum: ["lan", "cloud"], description: "FULU BambuNetwork connection type the print used. Defaults to BAMBU_DEFAULT_CONNECTION_TYPE, as for print_3mf. Authenticated controls support lan." }
|
|
2342
2397
|
}
|
|
2343
2398
|
}
|
|
2344
2399
|
},
|
|
2345
2400
|
{
|
|
2346
2401
|
name: "resume_print",
|
|
2347
|
-
description: "Resume a paused job that this server inspected and started. It re-downloads the job's file over FTPS and compares its SHA-256, asks a person to confirm
|
|
2402
|
+
description: "Resume a paused job that this server inspected and started. It re-downloads the job's file over FTPS and compares its SHA-256, asks a person to confirm only when the file could not be re-read, and reads the printer again before sending. A job that was cancelled, ended or replaced is never resumed. Returns jobName and bytesVerified.",
|
|
2348
2403
|
inputSchema: {
|
|
2349
2404
|
type: "object",
|
|
2350
2405
|
properties: {
|
|
2351
2406
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2352
2407
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2353
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2408
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2409
|
+
connection_mode: { type: "string", enum: ["lan_mqtt_ftps", "bambu_network", "bambu_native"], description: "The connection the print used. Defaults to BAMBU_DEFAULT_CONNECTION_MODE, the same default print_3mf uses, else the model's route." },
|
|
2410
|
+
connection_type: { type: "string", enum: ["lan", "cloud"], description: "FULU BambuNetwork connection type the print used. Defaults to BAMBU_DEFAULT_CONNECTION_TYPE, as for print_3mf. Authenticated controls support lan." }
|
|
2354
2411
|
}
|
|
2355
2412
|
}
|
|
2356
2413
|
},
|
|
@@ -2556,6 +2613,7 @@ class BambuPrinterMCPServer {
|
|
|
2556
2613
|
type: "object",
|
|
2557
2614
|
properties: {
|
|
2558
2615
|
three_mf_path: { type: "string", description: "Path to the 3MF file to print" },
|
|
2616
|
+
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. Used when the 3MF has no G-code yet; a sliced 3MF must already carry these pauses, or it is refused." },
|
|
2559
2617
|
bambu_model: {
|
|
2560
2618
|
type: "string",
|
|
2561
2619
|
enum: [...VALID_BAMBU_MODELS],
|
|
@@ -2686,7 +2744,7 @@ class BambuPrinterMCPServer {
|
|
|
2686
2744
|
},
|
|
2687
2745
|
{
|
|
2688
2746
|
name: "lay_flat",
|
|
2689
|
-
description: "Rotate the model so
|
|
2747
|
+
description: "Rotate the model so a face rests on the bed (Z=0), choosing the orientation with the least part and support volume per mm² of bed contact. A face counts only if nothing hangs below it. Returns the new STL path; structuredContent.laid_flat is false, with the input path, when no orientation qualifies.",
|
|
2690
2748
|
inputSchema: {
|
|
2691
2749
|
type: "object",
|
|
2692
2750
|
properties: {
|
|
@@ -2762,6 +2820,17 @@ class BambuPrinterMCPServer {
|
|
|
2762
2820
|
outputSchema: PRINTER_INFO_OUTPUT_SCHEMA,
|
|
2763
2821
|
annotations: { readOnlyHint: true }
|
|
2764
2822
|
},
|
|
2823
|
+
{
|
|
2824
|
+
name: "counterpart_print_route",
|
|
2825
|
+
description: "Counterpart contract (counterpart/1): how this server reaches the printer for prints and for Stop/Pause/Resume. route is \"lan\" (the local network through FULU's BambuNetwork bridge, or the configured X2D native or Bambu Connect mode), \"cloud\" (Bambu Cloud through FULU's bridge) or \"developer\" (the local network straight to a printer in LAN Only + Developer Mode, whose Pause, Resume and Stop need no Bambu app). options lists each with its label, whether it can be chosen here (and why not) and what controls do on it; choices lists the ids that can be chosen. mode and type are BAMBU_DEFAULT_CONNECTION_MODE and BAMBU_DEFAULT_CONNECTION_TYPE as resolved. Pass route to change it: the change applies to the next print and control at once, and is saved to the .env file in this server's working directory when that file exists (savedTo; null otherwise). Sends nothing to the printer.",
|
|
2826
|
+
inputSchema: {
|
|
2827
|
+
type: "object",
|
|
2828
|
+
properties: {
|
|
2829
|
+
route: { type: "string", enum: ["lan", "cloud", "developer"], description: "Change the route. Omit to read it." }
|
|
2830
|
+
},
|
|
2831
|
+
additionalProperties: false
|
|
2832
|
+
}
|
|
2833
|
+
},
|
|
2765
2834
|
{
|
|
2766
2835
|
name: "counterpart_print_progress",
|
|
2767
2836
|
description: "Counterpart contract (counterpart/1): the printer's state, current job (name, task id, percent, time left, layers, stage words), temperatures, active filament and problems with Bambu's HMS messages and links. Read from the MQTT report this server keeps, so a held session asks the printer nothing; observedAt is when the printer sent it. An unreachable printer reports state offline. Read-only; not a safety check.",
|
|
@@ -2825,14 +2894,14 @@ class BambuPrinterMCPServer {
|
|
|
2825
2894
|
inputSchema: {
|
|
2826
2895
|
type: "object",
|
|
2827
2896
|
properties: {
|
|
2897
|
+
document_id: { type: "string", minLength: 1, description: "Session identity returned by a bound new design. Every operation targets this document, even if the user changes tabs." },
|
|
2828
2898
|
tool_name: { type: "string", description: "Exact tool name advertised by the Fusion MCP server." },
|
|
2829
2899
|
arguments: { type: "object", description: "Arguments matching the remote tool's discovered input schema." },
|
|
2830
2900
|
timeout_ms: { type: "integer", minimum: 100, maximum: 600000, description: "Total deadline in milliseconds; defaults to FUSION_MCP_TIMEOUT_MS or 180000." }
|
|
2831
2901
|
},
|
|
2832
2902
|
required: ["tool_name"],
|
|
2833
2903
|
additionalProperties: false
|
|
2834
|
-
}
|
|
2835
|
-
outputSchema: FUSION_CALL_OUTPUT_SCHEMA
|
|
2904
|
+
}
|
|
2836
2905
|
},
|
|
2837
2906
|
{
|
|
2838
2907
|
name: "fusion_mcp_new_design",
|
|
@@ -2840,6 +2909,8 @@ class BambuPrinterMCPServer {
|
|
|
2840
2909
|
inputSchema: {
|
|
2841
2910
|
type: "object",
|
|
2842
2911
|
properties: {
|
|
2912
|
+
bind_document: { type: "boolean", description: "Create an isolated document and return its session identity, restoring the previously active document. Requires document-binding support in the configured bridge/add-in." },
|
|
2913
|
+
source_f3d: { type: "string", description: "With bind_document, import this absolute F3D path into a new document for revision." },
|
|
2843
2914
|
timeout_ms: { type: "integer", minimum: 100, maximum: 600000, description: "Total deadline in milliseconds; defaults to FUSION_MCP_TIMEOUT_MS or 180000." }
|
|
2844
2915
|
},
|
|
2845
2916
|
additionalProperties: false
|
|
@@ -2852,6 +2923,7 @@ class BambuPrinterMCPServer {
|
|
|
2852
2923
|
inputSchema: {
|
|
2853
2924
|
type: "object",
|
|
2854
2925
|
properties: {
|
|
2926
|
+
document_id: { type: "string", minLength: 1, description: "Session identity returned by a bound new design. Every operation targets this document, even if the user changes tabs." },
|
|
2855
2927
|
output_dir: { type: "string", description: "Existing directory for the three files." },
|
|
2856
2928
|
name: { type: "string", description: "File name without extension, such as bracket." },
|
|
2857
2929
|
body_name: { type: "string", description: "The body to export as STL. Optional when the design has exactly one body." },
|
|
@@ -2910,6 +2982,30 @@ class BambuPrinterMCPServer {
|
|
|
2910
2982
|
// again once every older helper for this printer has exited, and only
|
|
2911
2983
|
// that send counts. Either counted route succeeding is success. macOS
|
|
2912
2984
|
// stays native-only.
|
|
2985
|
+
// Print controls go over the same connection as the print (resolveConnection).
|
|
2986
|
+
// undefined keeps the direct MQTT route in BambuImplementation.
|
|
2987
|
+
const printerControl = (command) => {
|
|
2988
|
+
const nativeCommand = (assertActive, beforeDispatch) => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
2989
|
+
messageJson: JSON.stringify({ print: { command, param: "", sequence_id: String(Date.now()) } }), qos: 1 }, command === "resume" ? { signal: extra.signal, assertActive, beforeDispatch } : undefined);
|
|
2990
|
+
// The selected route decides first: a job started over FULU's bridge (LAN or cloud) is controlled there,
|
|
2991
|
+
// even on an X2D whose native plug-in is installed. Otherwise an X2D uses its native route when it can.
|
|
2992
|
+
const route = resolveConnection(args);
|
|
2993
|
+
if (route.mode !== "bambu_network" && nativeControls()) {
|
|
2994
|
+
return command === "stop"
|
|
2995
|
+
? linuxEmergency(() => nativeCommand(), signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
2996
|
+
: nativeCommand;
|
|
2997
|
+
}
|
|
2998
|
+
if (route.mode === "bambu_native")
|
|
2999
|
+
throw new Error(nativeUnavailableReason());
|
|
3000
|
+
if (route.mode !== "bambu_network")
|
|
3001
|
+
return undefined;
|
|
3002
|
+
return (assertActive, beforeDispatch) => {
|
|
3003
|
+
const options = { assertDispatchAllowed: () => { extra.signal.throwIfAborted(); assertActive?.(); } };
|
|
3004
|
+
return route.type === "cloud"
|
|
3005
|
+
? this.bambuNetwork.sendCloudPrintCommand(bambuSerial, command, options, beforeDispatch)
|
|
3006
|
+
: this.bambuNetwork.sendLocalPrintCommand({ devId: bambuSerial, devIp: host, username: "bblp", password: bambuToken, useSsl: true }, command, options, beforeDispatch);
|
|
3007
|
+
};
|
|
3008
|
+
};
|
|
2913
3009
|
const linuxEmergency = (native, mqtt) => async () => {
|
|
2914
3010
|
if (process.platform !== "linux")
|
|
2915
3011
|
return native();
|
|
@@ -3079,6 +3175,23 @@ class BambuPrinterMCPServer {
|
|
|
3079
3175
|
result = await this.print3mfViaBambuNetwork(args, host, bambuSerial, bambuToken);
|
|
3080
3176
|
break;
|
|
3081
3177
|
}
|
|
3178
|
+
case "camera_stream_start":
|
|
3179
|
+
result = this.bambu.cameraStreamStart(host, bambuSerial, bambuToken, {
|
|
3180
|
+
bambuModel: args?.bambu_model ?? process.env.BAMBU_MODEL ?? process.env.BAMBU_PRINTER_MODEL,
|
|
3181
|
+
fps: args?.fps, idleTimeoutMs: args?.idle_timeout_ms,
|
|
3182
|
+
ffmpegPath: this.runtimeConfig.ffmpegPath,
|
|
3183
|
+
});
|
|
3184
|
+
break;
|
|
3185
|
+
case "camera_frame":
|
|
3186
|
+
result = await this.bambu.cameraStreamFrame(host, bambuSerial, {
|
|
3187
|
+
sinceSeq: args?.since_seq, waitMs: args?.wait_ms,
|
|
3188
|
+
maxWidth: args?.max_width, maxBytes: args?.max_bytes, changedOnly: args?.changed_only,
|
|
3189
|
+
minChange: args?.min_change, signal: extra.signal,
|
|
3190
|
+
});
|
|
3191
|
+
break;
|
|
3192
|
+
case "camera_stream_stop":
|
|
3193
|
+
result = this.bambu.cameraStreamStop(host, bambuSerial);
|
|
3194
|
+
break;
|
|
3082
3195
|
case "camera_snapshot": {
|
|
3083
3196
|
const snapshotModel = args?.bambu_model ?? process.env.BAMBU_MODEL ?? process.env.BAMBU_PRINTER_MODEL;
|
|
3084
3197
|
result = await this.bambu.cameraSnapshot(host, bambuSerial, bambuToken, {
|
|
@@ -3140,22 +3253,13 @@ class BambuPrinterMCPServer {
|
|
|
3140
3253
|
break;
|
|
3141
3254
|
}
|
|
3142
3255
|
case "cancel_print":
|
|
3143
|
-
result = await this.bambu.cancelJob(host, bambuSerial, bambuToken,
|
|
3144
|
-
? linuxEmergency(() => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3145
|
-
messageJson: JSON.stringify({ print: { command: "stop", param: "", sequence_id: String(Date.now()) } }), qos: 1 }), signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
3146
|
-
: undefined);
|
|
3256
|
+
result = await this.bambu.cancelJob(host, bambuSerial, bambuToken, printerControl("stop"));
|
|
3147
3257
|
break;
|
|
3148
3258
|
case "pause_print":
|
|
3149
|
-
result = await this.bambu.pauseJob(host, bambuSerial, bambuToken,
|
|
3150
|
-
? () => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3151
|
-
messageJson: JSON.stringify({ print: { command: "pause", param: "", sequence_id: String(Date.now()) } }), qos: 1 })
|
|
3152
|
-
: undefined);
|
|
3259
|
+
result = await this.bambu.pauseJob(host, bambuSerial, bambuToken, printerControl("pause"));
|
|
3153
3260
|
break;
|
|
3154
3261
|
case "resume_print":
|
|
3155
|
-
result = await this.bambu.resumeJob(host, bambuSerial, bambuToken,
|
|
3156
|
-
? (assertActive, beforeDispatch) => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3157
|
-
messageJson: JSON.stringify({ print: { command: "resume", param: "", sequence_id: String(Date.now()) } }), qos: 1 }, { signal: extra.signal, assertActive, beforeDispatch })
|
|
3158
|
-
: undefined);
|
|
3262
|
+
result = await this.bambu.resumeJob(host, bambuSerial, bambuToken, printerControl("resume"));
|
|
3159
3263
|
break;
|
|
3160
3264
|
case "x2d_native_control": {
|
|
3161
3265
|
if (!args?.message_json) {
|
|
@@ -3507,6 +3611,11 @@ class BambuPrinterMCPServer {
|
|
|
3507
3611
|
sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
|
|
3508
3612
|
if (args?.slice_plate !== undefined)
|
|
3509
3613
|
sliceBambuOptions.slicePlate = Number(args.slice_plate);
|
|
3614
|
+
{
|
|
3615
|
+
const pauses = parsePauseLayers(args?.pause_at_layers);
|
|
3616
|
+
if (pauses)
|
|
3617
|
+
sliceBambuOptions.pauseAtLayers = pauses;
|
|
3618
|
+
}
|
|
3510
3619
|
const usePrinterFilaments = args?.use_printer_filaments !== undefined ? Boolean(args.use_printer_filaments) : true;
|
|
3511
3620
|
if (usePrinterFilaments &&
|
|
3512
3621
|
!explicitSlicerProfile &&
|
|
@@ -3588,6 +3697,11 @@ class BambuPrinterMCPServer {
|
|
|
3588
3697
|
sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
|
|
3589
3698
|
if (args?.slice_plate !== undefined)
|
|
3590
3699
|
sliceBambuOptions.slicePlate = Number(args.slice_plate);
|
|
3700
|
+
{
|
|
3701
|
+
const pauses = parsePauseLayers(args?.pause_at_layers);
|
|
3702
|
+
if (pauses)
|
|
3703
|
+
sliceBambuOptions.pauseAtLayers = pauses;
|
|
3704
|
+
}
|
|
3591
3705
|
const processOverrides = parseProcessOverrides(args, Number(nozzleDiam));
|
|
3592
3706
|
if (processOverrides)
|
|
3593
3707
|
sliceBambuOptions.processOverrides = processOverrides;
|
|
@@ -3611,9 +3725,11 @@ class BambuPrinterMCPServer {
|
|
|
3611
3725
|
console.warn("Could not resolve live printer filaments for slicing:", filamentError);
|
|
3612
3726
|
}
|
|
3613
3727
|
}
|
|
3614
|
-
|
|
3728
|
+
const sliced = await this.stlManipulator.sliceSTLWithResult(String(args.stl_path), slicerType, slicerPath, activeSlicerProfile, undefined, // progressCallback
|
|
3615
3729
|
printerPreset, sliceBambuOptions);
|
|
3616
|
-
|
|
3730
|
+
await progressNotifications;
|
|
3731
|
+
// The text stays the sliced file's path; slicer_result is the slicer's own result.json, verbatim.
|
|
3732
|
+
return { content: [{ type: "text", text: sliced.path }], structuredContent: sliced };
|
|
3617
3733
|
}
|
|
3618
3734
|
case "print_3mf": {
|
|
3619
3735
|
if (!args?.three_mf_path) {
|
|
@@ -3622,11 +3738,7 @@ class BambuPrinterMCPServer {
|
|
|
3622
3738
|
const printModel = await this.resolveBambuModel(args.bambu_model);
|
|
3623
3739
|
const resolvedArgs = { ...args, bambu_model: printModel };
|
|
3624
3740
|
const requestedModel = printModel;
|
|
3625
|
-
const
|
|
3626
|
-
(requestedModel === "x2d" ? "bambu_native" : "lan_mqtt_ftps");
|
|
3627
|
-
const connectionMode = String(args?.connection_mode || defaultConnectionMode).trim().toLowerCase();
|
|
3628
|
-
if (!["lan_mqtt_ftps", "bambu_native", "bambu_network", "bambu_connect"].includes(connectionMode))
|
|
3629
|
-
throw new Error("Unsupported connection_mode.");
|
|
3741
|
+
const connectionMode = resolveConnection(args, requestedModel).mode;
|
|
3630
3742
|
// X2D firmware accepts the Bambu Studio :6000/eMMC route but
|
|
3631
3743
|
// rejects the legacy direct FTPS STOR operation with 553. Keep
|
|
3632
3744
|
// an explicit old-mode request from re-entering that known-bad
|
|
@@ -3667,6 +3779,16 @@ class BambuPrinterMCPServer {
|
|
|
3667
3779
|
const zipData = fs.readFileSync(threeMFPath);
|
|
3668
3780
|
const zip = await JSZip.loadAsync(zipData);
|
|
3669
3781
|
const hasGcode = Object.values(zip.files).some(entry => !entry.dir && /\.gcode$/i.test(entry.name));
|
|
3782
|
+
const pauseLayers = parsePauseLayers(args?.pause_at_layers);
|
|
3783
|
+
if (hasGcode && pauseLayers) {
|
|
3784
|
+
// Already sliced: its G-code is what prints, so the pauses must already be in it.
|
|
3785
|
+
const gcode = await readPlateGcode(threeMFPath, Number(args?.plate_index ?? 0) + 1);
|
|
3786
|
+
const placed = gcode ? pausedLayers(gcode, machinePauseGcode(gcode)) : [];
|
|
3787
|
+
const missing = pauseLayers.filter(layer => !placed.includes(layer));
|
|
3788
|
+
if (missing.length) {
|
|
3789
|
+
throw new Error(`This 3MF is already sliced without a pause before layer ${missing.join(", ")}. Slice it again with pause_at_layers (slice_stl), or add the pause in Bambu Studio or OrcaSlicer.`);
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3670
3792
|
if (!hasGcode) {
|
|
3671
3793
|
assertUniformCliNozzles(args);
|
|
3672
3794
|
if (printBedType === "supertack_plate") {
|
|
@@ -3680,6 +3802,7 @@ class BambuPrinterMCPServer {
|
|
|
3680
3802
|
bedType: printBedType,
|
|
3681
3803
|
nozzleType: resolveNozzleType(args?.nozzle_type),
|
|
3682
3804
|
nozzleVolumeType: resolveNozzleVolumeType(args?.nozzle_volume_type),
|
|
3805
|
+
...(pauseLayers ? { pauseAtLayers: pauseLayers } : {}),
|
|
3683
3806
|
};
|
|
3684
3807
|
if (!explicitSlicerProfile) {
|
|
3685
3808
|
try {
|
|
@@ -3853,11 +3976,14 @@ class BambuPrinterMCPServer {
|
|
|
3853
3976
|
throw new Error("Missing required parameter: stl_path");
|
|
3854
3977
|
result = await this.stlManipulator.centerModel(String(args.stl_path));
|
|
3855
3978
|
break;
|
|
3856
|
-
case "lay_flat":
|
|
3979
|
+
case "lay_flat": {
|
|
3857
3980
|
if (!args?.stl_path)
|
|
3858
3981
|
throw new Error("Missing required parameter: stl_path");
|
|
3859
|
-
|
|
3860
|
-
|
|
3982
|
+
const layFlatResult = await this.stlManipulator.layFlatWithResult(String(args.stl_path));
|
|
3983
|
+
await progressNotifications;
|
|
3984
|
+
// The text stays the STL path clients read; structuredContent says whether it was laid flat.
|
|
3985
|
+
return { content: [{ type: "text", text: layFlatResult.path }], structuredContent: layFlatResult };
|
|
3986
|
+
}
|
|
3861
3987
|
case "blender_mcp_status":
|
|
3862
3988
|
result = await this.blender.status(args ?? {}, extra.signal);
|
|
3863
3989
|
break;
|
|
@@ -3869,6 +3995,36 @@ class BambuPrinterMCPServer {
|
|
|
3869
3995
|
case "counterpart_printer_info":
|
|
3870
3996
|
result = bambuPrinterInfo({ server: SERVER_INFO, host, serial: bambuSerial, model: this.displayModel(args, bambuSerial) });
|
|
3871
3997
|
break;
|
|
3998
|
+
case "counterpart_print_route": {
|
|
3999
|
+
let savedTo = null;
|
|
4000
|
+
// FULU's bridge is set up, so the routes through it can be used.
|
|
4001
|
+
const bridgeConfigured = Boolean(this.bambuNetwork.resolveBridgeCommand());
|
|
4002
|
+
const routeModel = this.displayModel(args, bambuSerial);
|
|
4003
|
+
// The printer's own local route (X2D native by default, or a configured native/Bambu Connect mode),
|
|
4004
|
+
// resolved from the start-up configuration so it survives choosing another route.
|
|
4005
|
+
const ownLocal = ownLocalOf({ mode: CONFIGURED_CONNECTION.mode || (routeModel === "x2d" ? "bambu_native" : ""), type: CONFIGURED_CONNECTION.type || "lan" });
|
|
4006
|
+
if (args?.route !== undefined) {
|
|
4007
|
+
if (!PRINT_ROUTES.includes(args.route))
|
|
4008
|
+
throw new Error('route must be "lan", "cloud" or "developer".');
|
|
4009
|
+
const next = connectionForRoute(args.route, resolveConnection({}, routeModel), bridgeConfigured, ownLocal);
|
|
4010
|
+
// dotenv loaded .env from the working directory at start; a client's own env block has no file to update.
|
|
4011
|
+
const file = path.resolve(process.cwd(), ".env");
|
|
4012
|
+
if (fs.existsSync(file)) {
|
|
4013
|
+
writeEnvValues(file, {
|
|
4014
|
+
...(next.mode ? { BAMBU_DEFAULT_CONNECTION_MODE: next.mode } : {}),
|
|
4015
|
+
...(next.type ? { BAMBU_DEFAULT_CONNECTION_TYPE: next.type } : {}),
|
|
4016
|
+
});
|
|
4017
|
+
savedTo = file;
|
|
4018
|
+
}
|
|
4019
|
+
DEFAULT_BAMBU_CONNECTION_MODE = next.mode;
|
|
4020
|
+
DEFAULT_BAMBU_CONNECTION_TYPE = next.type;
|
|
4021
|
+
}
|
|
4022
|
+
const connection = resolveConnection({}, routeModel);
|
|
4023
|
+
const options = routeOptions(connection, bridgeConfigured, ownLocal);
|
|
4024
|
+
result = { route: routeOf(connection), mode: connection.mode, type: connection.type,
|
|
4025
|
+
choices: options.filter(option => option.available).map(option => option.id), options, savedTo };
|
|
4026
|
+
break;
|
|
4027
|
+
}
|
|
3872
4028
|
case "counterpart_print_progress": {
|
|
3873
4029
|
const report = await this.bambu.readProgressReport(host, bambuSerial, bambuToken);
|
|
3874
4030
|
result = report
|
|
@@ -3883,9 +4039,9 @@ class BambuPrinterMCPServer {
|
|
|
3883
4039
|
result = await this.fusion.status(args ?? {}, extra.signal);
|
|
3884
4040
|
break;
|
|
3885
4041
|
case "fusion_mcp_call": {
|
|
3886
|
-
//
|
|
3887
|
-
|
|
3888
|
-
return
|
|
4042
|
+
// Preserve polymorphic text/images/errors. An invented empty structured result
|
|
4043
|
+
// masks useful text in clients that prefer structuredContent.
|
|
4044
|
+
return await this.fusion.call(args ?? {}, extra.signal);
|
|
3889
4045
|
}
|
|
3890
4046
|
case "fusion_mcp_new_design":
|
|
3891
4047
|
result = await this.fusion.newDesign(args ?? {}, extra.signal);
|
|
@@ -3897,7 +4053,11 @@ class BambuPrinterMCPServer {
|
|
|
3897
4053
|
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
3898
4054
|
}
|
|
3899
4055
|
await progressNotifications;
|
|
3900
|
-
|
|
4056
|
+
// A stream image belongs in structuredContent once. Repeating its base64 in text
|
|
4057
|
+
// doubles the wire budget; text-only clients still receive useful frame metadata.
|
|
4058
|
+
const textResult = name === "camera_frame" && result && typeof result === "object"
|
|
4059
|
+
? Object.fromEntries(Object.entries(result).filter(([key]) => key !== "base64")) : result;
|
|
4060
|
+
const text = typeof textResult === "string" ? textResult : JSON.stringify(textResult, null, 2);
|
|
3901
4061
|
// A declared outputSchema obliges structuredContent whatever MCP_HTTP_JSON_RESPONSE says.
|
|
3902
4062
|
if ((this.runtimeConfig.enableJsonResponse || OUTPUT_SCHEMA_TOOLS.has(name)) && typeof result === "object") {
|
|
3903
4063
|
return {
|
|
@@ -3919,11 +4079,14 @@ class BambuPrinterMCPServer {
|
|
|
3919
4079
|
: `Check parameters and try again. Error: ${message}`,
|
|
3920
4080
|
message,
|
|
3921
4081
|
tool: name,
|
|
4082
|
+
// The slicer's own result.json; the message starts with its error_string and warnings.
|
|
4083
|
+
...(error instanceof SlicerRunError && error.slicerResult ? { slicer_result: error.slicerResult } : {}),
|
|
3922
4084
|
};
|
|
3923
4085
|
// MCP clients validate structuredContent against a declared outputSchema even on
|
|
3924
4086
|
// errors (SDK 1.32 Client.callTool), so those tools return the error as text only.
|
|
3925
4087
|
return {
|
|
3926
|
-
|
|
4088
|
+
// A slicer failure leads with the slicer's own words.
|
|
4089
|
+
content: [{ type: "text", text: error instanceof SlicerRunError && error.slicerText ? message : `Error: ${message}` }],
|
|
3927
4090
|
...(OUTPUT_SCHEMA_TOOLS.has(name) ? {} : { structuredContent: structured }),
|
|
3928
4091
|
isError: true,
|
|
3929
4092
|
};
|
|
@@ -3941,6 +4104,8 @@ class BambuPrinterMCPServer {
|
|
|
3941
4104
|
return;
|
|
3942
4105
|
this.shuttingDown = true;
|
|
3943
4106
|
try {
|
|
4107
|
+
// Close camera sockets/processes first, waking any waiting frame requests.
|
|
4108
|
+
this.bambu.cameraStreams.stopAll();
|
|
3944
4109
|
// Closing the MCP transport aborts its active requests before exit cleanup.
|
|
3945
4110
|
await this.server.close();
|
|
3946
4111
|
await this.fusion.close();
|