bambu-printer-mcp 1.1.66 → 1.1.68

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.
@@ -185,4 +185,33 @@ export const DESIGN_PROMPTS: DesignPrompt[] = [
185
185
  description: "A separate review turn after a candidate has been sliced, before presenting the manufacturing recommendation: keep, revise, or validate one specific uncertainty." },
186
186
  ];
187
187
 
188
- export const SERVER_INSTRUCTIONS = "When designing or editing a model to print, apply the fdm_design prompt. Add fdm_multicolor when several colours or support materials share a print, fdm_assembly when a split or joint could help, and fdm_after_slice as a separate review turn after a candidate has been sliced, before presenting the manufacturing recommendation. Read " + FDM_CAPABILITY_URI + " when a bridge or overhang is consequential and there is no sufficiently specific measured capability available.";
188
+ const SLICER_NAMES: Record<string, string> = {
189
+ bambustudio: "Bambu Studio", orcaslicer: "OrcaSlicer", "orcaslicer-bambulab": "FULU OrcaSlicer-bambulab",
190
+ "orca-slicer-api": "the remote OrcaSlicer service (orca-slicer-api)", prusaslicer: "PrusaSlicer", cura: "Cura", slic3r: "Slic3r",
191
+ };
192
+
193
+ /**
194
+ * How this server's configured slicer orients, makes supports and checks a slice: the slicer-specific half of a
195
+ * design pass's print plan (the fdm_slicing prompt). `capabilities` is what slice_stl applies on that backend, as
196
+ * counterpart_printer_info reports it.
197
+ */
198
+ export function slicingGuidance(slicerType: string, capabilities: { supports: boolean; orient: boolean }): string {
199
+ const slicer = SLICER_NAMES[slicerType] ?? slicerType;
200
+ const lines = [
201
+ `How this printer MCP slices. Its slicer is ${slicer}.`,
202
+ "- When they could change a decision, read the printer's loaded filaments with get_printer_filaments and its slicing settings with get_slice_settings.",
203
+ "- To check a consequential choice, slice a checkpoint with slice_stl and read its structured slicer_result (return code, error and each plate's warning), not only the file path. A checkpoint is only a check: the print slices the exported model again.",
204
+ capabilities.orient
205
+ ? `- Orientation: slice_stl with orient true lets ${slicer}'s own auto-orient choose how an STL sits on the bed. It keeps overhang area low; it does not check cantilevers. To see what it chooses, slice the checkpoint with orient true. When a print is oriented this way, don't promise a particular orientation on the bed: the slicer chooses it.`
206
+ : `- Orientation: ${slicer} doesn't auto-orient here. An STL prints in the orientation it's exported in.`,
207
+ capabilities.supports
208
+ ? "- Supports: set enable_support on every slice_stl call. With enable_support true it generates supports in the style support_type names (tree(auto) or normal(auto)); with false it generates none; left out, the process preset's own setting applies. Slice the checkpoint with enable_support set the way the print will be sliced. A print gets the supports it was sliced with: print the sliced file itself, or slice the print with slice_stl and the same enable_support and support_type. print_3mf's own slicing of a file that isn't sliced yet takes no support settings; it uses the process profile's."
209
+ : `- Supports: ${slicer} takes no support settings from slice_stl here: whether it generates supports is its configured profile's own setting. Slice a checkpoint to see what that profile does before modeling any support yourself.`,
210
+ ];
211
+ return lines.join("\n");
212
+ }
213
+
214
+ export const FDM_SLICING_PROMPT = { name: "fdm_slicing", title: "How this MCP slices",
215
+ description: "Add to every design or model-editing task: how this server's slicer orients a model and generates supports, and how to check a choice with a checkpoint slice." };
216
+
217
+ export const SERVER_INSTRUCTIONS = "When designing or editing a model to print, apply the fdm_design prompt and the fdm_slicing prompt. Add fdm_multicolor when several colours or support materials share a print, fdm_assembly when a split or joint could help, and fdm_after_slice as a separate review turn after a candidate has been sliced, before presenting the manufacturing recommendation. Read " + FDM_CAPABILITY_URI + " when a bridge or overhang is consequential and there is no sufficiently specific measured capability available.";
@@ -20,15 +20,20 @@ import net from "node:net";
20
20
  import path from "node:path";
