bambu-printer-mcp 1.1.81 → 1.1.83

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.
@@ -1,3 +1,4 @@
1
+ import {CAD_CAPABILITY,cadEnabled} from "../cad/contracts.js";
1
2
  /** counterpart_printer_info for Bambu printers (PRD §8.4). Pure: no printer traffic. */
2
3
  import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "../printers/camera-models.js";
3
4
  import { normalizeModel } from "../safety/limits.js";
@@ -33,6 +34,7 @@ export function bambuPrinterInfo(options: { server: { name: string; version: str
33
34
  host: options.host,
34
35
  },
35
36
  capabilities: {
37
+ ...(cadEnabled()?{cad:CAD_CAPABILITY}:{}),
36
38
  progress: true,
37
39
  layers: true,
38
40
  // camera_snapshot needs the model to choose its transport.
@@ -41,6 +41,10 @@ export const REMOTE_SCOPES: Readonly<Record<string, RemoteScope>> = {
41
41
  blender_mcp_status: "read",
42
42
  counterpart_printer_info: "read",
43
43
  counterpart_print_progress: "read",
44
+ cad_status: "read",
45
+ cad_setup: "read",
46
+ cad_run: "design",
47
+ cad_check_fit: "design",
44
48
  fusion_mcp_status: "read",
45
49
  blender_mcp_setup: "read", // checks only; update raises it
46
50
  fusion_mcp_setup: "read", // checks only; install raises it
@@ -97,6 +101,7 @@ const RAISED_BY: Readonly<Record<string, Record<string, RemoteScope>>> = {
97
101
  fusion_mcp_status: { launch: "design" }, // starts Fusion on this computer
98
102
  blender_mcp_status: { connect: "design" }, // connects to Blender
99
103
  blender_mcp_setup: { update: "raw" }, // replaces the add-on in the person's Blender
104
+ cad_setup: { install: "raw" },
100
105
  fusion_mcp_setup: { install: "raw" }, // installs into the person's Fusion, a login item and this server's .env
101
106
  };
102
107
 
@@ -119,6 +124,7 @@ const FILE_ARGUMENTS: ReadonlySet<string> = new Set(["filament_profile", "slicer
119
124
  const isPath = (key: string) => /(?:path|dir|directory|_file)$/.test(key) || FILE_ARGUMENTS.has(key);
120
125
 
121
126
  function kindOf(tool: string, key: string, depth: number): ArgumentKind | undefined {
127
+ if (tool === "cad_check_fit" && depth === 0 && ["model", "reference"].includes(key)) return "path";
122
128
  // counterpart_print_route's own `route` is the connection the caller chooses.
123
129
  if ((CONFIG_ARGUMENTS.has(key) && !(key === "route" && tool === "counterpart_print_route")) || /config_dir$/.test(key)) return "config";
124
130
  if (depth === 0 && TOP_LEVEL_CONFIG.has(key)) return "config-top";
@@ -28,6 +28,7 @@ export type PrinterInfo = {
28
28
  server: { name: string; version: string };
29
29
  printer: { kind: typeof PRINTER_KINDS[number]; model?: string; serial?: string; host: string; name?: string };
30
30
  capabilities: {
31
+ cad?: {contract: string; status: string; setup: string; run: string; checkFit: string; prompt: string};
31
32
  progress: boolean; layers: boolean;
32
33
  camera: "bambu-tcp" | "rtsp" | "http-snapshot" | "none";
33
34
  cameraStream?: boolean;
@@ -67,6 +68,7 @@ export const PRINTER_INFO_OUTPUT_SCHEMA = {
67
68
  capabilities: {
68
69
  type: "object",
69
70
  properties: {
71
+ cad: {type: "object", properties: {contract: {type: "string", const: "cad/1"}, status: {type: "string"}, setup: {type: "string"}, run: {type: "string"}, checkFit: {type: "string"}, prompt: {type: "string"}}, required: ["contract", "status", "setup", "run", "checkFit", "prompt"]},
70
72
  progress: { type: "boolean" },
71
73
  layers: { type: "boolean" },
72
74
  camera: { type: "string", enum: ["bambu-tcp", "rtsp", "http-snapshot", "none"] },
@@ -28,6 +28,12 @@ export type SetupKind = {
28
28
  kind: typeof PRINTER_KINDS[number]; label: string;
29
29
  /** Values this server needs for the kind whatever the person enters (MCP_TRANSPORT, PRINTER_TYPE). */
30
30
  env: Record<string, string>;
31
+ /**
32
+ * Whether camera_snapshot reads this kind's camera with only the settings these fields write, so a client's setup
33
+ * check can ask for a picture as well as the status. What else the computer needs (ffmpeg for RTSP models) is
34
+ * reported in camera_snapshot's own error. Every kind declares it; a client reads it missing as an older server.
35
+ */
36
+ cameraSnapshot: boolean;
31
37
  fields: SetupField[];
32
38
  };
33
39
  /** The slicer this server runs, as it resolves it now, and the settings that choose it (for every printer). */
@@ -86,6 +92,8 @@ export function bambuSetupFields(options: { server: { name: string; version: str
86
92
  server: options.server,
87
93
  kinds: [{
88
94
  kind: "bambu", label: "Bambu Lab", env: { MCP_TRANSPORT: "stdio" },
95
+ // Every offered model has a built-in camera; the model field chooses its transport (camera-models.ts).
96
+ cameraSnapshot: true,
89
97
  fields: [
90
98
  { name: "host", env: "PRINTER_HOST", aliases: ["BAMBU_PRINTER_HOST"], label: "Address", hint: "The printer's IP address: on the printer, Settings → WLAN", required: true },
91
99
  { name: "serial", env: "BAMBU_SERIAL", aliases: ["BAMBU_PRINTER_SERIAL"], label: "Serial number", hint: "On the printer: Settings → Device", required: true, transform: "uppercase" },
@@ -115,8 +123,10 @@ export const SETUP_FIELDS_OUTPUT_SCHEMA = {
115
123
  server: { type: "object", properties: { name: { type: "string" }, version: { type: "string" } }, required: ["name", "version"] },
116
124
  kinds: { type: "array", items: { type: "object", properties: {
117
125
  kind: { type: "string", enum: [...PRINTER_KINDS] }, label: { type: "string" },
118
- env: { type: "object", additionalProperties: { type: "string" } }, fields: { type: "array", items: field },
119
- }, required: ["kind", "label", "env", "fields"] } },
126
+ env: { type: "object", additionalProperties: { type: "string" } },
127
+ cameraSnapshot: { type: "boolean", description: "Whether camera_snapshot reads this kind's camera with only the settings these fields write, so a setup check can ask for a picture too." },
128
+ fields: { type: "array", items: field },
129
+ }, required: ["kind", "label", "env", "cameraSnapshot", "fields"] } },
120
130
  model: { type: "string" },
121
131
  slicer: { type: "object", properties: {
122
132
  type: { type: "string" }, path: { type: "string" }, found: { type: "boolean" }, profilesRoot: { type: "string" }, profilesFound: { type: "boolean" },
@@ -1,3 +1,4 @@
1
+ import { CAD_DESIGN_PROMPT } from "./cad/contracts.js";
1
2
  /**
2
3
  * Manufacturing guidance for agents that design printable models: David Montgomery's FDM design
3
4
  * prompt pack (3 November 2026), verbatim. Served as MCP prompts and a resource; the other printer
@@ -175,6 +176,7 @@ export const FDM_CAPABILITY_RESOURCE = { uri: FDM_CAPABILITY_URI, name: "FDM bri
175
176
  description: "Planning bands and evidence for bridges and overhangs, for when one is consequential and there is no sufficiently specific measured capability available" };
176
177
 
177
178
  export const DESIGN_PROMPTS: DesignPrompt[] = [
179
+ CAD_DESIGN_PROMPT,
178
180
  { name: "fdm_design", title: "Design for FDM printing", text: FDM_CORE,
179
181
  description: "Persistent instructions for every design or model-editing task: plan how the object prints as part of the design, using the actual printer, filaments and slice." },
180
182
  { name: "fdm_multicolor", title: "Multicolour and support materials", text: FDM_MULTICOLOR,
package/src/index.ts CHANGED
@@ -57,6 +57,9 @@ import {
57
57
  type BambuNativeUpdateCallback,
58
58
  } from "./bambu-native.js";
59
59
  import { importFileViaBambuConnect } from "./bambu-connect.js";
60
+ import { CadEngine } from "./cad-engine.js";
61
+ import { CadRefusal } from "./cad/refusal.js";
62
+ import { CAD_TOOLS, cadEnabled } from "./cad/contracts.js";
60
63
  import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
61
64
  import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_MCP_PIN, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge, addinAddress } from "./fusion-mcp-bridge.js";
62
65
  import { BLENDER_SETUP_OUTPUT_SCHEMA, BlenderAddonSetup, FUSION_ADDIN_REPOSITORY, FUSION_SETUP_OUTPUT_SCHEMA, FusionAddinSetup, defaultSetupSystem, parseAddonHandshake, type BlenderAddonHandshake } from "./design-app-setup.js";
@@ -88,6 +91,7 @@ import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } fro
88
91
 
89
92
  dotenv.config();
90
93
 
94
+ const CAD_ENABLED = cadEnabled();
91
95
  const DEFAULT_HOST = process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST || "localhost";
92
96
  const DEFAULT_BAMBU_SERIAL = process.env.BAMBU_PRINTER_SERIAL || process.env.BAMBU_SERIAL || "";
93
97
  const DEFAULT_BAMBU_TOKEN =
@@ -151,6 +155,7 @@ const SERVER_INFO = {
151
155
  };
152
156
  /** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
153
157
  const OUTPUT_SCHEMA_TOOLS = new Set([
158
+ "cad_status", "cad_setup", "cad_run", "cad_check_fit",
154
159
  "counterpart_printer_info", "counterpart_print_progress", "counterpart_make_3mf",
155
160
  "counterpart_discover_printers", "counterpart_setup_fields", "counterpart_propose_filaments",
156
161
  "fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
@@ -1386,6 +1391,7 @@ class BambuPrinterMCPServer {
1386
1391
  private server: Server;
1387
1392
  private bambu: BambuImplementation;
1388
1393
  private bambuNetwork: BambuNetworkBridge;
1394
+ private readonly cad = new CadEngine({outputRoots:[TEMP_DIR,...(process.env.CAD_OUTPUT_DIRS?.split(path.delimiter).filter(Boolean)??[])]});
1389
1395
  private readonly blender = new BlenderMcpBridge();
1390
1396
  private readonly fusion = new FusionMcpBridge();
1391
1397
  // Downloads and installer output are staged in this server's own temporary folder.
@@ -1407,7 +1413,7 @@ class BambuPrinterMCPServer {
1407
1413
  resources: {},
1408
1414
  tools: {}
1409
1415
  },
1410
- instructions: SERVER_INSTRUCTIONS
1416
+ instructions: SERVER_INSTRUCTIONS + (CAD_ENABLED ? " For headless dimensioned designs and parameter edits, read the cad_design prompt before using cad_run." : "")
1411
1417
  }
1412
1418
  );
1413
1419
 
@@ -2380,7 +2386,7 @@ class BambuPrinterMCPServer {
2380
2386
  /** The FDM design guidance as MCP prompts: the client decides when to attach each one. */
2381
2387
  setupPromptHandlers() {
2382
2388
  this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({
2383
- prompts: [...DESIGN_PROMPTS, FDM_SLICING_PROMPT].map(({ name, title, description }) => ({ name, title, description })),
2389
+ prompts: [...DESIGN_PROMPTS.filter(p => CAD_ENABLED || p.name !== "cad_design"), FDM_SLICING_PROMPT].map(({ name, title, description }) => ({ name, title, description })),
2384
2390
  }));
2385
2391
  this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
2386
2392
  if (request.params.name === FDM_SLICING_PROMPT.name) {
@@ -2391,7 +2397,7 @@ class BambuPrinterMCPServer {
2391
2397
  messages: [{ role: "user" as const, content: { type: "text" as const, text: slicingGuidance(slicerType, bambuSliceCapabilities(slicerType)) } }],
2392
2398
  };
2393
2399
  }
2394
- const prompt = DESIGN_PROMPTS.find(item => item.name === request.params.name);
2400
+ const prompt = DESIGN_PROMPTS.find(item => item.name === request.params.name && (CAD_ENABLED || item.name !== "cad_design"));
2395
2401
  if (!prompt) throw new McpError(ErrorCode.InvalidParams, `Unknown prompt: ${request.params.name}`);
2396
2402
  return {
2397
2403
  description: prompt.description,
@@ -3468,6 +3474,7 @@ class BambuPrinterMCPServer {
3468
3474
  required: ["stl_path"]
3469
3475
  }
3470
3476
  },
3477
+ ...(CAD_ENABLED ? CAD_TOOLS : []),
3471
3478
  {
3472
3479
  name: "blender_mcp_status",
3473
3480
  description: "Inspect Blender MCP configuration or connect and discover the remote server's tools and schemas. Connecting does not edit the scene; use get_scene_info through blender_mcp_call to check the Blender addon.",
@@ -3546,7 +3553,7 @@ class BambuPrinterMCPServer {
3546
3553
  },
3547
3554
  {
3548
3555
  name: "counterpart_setup_fields",
3549
- description: "Counterpart contract (counterpart/1): the printers this server drives and the settings it reads for each, by .env variable name (first canonical, then aliases): label, hint, whether required, the model choices and the model each serial-number prefix names. Pass serial to get the model it names. Sends nothing to a printer and returns no configured values.",
3556
+ description: "Counterpart contract (counterpart/1): the printers this server drives and the settings it reads for each, by .env variable name (first canonical, then aliases): label, hint, whether required, the model choices and the model each serial-number prefix names, and whether camera_snapshot reads the printer's camera with only those settings (cameraSnapshot). Pass serial to get the model it names. Sends nothing to a printer and returns no configured values.",
3550
3557
  inputSchema: {
3551
3558
  type: "object",
3552
3559
  properties: { serial: { type: "string", maxLength: 64, description: "A Bambu serial number: model is the one it names, when known." } },
@@ -3750,6 +3757,10 @@ class BambuPrinterMCPServer {
3750
3757
  .catch(() => {});
3751
3758
  });
3752
3759
 
3760
+ if (!CAD_ENABLED && name.startsWith("cad_")) {
3761
+ const failure = await this.cad.failure(new CadRefusal("cad-disabled", "Code-CAD is disabled by CAD_ENABLED=0."), name);
3762
+ return {isError: true, content: [{type: "text", text: failure.message}], structuredContent: failure};
3763
+ }
3753
3764
  const host = String(args?.host || DEFAULT_HOST);
3754
3765
  const bambuSerial = String(args?.bambu_serial || DEFAULT_BAMBU_SERIAL);
3755
3766
  const bambuToken = String(args?.bambu_token || DEFAULT_BAMBU_TOKEN);
@@ -5095,6 +5106,27 @@ class BambuPrinterMCPServer {
5095
5106
  result = await makeCounterpart3mf(args ?? {});
5096
5107
  break;
5097
5108
 
5109
+ case "cad_status":
5110
+ if (args && Object.keys(args).length) throw new Error("cad_status takes no arguments.");
5111
+ result = await this.cad.status(); break;
5112
+ case "cad_setup":
5113
+ case "cad_run":
5114
+ case "cad_check_fit": {
5115
+ const started = Date.now();
5116
+ let sequence = 0;
5117
+ const heartbeat = progressToken === undefined ? undefined : setInterval(() => {
5118
+ progressNotifications = progressNotifications.then(() => extra.sendNotification({method: "notifications/progress", params: {
5119
+ progressToken, progress: ++sequence, message: `${name}: working for ${Math.round((Date.now()-started)/1000)} seconds`,
5120
+ }})).catch(() => {});
5121
+ }, 5000);
5122
+ try {
5123
+ result = name === "cad_setup" ? await this.cad.setup(args ?? {}, extra.signal)
5124
+ : name === "cad_run" ? await this.cad.run(args ?? {}, extra.signal)
5125
+ : await this.cad.checkFit(args ?? {}, extra.signal);
5126
+ } finally { if (heartbeat) clearInterval(heartbeat); }
5127
+ break;
5128
+ }
5129
+
5098
5130
  case "blender_mcp_setup":
5099
5131
  if (args?.update !== undefined && typeof args.update !== "boolean") throw new Error("update must be a boolean.");
5100
5132
  result = args?.update === true ? await this.blenderSetup.update(extra.signal) : await this.blenderSetup.check();
@@ -5145,6 +5177,10 @@ class BambuPrinterMCPServer {
5145
5177
  return { content: [{ type: "text", text }] };
5146
5178
 
5147
5179
  } catch (error) {
5180
+ if (name.startsWith("cad_")) {
5181
+ const failure = await this.cad.failure(error, name);
5182
+ return {isError: true, content: [{type: "text" as const, text: failure.message}], structuredContent: failure};
5183
+ }
5148
5184
  const message = error instanceof Error ? error.message : String(error);
5149
5185
  // Refusals and printer rejections repeat unchanged; say what to fix instead of "try again".
5150
5186
  const refused = /nothing was (?:sent|uploaded)|no command was sent|does not match the job|is ambiguous|is missing or ambiguous|rejected the print command|are refused|is refused|refused because|refused until|refused before/i.test(message);
@@ -34,6 +34,10 @@ const START_PRINT = hints(false, false, false, true);
34
34
  const SLICE_AND_PRINT = hints(false, true, false, true);
35
35
 
36
36
  export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
37
+ cad_status: READ_LOCAL,
38
+ cad_setup: hints(false, true, true, true),
39
+ cad_run: hints(false, false, false, false),
40
+ cad_check_fit: READ_LOCAL,
37
41
  // Printer and cloud reads
38
42
  get_printer_status: READ_OUTSIDE,
39
43
  get_printer_filaments: READ_OUTSIDE,