bambu-printer-mcp 1.1.82 → 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"] },
@@ -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.",
@@ -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,