21
21
  import { promisify } from "node:util";
22
22
  import { stlMetadata } from "./blender-mcp-bridge.js";
23
+ import { FUSION_ADDIN_COMMIT, FUSION_ADDIN_REPOSITORY } from "./design-app-setup.js";
23
24
 
24
25
  const execFileAsync = promisify(execFile);
25
26
 
26
- /** The faust-machines commit the setup installs; move it only after the PRD §8.9 acceptance check passes. */
27
- export const FUSION_MCP_PIN = "19b9f1e95192";
27
+ /**
28
+ * The server and add-in commit fusion_mcp_setup installs (FUSION_ADDIN_COMMIT): David Montgomery's fork of
29
+ * faust-machines/fusion360-mcp-server with document binding, which fusion_mcp_new_design's bind_document needs, while
30
+ * that change is reviewed upstream. Move it only after the Counterpart PRD §8.9 acceptance check passes.
31
+ */
32
+ export const FUSION_MCP_PIN = FUSION_ADDIN_COMMIT.slice(0, 12);
28
33
  /** PRD §8.9: Blender's MCP add-on holds the add-in's own default, 9876, so Counterpart's Fusion uses 9877. */
29
34
  export const FUSION_ADDIN_DEFAULT_PORT = 9877;
30
35
  export const FUSION_MCP_DEFAULT_ARGS = Object.freeze([
31
- "--from", `git+https://github.com/faust-machines/fusion360-mcp-server@${FUSION_MCP_PIN}`,
36
+ "--from", `git+https://github.com/${FUSION_ADDIN_REPOSITORY}@${FUSION_MCP_PIN}`,
32
37
  "fusion360-mcp-server", "--mode", "socket",
33
38
  ]);
34
39
  const DEFAULT_TIMEOUT_MS = 180_000;
@@ -158,7 +163,7 @@ function configuration(): { command: string; args: string[] } {
158
163
  }
159
164
 
160
165
  /** Where the add-in listens: faust reads FUSION_MCP_HOST and FUSION_MCP_PORT too. */
161
- function addinAddress(): { host: string; port: number } {
166
+ export function addinAddress(): { host: string; port: number } {
162
167
  const host = process.env.FUSION_MCP_HOST?.trim() || "localhost";
163
168
  const port = Number(process.env.FUSION_MCP_PORT?.trim() || FUSION_ADDIN_DEFAULT_PORT);
164
169
  return { host, port: Number.isInteger(port) && port > 0 && port < 65536 ? port : FUSION_ADDIN_DEFAULT_PORT };
package/src/index.ts CHANGED
@@ -41,7 +41,7 @@ import {
41
41
  type BambuSliceOptions,
42
42
  type SlicerType,
43
43
  } from "./stl/stl-manipulator.js";
44
- import { BambuNetworkBridge, describeBambuNetworkPrintError, type BambuNetworkBridgeOptions, type BridgeJobUpdate } from "./bambu-network-bridge.js";
44
+ import { BambuNetworkBridge, bridgeSnapshotRoot, describeBambuNetworkPrintError, type BambuNetworkBridgeOptions, type BridgeJobUpdate } from "./bambu-network-bridge.js";
45
45
  import {
46
46
  assertBambuNativeAvailable,
47
47
  bambuNativeControlsAvailable,
@@ -57,7 +57,8 @@ import {
57
57
  } from "./bambu-native.js";
58
58
  import { importFileViaBambuConnect } from "./bambu-connect.js";
59
59
  import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
60
- import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
60
+ 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";
61
+ import { BLENDER_SETUP_OUTPUT_SCHEMA, BlenderAddonSetup, FUSION_ADDIN_REPOSITORY, FUSION_SETUP_OUTPUT_SCHEMA, FusionAddinSetup, defaultSetupSystem, parseAddonHandshake, type BlenderAddonHandshake } from "./design-app-setup.js";
61
62
  import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
62
63
  import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, hasSlicerSettingsFile, parse3MF, withExtractedSettingsCleanup } from './3mf_parser.js';
63
64
  import type { ThreeMFAmsRequirements } from "./types.js";
@@ -74,7 +75,7 @@ import { bambuPrinterInfo, bambuSliceCapabilities } from "./counterpart/info.js"
74
75
  import { DISCOVER_OUTPUT_SCHEMA, discoverBambu } from "./counterpart/discovery.js";
75
76
  import { SETUP_FIELDS_OUTPUT_SCHEMA, bambuSetupFields, slicerSetup, type SlicerSetup } from "./counterpart/setup.js";
76
77
  import { PROPOSE_FILAMENTS_INPUT_PROPERTIES, PROPOSE_FILAMENTS_OUTPUT_SCHEMA, NO_COLOUR_NAMES, bambuTrayLabel, loadColourNames, proposeFilaments, spoolName, type ColourNames, type ProposalTray } from "./counterpart/filaments.js";
77
- import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_CAPABILITY_URI, SERVER_INSTRUCTIONS } from "./design-guidance.js";
78
+ import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_CAPABILITY_URI, FDM_SLICING_PROMPT, SERVER_INSTRUCTIONS, slicingGuidance } from "./design-guidance.js";
78
79
  import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
