bambu-printer-mcp 1.1.51 → 1.1.53
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 +206 -51
- 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 +3 -0
- package/dist/stl/stl-manipulator.js +50 -4
- package/dist/tool-annotations.d.ts +25 -0
- package/dist/tool-annotations.js +96 -0
- 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 +199 -55
- 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 +58 -5
- package/src/tool-annotations.ts +126 -0
package/src/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {CAMERA_STREAM_TOOLS} from "./printers/camera-tools.js";
|
|
3
|
+
import { withAnnotations } from "./tool-annotations.js";
|
|
2
4
|
|
|
3
5
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
6
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -8,10 +10,13 @@ import {
|
|
|
8
10
|
ReadResourceRequestSchema,
|
|
9
11
|
ListToolsRequestSchema,
|
|
10
12
|
CallToolRequestSchema,
|
|
13
|
+
ListPromptsRequestSchema,
|
|
14
|
+
GetPromptRequestSchema,
|
|
11
15
|
ErrorCode,
|
|
12
16
|
McpError
|
|
13
17
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
14
18
|
import dotenv from "dotenv";
|
|
19
|
+
import { PRINT_ROUTES, connectionForRoute, ownLocalOf, routeOf, routeOptions, writeEnvValues, type PrintRoute } from "./counterpart/route.js";
|
|
15
20
|
import fs from "fs";
|
|
16
21
|
import os from "node:os";
|
|
17
22
|
import path from "path";
|
|
@@ -41,11 +46,11 @@ import {
|
|
|
41
46
|
} from "./bambu-native.js";
|
|
42
47
|
import { importFileViaBambuConnect } from "./bambu-connect.js";
|
|
43
48
|
import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
|
|
44
|
-
import {
|
|
45
|
-
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue } from "./ams-mapping.js";
|
|
49
|
+
import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
|
|
50
|
+
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
|
|
46
51
|
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, parse3MF } from './3mf_parser.js';
|
|
47
52
|
import type { ThreeMFAmsRequirements } from "./types.js";
|
|
48
|
-
import { BambuImplementation, assertDirectPrintSupported, checkedFile } from "./printers/bambu.js";
|
|
53
|
+
import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
|
|
49
54
|
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "./studio-print-options.js";
|
|
50
55
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
51
56
|
import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
@@ -53,10 +58,12 @@ import { isDualNozzleModel } from "./safety/limits.js";
|
|
|
53
58
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName } from "./safety/artifact.js";
|
|
54
59
|
import { detectProfilesRoot } from "./slicer/profile-flatten.js";
|
|
55
60
|
import { bambuPrinterInfo } from "./counterpart/info.js";
|
|
61
|
+
import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_CAPABILITY_URI, SERVER_INSTRUCTIONS } from "./design-guidance.js";
|
|
56
62
|
import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
57
63
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
58
64
|
import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
|
|
59
65
|
import { parseProcessOverrides } from "./slicer/process-overrides.js";
|
|
66
|
+
import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
|
|
60
67
|
|
|
61
68
|
dotenv.config();
|
|
62
69
|
|
|
@@ -91,8 +98,29 @@ const DEFAULT_BAMBU_MODEL =
|
|
|
91
98
|
process.env.BAMBU_PRINTER_MODEL?.trim().toLowerCase() ||
|
|
92
99
|
process.env.BAMBU_MODEL?.trim().toLowerCase() ||
|
|
93
100
|
"";
|
|
94
|
-
|
|
101
|
+
// counterpart_print_route changes these at run time (and in the .env file they came from).
|
|
102
|
+
let DEFAULT_BAMBU_CONNECTION_MODE =
|
|
95
103
|
process.env.BAMBU_DEFAULT_CONNECTION_MODE?.trim().toLowerCase() || "";
|
|
104
|
+
let DEFAULT_BAMBU_CONNECTION_TYPE =
|
|
105
|
+
process.env.BAMBU_DEFAULT_CONNECTION_TYPE?.trim().toLowerCase() || "";
|
|
106
|
+
/** The connection configured at start, before counterpart_print_route changes it: its own local route is kept. */
|
|
107
|
+
const CONFIGURED_CONNECTION = { mode: DEFAULT_BAMBU_CONNECTION_MODE, type: DEFAULT_BAMBU_CONNECTION_TYPE };
|
|
108
|
+
const CONNECTION_MODES = ["lan_mqtt_ftps", "bambu_native", "bambu_network", "bambu_connect"];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The one route decision for a printer: print_3mf and every print control
|
|
112
|
+
* (cancel, pause, resume) resolve it here, so a job is never controlled over a
|
|
113
|
+
* different connection than the one that started it. Arguments override the
|
|
114
|
+
* server's configured defaults; without either, X2D uses its native route and
|
|
115
|
+
* every other model direct LAN MQTT/FTPS.
|
|
116
|
+
*/
|
|
117
|
+
function resolveConnection(args: Record<string, unknown> | undefined, model?: string): { mode: string; type: string } {
|
|
118
|
+
const mode = String(args?.connection_mode || DEFAULT_BAMBU_CONNECTION_MODE || (model === "x2d" ? "bambu_native" : "lan_mqtt_ftps")).trim().toLowerCase();
|
|
119
|
+
if (!CONNECTION_MODES.includes(mode)) throw new Error("Unsupported connection_mode.");
|
|
120
|
+
const type = String(args?.connection_type || DEFAULT_BAMBU_CONNECTION_TYPE || "cloud").trim().toLowerCase();
|
|
121
|
+
if (!["cloud", "lan"].includes(type)) throw new Error('connection_type must be "cloud" or "lan".');
|
|
122
|
+
return { mode, type };
|
|
123
|
+
}
|
|
96
124
|
const DEFAULT_BED_TYPE = process.env.BED_TYPE?.trim().toLowerCase() || "textured_plate";
|
|
97
125
|
const DEFAULT_NOZZLE_DIAMETER = process.env.NOZZLE_DIAMETER?.trim() || "0.4";
|
|
98
126
|
/** MCP initialize name/version; counterpart_printer_info reports the same values. */
|
|
@@ -103,7 +131,8 @@ const SERVER_INFO = {
|
|
|
103
131
|
/** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
|
|
104
132
|
const OUTPUT_SCHEMA_TOOLS = new Set([
|
|
105
133
|
"counterpart_printer_info", "counterpart_print_progress", "counterpart_make_3mf",
|
|
106
|
-
"fusion_mcp_status", "
|
|
134
|
+
"fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
|
|
135
|
+
"camera_stream_start", "camera_frame", "camera_stream_stop",
|
|
107
136
|
]);
|
|
108
137
|
|
|
109
138
|
/** Bound for each Linux X2D emergency MQTT send (BAMBU_EMERGENCY_MQTT_TIMEOUT_MS, 1–60000 ms). */
|
|
@@ -1256,9 +1285,11 @@ class BambuPrinterMCPServer {
|
|
|
1256
1285
|
SERVER_INFO,
|
|
1257
1286
|
{
|
|
1258
1287
|
capabilities: {
|
|
1288
|
+
prompts: {},
|
|
1259
1289
|
resources: {},
|
|
1260
1290
|
tools: {}
|
|
1261
|
-
}
|
|
1291
|
+
},
|
|
1292
|
+
instructions: SERVER_INSTRUCTIONS
|
|
1262
1293
|
}
|
|
1263
1294
|
);
|
|
1264
1295
|
|
|
@@ -1282,11 +1313,11 @@ class BambuPrinterMCPServer {
|
|
|
1282
1313
|
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.`);
|
|
1283
1314
|
}
|
|
1284
1315
|
if (isElicitationUnsupported(error)) {
|
|
1285
|
-
throw new Error("Human hardware confirmation requires an MCP client with elicitation support.
|
|
1316
|
+
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.");
|
|
1286
1317
|
}
|
|
1287
1318
|
throw new Error(`Human hardware confirmation failed: ${error?.message ?? error}. Nothing was sent to the printer.`);
|
|
1288
1319
|
}
|
|
1289
|
-
});
|
|
1320
|
+
}, { resumeStateDir: defaultResumeStateDir() });
|
|
1290
1321
|
this.bambuNetwork = new BambuNetworkBridge();
|
|
1291
1322
|
this.stlManipulator = new STLManipulator(TEMP_DIR);
|
|
1292
1323
|
|
|
@@ -1302,6 +1333,7 @@ class BambuPrinterMCPServer {
|
|
|
1302
1333
|
|
|
1303
1334
|
setupHandlers() {
|
|
1304
1335
|
this.setupResourceHandlers();
|
|
1336
|
+
this.setupPromptHandlers();
|
|
1305
1337
|
this.setupToolHandlers();
|
|
1306
1338
|
}
|
|
1307
1339
|
|
|
@@ -1611,10 +1643,7 @@ class BambuPrinterMCPServer {
|
|
|
1611
1643
|
throw new Error("plate_index must be a non-negative integer.");
|
|
1612
1644
|
}
|
|
1613
1645
|
|
|
1614
|
-
const connectionType =
|
|
1615
|
-
if (!["cloud", "lan"].includes(connectionType)) {
|
|
1616
|
-
throw new Error('connection_type must be "cloud" or "lan".');
|
|
1617
|
-
}
|
|
1646
|
+
const connectionType = resolveConnection(args).type;
|
|
1618
1647
|
|
|
1619
1648
|
const bridgePrintMethod = resolveBambuNetworkPrintMethod(
|
|
1620
1649
|
args?.bambu_network_method !== undefined ? String(args.bambu_network_method) : undefined,
|
|
@@ -1721,7 +1750,10 @@ class BambuPrinterMCPServer {
|
|
|
1721
1750
|
nozzle_mapping: stringifyBridgeJson(args?.nozzle_mapping) || "",
|
|
1722
1751
|
ams_mapping: amsMapping || "",
|
|
1723
1752
|
ams_mapping2: nativeAmsMapping2(mapping, isDualNozzleModel(printModel)) || "",
|
|
1724
|
-
|
|
1753
|
+
// Bambu Studio and FULU's slicer send this with every job (get_ams_mapping_result).
|
|
1754
|
+
ams_mapping_info: mapping && inspection.projectFilaments?.length
|
|
1755
|
+
? JSON.stringify(studioAmsMappingInfo(inspection.projectFilaments, mapping, tray => trayColour(confirmedStatus.raw, tray)))
|
|
1756
|
+
: "",
|
|
1725
1757
|
nozzles_info: stringifyBridgeJson(args?.nozzles_info) || "",
|
|
1726
1758
|
connection_type: connectionType,
|
|
1727
1759
|
comments: String(args?.comments || ""),
|
|
@@ -1813,7 +1845,7 @@ class BambuPrinterMCPServer {
|
|
|
1813
1845
|
assertActive
|
|
1814
1846
|
));
|
|
1815
1847
|
} else {
|
|
1816
|
-
bridgeResult = await this.bambuNetwork.
|
|
1848
|
+
({ result: bridgeResult, jobUpdates } = await this.bambuNetwork.startCloudPrint(devId, bridgeMethod, { client_job_id: clientJobId, params }, bridgeOptions, assertActive));
|
|
1817
1849
|
}
|
|
1818
1850
|
|
|
1819
1851
|
if (typeof bridgeResult === "object" && bridgeResult !== null && (bridgeResult as { ok?: unknown }).ok === false) {
|
|
@@ -2197,6 +2229,21 @@ class BambuPrinterMCPServer {
|
|
|
2197
2229
|
};
|
|
2198
2230
|
}
|
|
2199
2231
|
|
|
2232
|
+
/** The FDM design guidance as MCP prompts: the client decides when to attach each one. */
|
|
2233
|
+
setupPromptHandlers() {
|
|
2234
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
2235
|
+
prompts: DESIGN_PROMPTS.map(({ name, title, description }) => ({ name, title, description })),
|
|
2236
|
+
}));
|
|
2237
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
2238
|
+
const prompt = DESIGN_PROMPTS.find(item => item.name === request.params.name);
|
|
2239
|
+
if (!prompt) throw new McpError(ErrorCode.InvalidParams, `Unknown prompt: ${request.params.name}`);
|
|
2240
|
+
return {
|
|
2241
|
+
description: prompt.description,
|
|
2242
|
+
messages: [{ role: "user" as const, content: { type: "text" as const, text: prompt.text } }],
|
|
2243
|
+
};
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2200
2247
|
setupResourceHandlers() {
|
|
2201
2248
|
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
2202
2249
|
return {
|
|
@@ -2218,7 +2265,8 @@ class BambuPrinterMCPServer {
|
|
|
2218
2265
|
name: "Bambu Printer HMS Diagnostics",
|
|
2219
2266
|
mimeType: "application/json",
|
|
2220
2267
|
description: "HMS and error-related fields from the latest printer status"
|
|
2221
|
-
}
|
|
2268
|
+
},
|
|
2269
|
+
FDM_CAPABILITY_RESOURCE
|
|
2222
2270
|
],
|
|
2223
2271
|
templates: [
|
|
2224
2272
|
{
|
|
@@ -2242,6 +2290,9 @@ class BambuPrinterMCPServer {
|
|
|
2242
2290
|
|
|
2243
2291
|
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
2244
2292
|
const uri = request.params.uri;
|
|
2293
|
+
if (uri === FDM_CAPABILITY_URI) {
|
|
2294
|
+
return { contents: [{ uri, mimeType: FDM_CAPABILITY_RESOURCE.mimeType, text: FDM_CAPABILITY_GUIDANCE }] };
|
|
2295
|
+
}
|
|
2245
2296
|
const match = uri.match(/^printer:\/\/([^\/]+)\/(.+)$/);
|
|
2246
2297
|
|
|
2247
2298
|
if (!match) {
|
|
@@ -2528,13 +2579,14 @@ class BambuPrinterMCPServer {
|
|
|
2528
2579
|
ensure_on_bed: { type: "boolean", description: "Lift floating models onto the bed." },
|
|
2529
2580
|
arrange: { type: "boolean", description: "Auto-arrange objects on the build plate." },
|
|
2530
2581
|
orient: { type: "boolean", description: "Auto-orient model for optimal printability." },
|
|
2531
|
-
repetitions: { type: "number", description: "
|
|
2582
|
+
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." },
|
|
2532
2583
|
scale: { type: "number", description: "Uniform scale factor." },
|
|
2533
2584
|
rotate: { type: "number", description: "Z-axis rotation in degrees." },
|
|
2534
2585
|
rotate_x: { type: "number", description: "X-axis rotation in degrees." },
|
|
2535
2586
|
rotate_y: { type: "number", description: "Y-axis rotation in degrees." },
|
|
2536
2587
|
min_save: { type: "boolean", description: "Produce smaller output 3MF." },
|
|
2537
2588
|
skip_modified_gcodes: { type: "boolean", description: "Ignore stale custom gcodes in the 3MF." },
|
|
2589
|
+
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." },
|
|
2538
2590
|
slice_plate: { type: "number", description: "Which plate index to slice. 0 = all plates." }
|
|
2539
2591
|
},
|
|
2540
2592
|
required: ["stl_path", "template_name", "bambu_model"]
|
|
@@ -2580,7 +2632,7 @@ class BambuPrinterMCPServer {
|
|
|
2580
2632
|
},
|
|
2581
2633
|
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." },
|
|
2582
2634
|
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." },
|
|
2583
|
-
repetitions: { type: "number", description: "
|
|
2635
|
+
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." },
|
|
2584
2636
|
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." },
|
|
2585
2637
|
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." },
|
|
2586
2638
|
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." },
|
|
@@ -2598,6 +2650,7 @@ class BambuPrinterMCPServer {
|
|
|
2598
2650
|
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." },
|
|
2599
2651
|
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." },
|
|
2600
2652
|
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." },
|
|
2653
|
+
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." },
|
|
2601
2654
|
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." },
|
|
2602
2655
|
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." },
|
|
2603
2656
|
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." },
|
|
@@ -2726,6 +2779,7 @@ class BambuPrinterMCPServer {
|
|
|
2726
2779
|
required: ["three_mf_path", "bambu_model"]
|
|
2727
2780
|
}
|
|
2728
2781
|
},
|
|
2782
|
+
...CAMERA_STREAM_TOOLS,
|
|
2729
2783
|
{
|
|
2730
2784
|
name: "camera_snapshot",
|
|
2731
2785
|
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.",
|
|
@@ -2857,7 +2911,9 @@ class BambuPrinterMCPServer {
|
|
|
2857
2911
|
properties: {
|
|
2858
2912
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2859
2913
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2860
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2914
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2915
|
+
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." },
|
|
2916
|
+
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." }
|
|
2861
2917
|
}
|
|
2862
2918
|
}
|
|
2863
2919
|
},
|
|
@@ -2869,19 +2925,23 @@ class BambuPrinterMCPServer {
|
|
|
2869
2925
|
properties: {
|
|
2870
2926
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2871
2927
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2872
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2928
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2929
|
+
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." },
|
|
2930
|
+
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." }
|
|
2873
2931
|
}
|
|
2874
2932
|
}
|
|
2875
2933
|
},
|
|
2876
2934
|
{
|
|
2877
2935
|
name: "resume_print",
|
|
2878
|
-
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
|
|
2936
|
+
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.",
|
|
2879
2937
|
inputSchema: {
|
|
2880
2938
|
type: "object",
|
|
2881
2939
|
properties: {
|
|
2882
2940
|
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
2883
2941
|
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
2884
|
-
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
2942
|
+
bambu_token: { type: "string", description: "Access token (default: value from env)" },
|
|
2943
|
+
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." },
|
|
2944
|
+
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." }
|
|
2885
2945
|
}
|
|
2886
2946
|
}
|
|
2887
2947
|
},
|
|
@@ -3066,7 +3126,6 @@ class BambuPrinterMCPServer {
|
|
|
3066
3126
|
{
|
|
3067
3127
|
name: "inspect_print_file",
|
|
3068
3128
|
description: "Inspect an exact private snapshot of a prepared sliced 3MF or textual G-code file and selected plate without contacting a printer. Returns versioned file-only evidence; no printer readiness or permission to dispatch is established. Does not auto-slice.",
|
|
3069
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
3070
3129
|
inputSchema: {
|
|
3071
3130
|
type: "object",
|
|
3072
3131
|
additionalProperties: false,
|
|
@@ -3087,6 +3146,7 @@ class BambuPrinterMCPServer {
|
|
|
3087
3146
|
type: "object",
|
|
3088
3147
|
properties: {
|
|
3089
3148
|
three_mf_path: { type: "string", description: "Path to the 3MF file to print" },
|
|
3149
|
+
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." },
|
|
3090
3150
|
bambu_model: {
|
|
3091
3151
|
type: "string",
|
|
3092
3152
|
enum: [...VALID_BAMBU_MODELS],
|
|
@@ -3290,8 +3350,18 @@ class BambuPrinterMCPServer {
|
|
|
3290
3350
|
bambu_token: { type: "string", description: "Access token (default: value from env); never returned." }
|
|
3291
3351
|
}
|
|
3292
3352
|
},
|
|
3293
|
-
outputSchema: PRINTER_INFO_OUTPUT_SCHEMA
|
|
3294
|
-
|
|
3353
|
+
outputSchema: PRINTER_INFO_OUTPUT_SCHEMA
|
|
3354
|
+
},
|
|
3355
|
+
{
|
|
3356
|
+
name: "counterpart_print_route",
|
|
3357
|
+
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.",
|
|
3358
|
+
inputSchema: {
|
|
3359
|
+
type: "object",
|
|
3360
|
+
properties: {
|
|
3361
|
+
route: { type: "string", enum: ["lan", "cloud", "developer"], description: "Change the route. Omit to read it." }
|
|
3362
|
+
},
|
|
3363
|
+
additionalProperties: false
|
|
3364
|
+
}
|
|
3295
3365
|
},
|
|
3296
3366
|
{
|
|
3297
3367
|
name: "counterpart_print_progress",
|
|
@@ -3305,8 +3375,7 @@ class BambuPrinterMCPServer {
|
|
|
3305
3375
|
bambu_token: { type: "string", description: "Access token (default: value from env)" }
|
|
3306
3376
|
}
|
|
3307
3377
|
},
|
|
3308
|
-
outputSchema: PRINT_PROGRESS_OUTPUT_SCHEMA
|
|
3309
|
-
annotations: { readOnlyHint: true }
|
|
3378
|
+
outputSchema: PRINT_PROGRESS_OUTPUT_SCHEMA
|
|
3310
3379
|
},
|
|
3311
3380
|
{
|
|
3312
3381
|
name: "counterpart_make_3mf",
|
|
@@ -3356,14 +3425,14 @@ class BambuPrinterMCPServer {
|
|
|
3356
3425
|
inputSchema: {
|
|
3357
3426
|
type: "object",
|
|
3358
3427
|
properties: {
|
|
3428
|
+
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." },
|
|
3359
3429
|
tool_name: { type: "string", description: "Exact tool name advertised by the Fusion MCP server." },
|
|
3360
3430
|
arguments: { type: "object", description: "Arguments matching the remote tool's discovered input schema." },
|
|
3361
3431
|
timeout_ms: { type: "integer", minimum: 100, maximum: 600000, description: "Total deadline in milliseconds; defaults to FUSION_MCP_TIMEOUT_MS or 180000." }
|
|
3362
3432
|
},
|
|
3363
3433
|
required: ["tool_name"],
|
|
3364
3434
|
additionalProperties: false
|
|
3365
|
-
}
|
|
3366
|
-
outputSchema: FUSION_CALL_OUTPUT_SCHEMA
|
|
3435
|
+
}
|
|
3367
3436
|
},
|
|
3368
3437
|
{
|
|
3369
3438
|
name: "fusion_mcp_new_design",
|
|
@@ -3371,6 +3440,8 @@ class BambuPrinterMCPServer {
|
|
|
3371
3440
|
inputSchema: {
|
|
3372
3441
|
type: "object",
|
|
3373
3442
|
properties: {
|
|
3443
|
+
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." },
|
|
3444
|
+
source_f3d: { type: "string", description: "With bind_document, import this absolute F3D path into a new document for revision." },
|
|
3374
3445
|
timeout_ms: { type: "integer", minimum: 100, maximum: 600000, description: "Total deadline in milliseconds; defaults to FUSION_MCP_TIMEOUT_MS or 180000." }
|
|
3375
3446
|
},
|
|
3376
3447
|
additionalProperties: false
|
|
@@ -3383,6 +3454,7 @@ class BambuPrinterMCPServer {
|
|
|
3383
3454
|
inputSchema: {
|
|
3384
3455
|
type: "object",
|
|
3385
3456
|
properties: {
|
|
3457
|
+
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." },
|
|
3386
3458
|
output_dir: { type: "string", description: "Existing directory for the three files." },
|
|
3387
3459
|
name: { type: "string", description: "File name without extension, such as bracket." },
|
|
3388
3460
|
body_name: { type: "string", description: "The body to export as STL. Optional when the design has exactly one body." },
|
|
@@ -3393,7 +3465,7 @@ class BambuPrinterMCPServer {
|
|
|
3393
3465
|
},
|
|
3394
3466
|
outputSchema: FUSION_EXPORT_OUTPUT_SCHEMA
|
|
3395
3467
|
}
|
|
3396
|
-
]
|
|
3468
|
+
].map(withAnnotations)
|
|
3397
3469
|
};
|
|
3398
3470
|
});
|
|
3399
3471
|
|
|
@@ -3448,6 +3520,29 @@ class BambuPrinterMCPServer {
|
|
|
3448
3520
|
// again once every older helper for this printer has exited, and only
|
|
3449
3521
|
// that send counts. Either counted route succeeding is success. macOS
|
|
3450
3522
|
// stays native-only.
|
|
3523
|
+
// Print controls go over the same connection as the print (resolveConnection).
|
|
3524
|
+
// undefined keeps the direct MQTT route in BambuImplementation.
|
|
3525
|
+
const printerControl = (command: "stop" | "pause" | "resume") => {
|
|
3526
|
+
const nativeCommand = (assertActive?: () => void, beforeDispatch?: () => Promise<void>) => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3527
|
+
messageJson: JSON.stringify({ print: { command, param: "", sequence_id: String(Date.now()) } }), qos: 1 },
|
|
3528
|
+
command === "resume" ? { signal: extra.signal, assertActive, beforeDispatch } : undefined);
|
|
3529
|
+
// The selected route decides first: a job started over FULU's bridge (LAN or cloud) is controlled there,
|
|
3530
|
+
// even on an X2D whose native plug-in is installed. Otherwise an X2D uses its native route when it can.
|
|
3531
|
+
const route = resolveConnection(args);
|
|
3532
|
+
if (route.mode !== "bambu_network" && nativeControls()) {
|
|
3533
|
+
return command === "stop"
|
|
3534
|
+
? linuxEmergency(() => nativeCommand(), signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
3535
|
+
: nativeCommand;
|
|
3536
|
+
}
|
|
3537
|
+
if (route.mode === "bambu_native") throw new Error(nativeUnavailableReason()!);
|
|
3538
|
+
if (route.mode !== "bambu_network") return undefined;
|
|
3539
|
+
return (assertActive?: () => void, beforeDispatch?: () => Promise<void>) => {
|
|
3540
|
+
const options = { assertDispatchAllowed: () => { extra.signal.throwIfAborted(); assertActive?.(); } };
|
|
3541
|
+
return route.type === "cloud"
|
|
3542
|
+
? this.bambuNetwork.sendCloudPrintCommand(bambuSerial, command, options, beforeDispatch)
|
|
3543
|
+
: this.bambuNetwork.sendLocalPrintCommand({ devId: bambuSerial, devIp: host, username: "bblp", password: bambuToken, useSsl: true }, command, options, beforeDispatch);
|
|
3544
|
+
};
|
|
3545
|
+
};
|
|
3451
3546
|
const linuxEmergency = (native: () => Promise<any>, mqtt: (signal: AbortSignal) => Promise<any>) => async () => {
|
|
3452
3547
|
if (process.platform !== "linux") return native();
|
|
3453
3548
|
// An unreachable printer makes the MQTT connect retry forever; bound each
|
|
@@ -3649,6 +3744,24 @@ class BambuPrinterMCPServer {
|
|
|
3649
3744
|
break;
|
|
3650
3745
|
}
|
|
3651
3746
|
|
|
3747
|
+
case "camera_stream_start":
|
|
3748
|
+
result = this.bambu.cameraStreamStart(host, bambuSerial, bambuToken, {
|
|
3749
|
+
bambuModel: (args?.bambu_model as string | undefined) ?? process.env.BAMBU_MODEL ?? process.env.BAMBU_PRINTER_MODEL,
|
|
3750
|
+
fps: args?.fps as number | undefined, idleTimeoutMs: args?.idle_timeout_ms as number | undefined,
|
|
3751
|
+
ffmpegPath: this.runtimeConfig.ffmpegPath,
|
|
3752
|
+
});
|
|
3753
|
+
break;
|
|
3754
|
+
case "camera_frame":
|
|
3755
|
+
result = await this.bambu.cameraStreamFrame(host, bambuSerial, {
|
|
3756
|
+
sinceSeq: args?.since_seq as number | undefined, waitMs: args?.wait_ms as number | undefined,
|
|
3757
|
+
maxWidth: args?.max_width as number | undefined, maxBytes: args?.max_bytes as number | undefined, changedOnly: args?.changed_only as boolean | undefined,
|
|
3758
|
+
minChange: args?.min_change as number | undefined, signal: extra.signal,
|
|
3759
|
+
});
|
|
3760
|
+
break;
|
|
3761
|
+
case "camera_stream_stop":
|
|
3762
|
+
result = this.bambu.cameraStreamStop(host, bambuSerial);
|
|
3763
|
+
break;
|
|
3764
|
+
|
|
3652
3765
|
case "camera_snapshot": {
|
|
3653
3766
|
const snapshotModel = (args?.bambu_model as string | undefined) ?? process.env.BAMBU_MODEL ?? process.env.BAMBU_PRINTER_MODEL;
|
|
3654
3767
|
result = await this.bambu.cameraSnapshot(host, bambuSerial, bambuToken, {
|
|
@@ -3730,29 +3843,15 @@ class BambuPrinterMCPServer {
|
|
|
3730
3843
|
}
|
|
3731
3844
|
|
|
3732
3845
|
case "cancel_print":
|
|
3733
|
-
result = await this.bambu.cancelJob(host, bambuSerial, bambuToken,
|
|
3734
|
-
nativeControls()
|
|
3735
|
-
? linuxEmergency(
|
|
3736
|
-
() => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3737
|
-
messageJson: JSON.stringify({ print: { command: "stop", param: "", sequence_id: String(Date.now()) } }), qos: 1 }),
|
|
3738
|
-
signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
3739
|
-
: undefined);
|
|
3846
|
+
result = await this.bambu.cancelJob(host, bambuSerial, bambuToken, printerControl("stop"));
|
|
3740
3847
|
break;
|
|
3741
3848
|
|
|
3742
3849
|
case "pause_print":
|
|
3743
|
-
result = await this.bambu.pauseJob(host, bambuSerial, bambuToken,
|
|
3744
|
-
nativeControls()
|
|
3745
|
-
? () => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3746
|
-
messageJson: JSON.stringify({ print: { command: "pause", param: "", sequence_id: String(Date.now()) } }), qos: 1 })
|
|
3747
|
-
: undefined);
|
|
3850
|
+
result = await this.bambu.pauseJob(host, bambuSerial, bambuToken, printerControl("pause"));
|
|
3748
3851
|
break;
|
|
3749
3852
|
|
|
3750
3853
|
case "resume_print":
|
|
3751
|
-
result = await this.bambu.resumeJob(host, bambuSerial, bambuToken,
|
|
3752
|
-
nativeControls()
|
|
3753
|
-
? (assertActive, beforeDispatch) => sendNativeCommand({ host, serial: bambuSerial, token: bambuToken,
|
|
3754
|
-
messageJson: JSON.stringify({ print: { command: "resume", param: "", sequence_id: String(Date.now()) } }), qos: 1 }, { signal: extra.signal, assertActive, beforeDispatch })
|
|
3755
|
-
: undefined);
|
|
3854
|
+
result = await this.bambu.resumeJob(host, bambuSerial, bambuToken, printerControl("resume"));
|
|
3756
3855
|
break;
|
|
3757
3856
|
|
|
3758
3857
|
case "x2d_native_control": {
|
|
@@ -4152,6 +4251,7 @@ class BambuPrinterMCPServer {
|
|
|
4152
4251
|
if (args?.min_save !== undefined) sliceBambuOptions.minSave = Boolean(args.min_save);
|
|
4153
4252
|
if (args?.skip_modified_gcodes !== undefined) sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
|
|
4154
4253
|
if (args?.slice_plate !== undefined) sliceBambuOptions.slicePlate = Number(args.slice_plate);
|
|
4254
|
+
{ const pauses = parsePauseLayers(args?.pause_at_layers); if (pauses) sliceBambuOptions.pauseAtLayers = pauses; }
|
|
4155
4255
|
const usePrinterFilaments =
|
|
4156
4256
|
args?.use_printer_filaments !== undefined ? Boolean(args.use_printer_filaments) : true;
|
|
4157
4257
|
if (
|
|
@@ -4240,6 +4340,7 @@ class BambuPrinterMCPServer {
|
|
|
4240
4340
|
if (args?.min_save !== undefined) sliceBambuOptions.minSave = Boolean(args.min_save);
|
|
4241
4341
|
if (args?.skip_modified_gcodes !== undefined) sliceBambuOptions.skipModifiedGcodes = Boolean(args.skip_modified_gcodes);
|
|
4242
4342
|
if (args?.slice_plate !== undefined) sliceBambuOptions.slicePlate = Number(args.slice_plate);
|
|
4343
|
+
{ const pauses = parsePauseLayers(args?.pause_at_layers); if (pauses) sliceBambuOptions.pauseAtLayers = pauses; }
|
|
4243
4344
|
const processOverrides = parseProcessOverrides(args as Record<string, unknown>, Number(nozzleDiam));
|
|
4244
4345
|
if (processOverrides) sliceBambuOptions.processOverrides = processOverrides;
|
|
4245
4346
|
if (sliceBambuOptions.loadFilamentIds && String(args.stl_path).toLowerCase().endsWith(".3mf")) {
|
|
@@ -4290,11 +4391,7 @@ class BambuPrinterMCPServer {
|
|
|
4290
4391
|
const printModel = await this.resolveBambuModel(args.bambu_model as string | undefined);
|
|
4291
4392
|
const resolvedArgs = { ...args, bambu_model: printModel };
|
|
4292
4393
|
const requestedModel = printModel;
|
|
4293
|
-
const
|
|
4294
|
-
DEFAULT_BAMBU_CONNECTION_MODE ||
|
|
4295
|
-
(requestedModel === "x2d" ? "bambu_native" : "lan_mqtt_ftps");
|
|
4296
|
-
const connectionMode = String(args?.connection_mode || defaultConnectionMode).trim().toLowerCase();
|
|
4297
|
-
if (!["lan_mqtt_ftps", "bambu_native", "bambu_network", "bambu_connect"].includes(connectionMode)) throw new Error("Unsupported connection_mode.");
|
|
4394
|
+
const connectionMode = resolveConnection(args, requestedModel).mode;
|
|
4298
4395
|
// X2D firmware accepts the Bambu Studio :6000/eMMC route but
|
|
4299
4396
|
// rejects the legacy direct FTPS STOR operation with 553. Keep
|
|
4300
4397
|
// an explicit old-mode request from re-entering that known-bad
|
|
@@ -4352,6 +4449,16 @@ class BambuPrinterMCPServer {
|
|
|
4352
4449
|
const hasGcode = Object.values(zip.files).some(
|
|
4353
4450
|
entry => !entry.dir && /\.gcode$/i.test(entry.name)
|
|
4354
4451
|
);
|
|
4452
|
+
const pauseLayers = parsePauseLayers(args?.pause_at_layers);
|
|
4453
|
+
if (hasGcode && pauseLayers) {
|
|
4454
|
+
// Already sliced: its G-code is what prints, so the pauses must already be in it.
|
|
4455
|
+
const gcode = await readPlateGcode(threeMFPath, Number(args?.plate_index ?? 0) + 1);
|
|
4456
|
+
const placed = gcode ? pausedLayers(gcode, machinePauseGcode(gcode)) : [];
|
|
4457
|
+
const missing = pauseLayers.filter(layer => !placed.includes(layer));
|
|
4458
|
+
if (missing.length) {
|
|
4459
|
+
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.`);
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4355
4462
|
if (!hasGcode) {
|
|
4356
4463
|
assertUniformCliNozzles(args as Record<string, any>);
|
|
4357
4464
|
if (printBedType === "supertack_plate") {
|
|
@@ -4367,6 +4474,7 @@ class BambuPrinterMCPServer {
|
|
|
4367
4474
|
bedType: printBedType,
|
|
4368
4475
|
nozzleType: resolveNozzleType(args?.nozzle_type),
|
|
4369
4476
|
nozzleVolumeType: resolveNozzleVolumeType(args?.nozzle_volume_type),
|
|
4477
|
+
...(pauseLayers ? { pauseAtLayers: pauseLayers } : {}),
|
|
4370
4478
|
};
|
|
4371
4479
|
if (!explicitSlicerProfile) {
|
|
4372
4480
|
try {
|
|
@@ -4634,6 +4742,36 @@ class BambuPrinterMCPServer {
|
|
|
4634
4742
|
result = bambuPrinterInfo({ server: SERVER_INFO, host, serial: bambuSerial, model: this.displayModel(args, bambuSerial) });
|
|
4635
4743
|
break;
|
|
4636
4744
|
|
|
4745
|
+
case "counterpart_print_route": {
|
|
4746
|
+
let savedTo: string | null = null;
|
|
4747
|
+
// FULU's bridge is set up, so the routes through it can be used.
|
|
4748
|
+
const bridgeConfigured = Boolean(this.bambuNetwork.resolveBridgeCommand());
|
|
4749
|
+
const routeModel = this.displayModel(args, bambuSerial);
|
|
4750
|
+
// The printer's own local route (X2D native by default, or a configured native/Bambu Connect mode),
|
|
4751
|
+
// resolved from the start-up configuration so it survives choosing another route.
|
|
4752
|
+
const ownLocal = ownLocalOf({ mode: CONFIGURED_CONNECTION.mode || (routeModel === "x2d" ? "bambu_native" : ""), type: CONFIGURED_CONNECTION.type || "lan" });
|
|
4753
|
+
if (args?.route !== undefined) {
|
|
4754
|
+
if (!PRINT_ROUTES.includes(args.route as PrintRoute)) throw new Error('route must be "lan", "cloud" or "developer".');
|
|
4755
|
+
const next = connectionForRoute(args.route as PrintRoute, resolveConnection({}, routeModel), bridgeConfigured, ownLocal);
|
|
4756
|
+
// dotenv loaded .env from the working directory at start; a client's own env block has no file to update.
|
|
4757
|
+
const file = path.resolve(process.cwd(), ".env");
|
|
4758
|
+
if (fs.existsSync(file)) {
|
|
4759
|
+
writeEnvValues(file, {
|
|
4760
|
+
...(next.mode ? { BAMBU_DEFAULT_CONNECTION_MODE: next.mode } : {}),
|
|
4761
|
+
...(next.type ? { BAMBU_DEFAULT_CONNECTION_TYPE: next.type } : {}),
|
|
4762
|
+
});
|
|
4763
|
+
savedTo = file;
|
|
4764
|
+
}
|
|
4765
|
+
DEFAULT_BAMBU_CONNECTION_MODE = next.mode;
|
|
4766
|
+
DEFAULT_BAMBU_CONNECTION_TYPE = next.type;
|
|
4767
|
+
}
|
|
4768
|
+
const connection = resolveConnection({}, routeModel);
|
|
4769
|
+
const options = routeOptions(connection, bridgeConfigured, ownLocal);
|
|
4770
|
+
result = { route: routeOf(connection), mode: connection.mode, type: connection.type,
|
|
4771
|
+
choices: options.filter(option => option.available).map(option => option.id), options, savedTo };
|
|
4772
|
+
break;
|
|
4773
|
+
}
|
|
4774
|
+
|
|
4637
4775
|
case "counterpart_print_progress": {
|
|
4638
4776
|
const report = await this.bambu.readProgressReport(host, bambuSerial, bambuToken);
|
|
4639
4777
|
result = report
|
|
@@ -4651,9 +4789,9 @@ class BambuPrinterMCPServer {
|
|
|
4651
4789
|
break;
|
|
4652
4790
|
|
|
4653
4791
|
case "fusion_mcp_call": {
|
|
4654
|
-
//
|
|
4655
|
-
|
|
4656
|
-
return
|
|
4792
|
+
// Preserve polymorphic text/images/errors. An invented empty structured result
|
|
4793
|
+
// masks useful text in clients that prefer structuredContent.
|
|
4794
|
+
return await this.fusion.call(args ?? {}, extra.signal);
|
|
4657
4795
|
}
|
|
4658
4796
|
|
|
4659
4797
|
case "fusion_mcp_new_design":
|
|
@@ -4669,7 +4807,11 @@ class BambuPrinterMCPServer {
|
|
|
4669
4807
|
}
|
|
4670
4808
|
|
|
4671
4809
|
await progressNotifications;
|
|
4672
|
-
|
|
4810
|
+
// A stream image belongs in structuredContent once. Repeating its base64 in text
|
|
4811
|
+
// doubles the wire budget; text-only clients still receive useful frame metadata.
|
|
4812
|
+
const textResult = name === "camera_frame" && result && typeof result === "object"
|
|
4813
|
+
? Object.fromEntries(Object.entries(result).filter(([key]) => key !== "base64")) : result;
|
|
4814
|
+
const text = typeof textResult === "string" ? textResult : JSON.stringify(textResult, null, 2);
|
|
4673
4815
|
|
|
4674
4816
|
// A declared outputSchema obliges structuredContent whatever MCP_HTTP_JSON_RESPONSE says.
|
|
4675
4817
|
if ((this.runtimeConfig.enableJsonResponse || OUTPUT_SCHEMA_TOOLS.has(name)) && typeof result === "object") {
|
|
@@ -4720,6 +4862,8 @@ class BambuPrinterMCPServer {
|
|
|
4720
4862
|
if (this.shuttingDown) return;
|
|
4721
4863
|
this.shuttingDown = true;
|
|
4722
4864
|
try {
|
|
4865
|
+
// Close camera sockets/processes first, waking any waiting frame requests.
|
|
4866
|
+
this.bambu.cameraStreams.stopAll();
|
|
4723
4867
|
// Closing the MCP transport aborts its active requests before exit cleanup.
|
|
4724
4868
|
await this.server.close();
|
|
4725
4869
|
await this.fusion.close();
|