bambu-printer-mcp 1.1.65 → 1.1.67

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.
@@ -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
@@ -57,9 +57,10 @@ 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
- import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, parse3MF } from './3mf_parser.js';
63
+ import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, hasSlicerSettingsFile, parse3MF, withExtractedSettingsCleanup } from './3mf_parser.js';
63
64
  import type { ThreeMFAmsRequirements } from "./types.js";
64
65
  import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
65
66
  import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "./studio-print-options.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
@@ -2148,12 +2160,17 @@ class BambuPrinterMCPServer {
2148
2160
 
2149
2161
  if (extension === ".3mf") {
2150
2162
  const parsed = await parse3MF(sourcePath);
2151
- const extractedSettingsPath = await extractBambuTemplateSettings(sourcePath, tempDir);
2152
2163
  const config = (parsed.slicerConfig || {}) as Record<string, any>;
2164
+ // A 3MF with no settings file says so (raw_key_count 0) rather than failing, so a client can tell a file with
2165
+ // none to keep from one whose settings couldn't be read, which stays an error.
2166
+ const hasSettingsFile = await hasSlicerSettingsFile(sourcePath);
2167
+ if (hasSettingsFile && !Object.keys(config).length) throw new Error(`The slicer settings in ${sourcePath} couldn't be read.`);
2168
+ // Returned to the caller, so it stays.
2169
+ const extractedSettingsPath = hasSettingsFile ? await extractBambuTemplateSettings(sourcePath, tempDir, { keep: true }) : undefined;
2153
2170
  return {
2154
2171
  source_path: sourcePath,
2155
2172
  source_type: "3mf",
2156
- extracted_settings_path: extractedSettingsPath,
2173
+ ...(extractedSettingsPath ? { extracted_settings_path: extractedSettingsPath } : {}),
2157
2174
  object_count: parsed.objects.length,
2158
2175
  build_item_count: parsed.build.items.length,
2159
2176
  metadata_keys: Object.keys(parsed.metadata),
@@ -2651,7 +2668,7 @@ class BambuPrinterMCPServer {
2651
2668
  },
2652
2669
  {
2653
2670
  name: "get_slice_settings",
2654
- description: "Inspect slicer settings from a saved 3MF template or a JSON/config slicer profile without slicing anything. For a 3MF given as source_path, own_process is true when slice_stl, given this call's other arguments as it would take them (slicer_profile, template_name, template_3mf_path, layer_height, wall_loops, sparse_infill_density, quality, strength), prints the process the file carries (a designer's Bambu Studio or Orca project) unchanged.",
2671
+ description: "Inspect slicer settings from a saved 3MF template or a JSON/config slicer profile without slicing anything. For a 3MF given as source_path, own_process is true when slice_stl, given this call's other arguments as it would take them (slicer_profile, template_name, template_3mf_path, layer_height, wall_loops, sparse_infill_density, quality, strength), prints the process the file carries (a designer's Bambu Studio or Orca project) unchanged. A 3MF with no slicer settings reports raw_key_count 0; a file that can't be read is an error.",
2655
2672
  inputSchema: {
2656
2673
  type: "object",
2657
2674
  properties: {
@@ -3596,9 +3613,29 @@ class BambuPrinterMCPServer {
3596
3613
  },
3597
3614
  outputSchema: MAKE_3MF_OUTPUT_SCHEMA
3598
3615
  },
3616
+ {
3617
+ name: "blender_mcp_setup",
3618
+ 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.",
3619
+ inputSchema: {
3620
+ type: "object",
3621
+ properties: { update: { type: "boolean", description: "Replace the installed add-on with the package's own (default false: check only)." } },
3622
+ additionalProperties: false
3623
+ },
3624
+ outputSchema: BLENDER_SETUP_OUTPUT_SCHEMA
3625
+ },
3626
+ {
3627
+ name: "fusion_mcp_setup",
3628
+ 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.`,
3629
+ inputSchema: {
3630
+ type: "object",
3631
+ properties: { install: { type: "boolean", description: "Install what is missing (default false: check only)." } },
3632
+ additionalProperties: false
3633
+ },
3634
+ outputSchema: FUSION_SETUP_OUTPUT_SCHEMA
3635
+ },
3599
3636
  {
3600
3637
  name: "fusion_mcp_status",
3601
- 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)}).`,
3638
+ 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.`,
3602
3639
  inputSchema: {
3603
3640
  type: "object",
3604
3641
  properties: {
@@ -3659,7 +3696,8 @@ class BambuPrinterMCPServer {
3659
3696
  };
3660
3697
  });
3661
3698
 
3662
- this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
3699
+ // A designer's settings extracted for this call are removed when it settles.
3700
+ this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
3663
3701
  const { name, arguments: args } = request.params;
3664
3702
  const sendNativeCommand = (
3665
3703
  options: Parameters<typeof sendCommandWithBambuNative>[0],
@@ -5029,6 +5067,16 @@ class BambuPrinterMCPServer {
5029
5067
  result = await makeCounterpart3mf(args ?? {});
5030
5068
  break;
5031
5069
 
5070
+ case "blender_mcp_setup":
5071
+ if (args?.update !== undefined && typeof args.update !== "boolean") throw new Error("update must be a boolean.");
5072
+ result = args?.update === true ? await this.blenderSetup.update(extra.signal) : await this.blenderSetup.check();
5073
+ break;
5074
+
5075
+ case "fusion_mcp_setup":
5076
+ if (args?.install !== undefined && typeof args.install !== "boolean") throw new Error("install must be a boolean.");
5077
+ result = args?.install === true ? await this.fusionSetup.install(extra.signal) : await this.fusionSetup.check();
5078
+ break;
5079
+
5032
5080
  case "fusion_mcp_status":
5033
5081
  result = await this.fusion.status(args ?? {}, extra.signal);
5034
5082
  break;
@@ -5094,7 +5142,7 @@ class BambuPrinterMCPServer {
5094
5142
  isError: true,
5095
5143
  };
5096
5144
  }
5097
- });
5145
+ }));
5098
5146
  }
5099
5147
 
5100
5148
  async startStdio() {
@@ -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