79
80
  import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
80
81
  import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
@@ -1385,6 +1386,9 @@ class BambuPrinterMCPServer {
1385
1386
  private bambuNetwork: BambuNetworkBridge;
1386
1387
  private readonly blender = new BlenderMcpBridge();
1387
1388
  private readonly fusion = new FusionMcpBridge();
1389
+ // Downloads and installer output are staged in this server's own temporary folder.
1390
+ private readonly blenderSetup = new BlenderAddonSetup(() => this.blenderAddonHandshake(), { ...defaultSetupSystem, tmp: TEMP_DIR });
1391
+ private readonly fusionSetup = new FusionAddinSetup(() => addinAddress().port, FUSION_MCP_DEFAULT_ARGS, { ...defaultSetupSystem, tmp: TEMP_DIR });
1388
1392
  private stlManipulator: STLManipulator;
1389
1393
  private readonly runtimeConfig: RuntimeConfig;
1390
1394
  private httpRuntime?: { transport: StreamableHTTPServerTransport; httpServer: HttpServer };
@@ -1449,6 +1453,14 @@ class BambuPrinterMCPServer {
1449
1453
  this.setupToolHandlers();
1450
1454
  }
1451
1455
 
1456
+ /** The running Blender add-on's get_addon_status, read through this server's Blender bridge (undefined when it has none). */
1457
+ private async blenderAddonHandshake(): Promise<BlenderAddonHandshake | undefined> {
1458
+ const signal = AbortSignal.timeout(20_000);
1459
+ const status = await this.blender.status({ connect: true, timeout_ms: 15_000 }, signal) as { connected?: boolean; tools?: { name?: string }[] };
1460
+ if (status?.connected !== true || !status.tools?.some(tool => tool.name === "get_addon_status")) return undefined;
1461
+ return parseAddonHandshake(await this.blender.call({ tool_name: "get_addon_status", arguments: {}, timeout_ms: 15_000 }, signal));
1462
+ }
1463
+
1452
1464
  /**
1453
1465
  * The model for display-only counterpart tools: the argument, then the
1454
1466
  * configured model, then the serial prefix. Never a safety decision and
@@ -2011,7 +2023,7 @@ class BambuPrinterMCPServer {
2011
2023
  amsMapping: mapping,
2012
2024
  params: redactPrintParams(params),
2013
2025
  };
2014
- }));
2026
+ }, bridgeSnapshotRoot()));
2015
2027
  }
2016
2028
 
2017
2029
  private async handoff3mfViaBambuConnect(
@@ -2375,9 +2387,17 @@ class BambuPrinterMCPServer {
2375
2387
  /** The FDM design guidance as MCP prompts: the client decides when to attach each one. */
2376
2388
  setupPromptHandlers() {
2377
2389
  this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({
2378
- prompts: DESIGN_PROMPTS.map(({ name, title, description }) => ({ name, title, description })),
2390
+ prompts: [...DESIGN_PROMPTS, FDM_SLICING_PROMPT].map(({ name, title, description }) => ({ name, title, description })),
2379
2391
  }));
2380
2392
  this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
2393
+ if (request.params.name === FDM_SLICING_PROMPT.name) {
2394
+ // The slicer slice_stl uses by default, and what it applies there (as counterpart_printer_info reports it).
2395
+ const slicerType = normalizeSlicerType(DEFAULT_SLICER_TYPE);
2396
+ return {
2397
+ description: FDM_SLICING_PROMPT.description,
2398
+ messages: [{ role: "user" as const, content: { type: "text" as const, text: slicingGuidance(slicerType, bambuSliceCapabilities(slicerType)) } }],
2399
+ };
2400
+ }
2381
2401
  const prompt = DESIGN_PROMPTS.find(item => item.name === request.params.name);
2382
2402
  if (!prompt) throw new McpError(ErrorCode.InvalidParams, `Unknown prompt: ${request.params.name}`);
2383
2403
  return {
@@ -3601,9 +3621,29 @@ class BambuPrinterMCPServer {
3601
3621
  },
3602
3622
  outputSchema: MAKE_3MF_OUTPUT_SCHEMA
3603
3623
  },
3624
+ {
3625
+ name: "blender_mcp_setup",
3626
+ description: "Check or update the MCP for Blender add-on that the configured Blender bridge (BLENDER_MCP_COMMAND uvx, BLENDER_MCP_ARGS naming mcp-for-blender or blender-mcp) needs. Without update: which add-on file Blender loads, its protocol and the protocol the package expects, whether Blender is listening and the running add-on's own handshake. Changes nothing. With update: true, stages the add-on with the package's own installer (mcp-for-blender install-addon) at the inspected version, checks it, keeps the old file as a backup next to it and renames the new one into place. Never starts, stops or edits Blender; a running Blender uses the new add-on once it is re-enabled or restarted. A custom bridge returns supported false.",
3627
+ inputSchema: {
3628
+ type: "object",
3629
+ properties: { update: { type: "boolean", description: "Replace the installed add-on with the package's own (default false: check only)." } },
3630
+ additionalProperties: false
3631
+ },
3632
+ outputSchema: BLENDER_SETUP_OUTPUT_SCHEMA
3633
+ },
3634
+ {
3635
+ name: "fusion_mcp_setup",
3636
+ description: `Check or install what the Fusion bridge needs on macOS: Autodesk Fusion itself (found, never installed), the Fusion360MCP add-in from ${FUSION_ADDIN_REPOSITORY} at ${FUSION_MCP_PIN} (every file checked against its pinned SHA-256) set to run on startup, a login item that sets FUSION_MCP_PORT for Fusion however it is opened, and this server's FUSION_MCP_* settings. Without install: reports them and changes nothing. With install: true, installs what is missing and adds the missing settings to this server's own .env (after a copy of it), keeping a configured FUSION_MCP_COMMAND and its arguments. Never starts or quits Fusion; check the connection with fusion_mcp_status.`,
3637
+ inputSchema: {
3638
+ type: "object",
3639
+ properties: { install: { type: "boolean", description: "Install what is missing (default false: check only)." } },
3640
+ additionalProperties: false
3641
+ },
3642
+ outputSchema: FUSION_SETUP_OUTPUT_SCHEMA
3643
+ },
3604
3644
  {
3605
3645
  name: "fusion_mcp_status",
3606
- description: `Check Autodesk Fusion through the configured Fusion MCP server (faust-machines/fusion360-mcp-server): whether it is configured, Fusion is running, the Fusion360MCP add-in answers on its port, and the server's tools and schemas. connected is true only when the add-in answers. With launch: true, starts Fusion on macOS when it is not running and waits up to 90 s for the add-in. Configure FUSION_MCP_COMMAND (uvx) and FUSION_MCP_ARGS (${JSON.stringify(FUSION_MCP_DEFAULT_ARGS)}).`,
3646
+ description: `Check Autodesk Fusion through the configured Fusion MCP server (fusion360-mcp-server, faust-machines or the pinned fork with document binding): whether it is configured, Fusion is running, the Fusion360MCP add-in answers on its port, and the server's tools and schemas. connected is true only when the add-in answers. With launch: true, starts Fusion on macOS when it is not running and waits up to 90 s for the add-in. Configure FUSION_MCP_COMMAND (uvx) and FUSION_MCP_ARGS (${JSON.stringify(FUSION_MCP_DEFAULT_ARGS)}), or run fusion_mcp_setup.`,
3607
3647
  inputSchema: {
3608
3648
  type: "object",
3609
3649
  properties: {
@@ -5035,6 +5075,16 @@ class BambuPrinterMCPServer {
5035
5075
  result = await makeCounterpart3mf(args ?? {});
5036
5076
  break;
5037
5077
 
5078
+ case "blender_mcp_setup":
5079
+ if (args?.update !== undefined && typeof args.update !== "boolean") throw new Error("update must be a boolean.");
5080
+ result = args?.update === true ? await this.blenderSetup.update(extra.signal) : await this.blenderSetup.check();
5081
+ break;
5082
+
5083
+ case "fusion_mcp_setup":
5084
+ if (args?.install !== undefined && typeof args.install !== "boolean") throw new Error("install must be a boolean.");
5085
+ result = args?.install === true ? await this.fusionSetup.install(extra.signal) : await this.fusionSetup.check();
5086
+ break;
5087
+
5038
5088
  case "fusion_mcp_status":
5039
5089
  result = await this.fusion.status(args ?? {}, extra.signal);
5040
5090
  break;
@@ -5119,6 +5169,8 @@ class BambuPrinterMCPServer {
5119
5169
  // Closing the MCP transport aborts its active requests before exit cleanup.
5120
5170
  await this.server.close();
5121
5171
  await this.fusion.close();
5172
+ // The FULU host's container (BAMBU_NETWORK_BRIDGE_IMAGE) is removed with the server, not left running.
5173
+ await this.bambuNetwork.stop();
5122
5174
  this.httpRuntime?.httpServer.close();
5123
5175
  } catch (error) {
5124
5176
  console.error("[MCP Shutdown]", error);
@@ -29,9 +29,12 @@ export async function withPrinterOperation<T>(_host: string, serial: string, ope
29
29
  finally { if (operations.get(key) === next) operations.delete(key); }
30
30
  }
31
31
 
32
- /** Inspect and send a private copy, so changes to the user's source cannot change the job. */
33
- export async function withPrintSnapshot<T>(source: string, operation: (snapshot: string, retainForDispatchedUpload: () => void) => Promise<T>): Promise<T> {
34
- const directory = await fs.mkdtemp(path.join(os.tmpdir(), "bambu-print-"));
32
+ /**
33
+ * Inspect and send a private copy, so changes to the user's source cannot change the job. `root` is where the copy
34
+ * goes (the system temporary folder unless the bridge host needs it in a folder its container mounts).
35
+ */
36
+ export async function withPrintSnapshot<T>(source: string, operation: (snapshot: string, retainForDispatchedUpload: () => void) => Promise<T>, root = os.tmpdir()): Promise<T> {
37
+ const directory = await fs.mkdtemp(path.join(root, "bambu-print-"));
35
38
  const snapshot = path.join(directory, path.basename(source));
36
39
  let retainUntilExit = false;
37
40
  try {
@@ -115,6 +115,10 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
115
115
  // The standard route preserves scene objects and needs a new output path; a configured legacy bridge promises neither.
116
116
  blender_mcp_edit_model: hints(false, true, false, true),
117
117
  fusion_mcp_status: hints(false, false, true, true), // launch: true starts Fusion on this computer
118
+ // Install add-ons into the person's own Blender or Fusion: the add-on file is replaced (kept as a backup), and
119
+ // the Fusion add-in folder, a login item and this server's .env are written. Repeating finds them current.
120
+ blender_mcp_setup: hints(false, true, true, true),
121
+ fusion_mcp_setup: hints(false, true, true, true),
118
122
  fusion_mcp_call: hints(false, true, false, true), // any Fusion tool, including execute_code
119
123
  fusion_mcp_new_design: hints(false, false, false, true), // opens another new document
120
124
  fusion_mcp_export: hints(false, false, true, true), // never overwrites; a repeat fails and changes nothing