bambu-printer-mcp 1.1.94 → 1.1.95

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.
@@ -46,6 +46,7 @@ export function bambuPrinterInfo(options: { server: { name: string; version: str
46
46
  // camera_snapshot needs the model to choose its transport.
47
47
  camera: model && TCP_CAMERA_MODELS.has(model) ? "bambu-tcp" : model && RTSP_CAMERA_MODELS.has(model) ? "rtsp" : "none",
48
48
  cameraStream: !!model && (TCP_CAMERA_MODELS.has(model) || RTSP_CAMERA_MODELS.has(model)),
49
+ diagnostics: true,
49
50
  filaments: "ams",
50
51
  pause: true,
51
52
  resume: true,
@@ -41,6 +41,7 @@ export const REMOTE_SCOPES: Readonly<Record<string, RemoteScope>> = {
41
41
  blender_mcp_status: "read",
42
42
  counterpart_printer_info: "read",
43
43
  counterpart_self_check: "read",
44
+ counterpart_diagnostics: "read", // this server's own redacted logs; nothing reaches the printer
44
45
  counterpart_print_progress: "read",
45
46
  counterpart_print_record: "read",
46
47
  counterpart_print_assess: "control", // local evidence mutation, never a printer command
@@ -35,6 +35,8 @@ export type PrinterInfo = {
35
35
  progress: boolean; layers: boolean;
36
36
  camera: "bambu-tcp" | "rtsp" | "http-snapshot" | "none";
37
37
  cameraStream?: boolean;
38
+ /** counterpart_diagnostics is here: this server hands over its own redacted diagnostics bundle. */
39
+ diagnostics?: boolean;
38
40
  filaments: "ams" | "single" | "none";
39
41
  pause: boolean; resume: boolean; cancel: boolean; print3mf: boolean; gcode: boolean;
40
42
  /** What slice_stl can apply with this server's slicer (the same field in mcp-3D-printer-server). */
@@ -77,6 +79,7 @@ export const PRINTER_INFO_OUTPUT_SCHEMA = {
77
79
  layers: { type: "boolean" },
78
80
  camera: { type: "string", enum: ["bambu-tcp", "rtsp", "http-snapshot", "none"] },
79
81
  cameraStream: { type: "boolean" },
82
+ diagnostics: { type: "boolean", description: "counterpart_diagnostics is available." },
80
83
  filaments: { type: "string", enum: ["ams", "single", "none"] },
81
84
  pause: { type: "boolean" },
82
85
  resume: { type: "boolean" },
package/src/index.ts CHANGED
@@ -89,6 +89,7 @@ import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
89
89
  import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
90
90
  import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
91
91
  import { SELF_CHECK_OUTPUT_SCHEMA, selfCheck } from "./counterpart/self-check.js";
92
+ import { DIAGNOSTICS_INPUT_PROPERTIES, DIAGNOSTICS_OUTPUT_SCHEMA, appVersion, buildDiagnostics, captureServerLog, diagnosticsBudget, jsonText, recordToolError, rememberSecretArguments, serverLogText, settingsSnapshot, toolErrorsText, type DiagnosticsSource } from "./counterpart/diagnostics.js";
92
93
  import { parseProcessOverrides } from "./slicer/process-overrides.js";
93
94
  import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
94
95
  import { PrinterRefusal, withPrintDispatch, markPrintCommandSent, printOutcome } from "./refusal.js";
@@ -96,12 +97,16 @@ import { uploadProgressReporter } from "./upload-progress.js";
96
97
  import { machinePauseGcode, parsePauseLayers, pausedLayers, readPlateGcode } from "./slicer/layer-pauses.js";
97
98
 
98
99
  dotenv.config();
100
+ // What the server writes to stderr is also kept for counterpart_diagnostics.
101
+ captureServerLog();
99
102
 
100
103
  const CAD_ENABLED = cadEnabled();
101
104
  const DEFAULT_HOST = process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST || "localhost";
102
105
  const DEFAULT_BAMBU_SERIAL = process.env.BAMBU_PRINTER_SERIAL || process.env.BAMBU_SERIAL || "";
103
106
  const DEFAULT_BAMBU_TOKEN =
104
107
  process.env.BAMBU_PRINTER_ACCESS_TOKEN || process.env.BAMBU_TOKEN || "";
108
+ /** Access-code names people try that this server does not read (counterpart_diagnostics names them when set). */
109
+ const UNREAD_ACCESS_CODE_NAMES = ["BAMBU_PRINTER_ACCESS_CODE", "BAMBU_ACCESS_CODE", "BAMBU_ACCESS_TOKEN", "BAMBU_PRINTER_TOKEN"];
105
110
  const DEFAULT_BAMBU_DEV_ID = process.env.BAMBU_DEV_ID || DEFAULT_BAMBU_SERIAL;
106
111
  // os.tmpdir(), not process.cwd() — a packaged Claude Desktop extension is
107
112
  // spawned with a cwd we don't control (and may not be writable), so a
@@ -162,7 +167,7 @@ const SERVER_INFO = {
162
167
  /** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
163
168
  const OUTPUT_SCHEMA_TOOLS = new Set([
164
169
  "cad_status", "cad_setup", "cad_run", "cad_check_fit", "cad_examples",
165
- "counterpart_printer_info", "counterpart_self_check", "counterpart_print_progress", "counterpart_make_3mf",
170
+ "counterpart_printer_info", "counterpart_self_check", "counterpart_diagnostics", "counterpart_print_progress", "counterpart_make_3mf",
166
171
  "counterpart_discover_printers", "counterpart_setup_fields", "counterpart_propose_filaments",
167
172
  "fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
168
173
  "camera_stream_start", "camera_frame", "camera_stream_stop",
@@ -3574,6 +3579,12 @@ class BambuPrinterMCPServer {
3574
3579
  inputSchema: { type: "object", properties: {} },
3575
3580
  outputSchema: SELF_CHECK_OUTPUT_SCHEMA
3576
3581
  },
3582
+ {
3583
+ name: "counterpart_diagnostics",
3584
+ description: "Counterpart contract (counterpart/1): this server's own diagnostics for a bug report, as files for the client to add to its export: the configured printers (model, serial, connection; firmware is not read), this server's settings, slicer path and version, CAD runtime status, recent tool errors, this run's stderr log (MQTT and connection messages). The Bambu network plug-in logs are not included. Redaction fails closed: configured secrets go in their encoded forms, JSON is redacted by key, and any log line that names a secret is withheld whole; serial numbers, error codes and whether a secret is set stay. Names, contents and notes stay within max_bytes; anything missing is listed in notes. Sends nothing to the printer.",
3585
+ inputSchema: { type: "object", properties: DIAGNOSTICS_INPUT_PROPERTIES, additionalProperties: false },
3586
+ outputSchema: DIAGNOSTICS_OUTPUT_SCHEMA
3587
+ },
3577
3588
  {
3578
3589
  name: "counterpart_discover_printers",
3579
3590
  description: "Counterpart contract (counterpart/1): Bambu printers on the local network, from their own SSDP announcements (UDP 2021), with serial, model (as bambu_model names it), name and firmware. Listens for duration_ms (default 4000). network is \"unavailable\" when another app holds the port. Never connects to or authenticates with a printer.",
@@ -3762,6 +3773,7 @@ class BambuPrinterMCPServer {
3762
3773
  // A designer's settings extracted for this call are removed when it settles.
3763
3774
  this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withPrintDispatch(() => withExtractedSettingsCleanup(async () => {
3764
3775
  const { name, arguments: args } = request.params;
3776
+ rememberSecretArguments(args);
3765
3777
  const sendNativeCommand = (
3766
3778
  options: Parameters<typeof sendCommandWithBambuNative>[0],
3767
3779
  execution: Parameters<typeof sendCommandWithBambuNative>[1] = {}
@@ -5109,6 +5121,10 @@ class BambuPrinterMCPServer {
5109
5121
  result = await selfCheck(SERVER_INFO);
5110
5122
  break;
5111
5123
 
5124
+ case "counterpart_diagnostics":
5125
+ result = await this.diagnostics(args ?? {});
5126
+ break;
5127
+
5112
5128
  case "counterpart_printer_info":
5113
5129
  result = bambuPrinterInfo({ server: SERVER_INFO, host, serial: bambuSerial, model: this.displayModel(args, bambuSerial), slicerType: normalizeSlicerType(DEFAULT_SLICER_TYPE) });
5114
5130
  break;
@@ -5243,6 +5259,7 @@ class BambuPrinterMCPServer {
5243
5259
  return { content: [{ type: "text", text }] };
5244
5260
 
5245
5261
  } catch (error) {
5262
+ recordToolError(name, error);
5246
5263
  if (name.startsWith("cad_")) {
5247
5264
  const failure = await this.cad.failure(error, name);
5248
5265
  return {isError: true, content: [{type: "text" as const, text: failure.message}], structuredContent: failure};
@@ -5280,6 +5297,70 @@ class BambuPrinterMCPServer {
5280
5297
  })));
5281
5298
  }
5282
5299
 
5300
+ /** counterpart_diagnostics: this server's own redacted bundle (src/counterpart/diagnostics.ts). Sends nothing to a printer. */
5301
+ private async diagnostics(args: Record<string, unknown>): Promise<ReturnType<typeof buildDiagnostics>> {
5302
+ const unknown = Object.keys(args).filter(key => key !== "printer" && key !== "max_bytes");
5303
+ if (unknown.length) throw new Error(`counterpart_diagnostics takes only printer and max_bytes, not ${unknown.join(", ")}.`);
5304
+ if (args.printer !== undefined && typeof args.printer !== "string") throw new Error("printer must be a string.");
5305
+ const maxBytes = diagnosticsBudget(args.max_bytes);
5306
+ const wanted = (args.printer as string | undefined)?.trim().toLowerCase();
5307
+ const notes: string[] = [];
5308
+ // This server's own sentences, built only from setting names it reads: their secret words name settings.
5309
+ const fixedNotes: string[] = [];
5310
+
5311
+ const model = DEFAULT_BAMBU_MODEL || undefined;
5312
+ let connection: { mode: string; type: string } | { error: string };
5313
+ try { connection = resolveConnection(undefined, model); } catch (error) { connection = { error: error instanceof Error ? error.message : String(error) }; }
5314
+ const configured = DEFAULT_BAMBU_SERIAL || process.env.BAMBU_PRINTER_HOST || process.env.PRINTER_HOST;
5315
+ const printers = configured ? [{
5316
+ id: DEFAULT_BAMBU_SERIAL || DEFAULT_HOST,
5317
+ kind: "bambu",
5318
+ host: DEFAULT_HOST,
5319
+ ...(DEFAULT_BAMBU_SERIAL ? { serial: DEFAULT_BAMBU_SERIAL } : {}),
5320
+ ...(model ? { model } : {}),
5321
+ connection,
5322
+ accessCodeSet: Boolean(DEFAULT_BAMBU_TOKEN),
5323
+ // Firmware comes only from the printer; this tool asks it nothing.
5324
+ firmware: "unknown",
5325
+ }] : [];
5326
+ if (!configured) notes.push("No printer is configured (BAMBU_SERIAL and BAMBU_PRINTER_HOST are unset).");
5327
+ // A look-alike name this server never reads leaves accessCodeSet false; name it so the bundle says why.
5328
+ const ignored = UNREAD_ACCESS_CODE_NAMES.filter(key => process.env[key]);
5329
+ if (ignored.length) fixedNotes.push(`${ignored.join(" and ")} ${ignored.length > 1 ? "are" : "is"} set, but this server reads the access code only from BAMBU_TOKEN or BAMBU_PRINTER_ACCESS_TOKEN (in the environment or its .env).`);
5330
+ const selected = wanted ? printers.filter(p => [p.id, p.host, p.serial].some(v => v?.toLowerCase() === wanted)) : printers;
5331
+ if (wanted && !selected.length) notes.push(`No configured printer is ${args.printer}; printers.json lists none.`);
5332
+ if (printers.length) notes.push("Printer firmware is not included: only the printer reports it, and this tool sends it nothing.");
5333
+
5334
+ let slicer: Record<string, unknown>;
5335
+ try {
5336
+ const { fields: _fields, ...setup } = slicerSetupNow();
5337
+ const version = appVersion(setup.path);
5338
+ slicer = { ...setup, ...(version ? { version } : {}) };
5339
+ if (setup.type === "orca-slicer-api") { if (!setup.found) notes.push("The remote OrcaSlicer API slicer has no SLICER_API_URL."); }
5340
+ else if (!setup.found) notes.push(`The ${setup.type} slicer is not installed where this server looks (${setup.path ?? "no path"}).`);
5341
+ else if (!version && setup.path) notes.push("Slicer version is unknown: its install doesn't name it, and this tool doesn't run the slicer.");
5342
+ } catch (error) { slicer = { error: error instanceof Error ? error.message : String(error) }; }
5343
+
5344
+ let cad: unknown;
5345
+ try { cad = await this.cad.status(); } catch (error) { cad = { error: error instanceof Error ? error.message : String(error) }; }
5346
+
5347
+ const settings = settingsSnapshot(/^(?:BAMBU|PRINTER|SLICER|ORCA|CAD|BLENDER|FUSION|BED_TYPE|NOZZLE|MCP|PJARCZAK|FULU|TEMP_DIR)/);
5348
+
5349
+ const sources: DiagnosticsSource[] = [
5350
+ { name: "server.json", text: jsonText({ package: SERVER_INFO.name, version: SERVER_INFO.version, node: process.version, platform: process.platform, arch: process.arch, uptimeSec: Math.round(process.uptime()) }) },
5351
+ { name: "printers.json", text: jsonText({ printers: selected }) },
5352
+ { name: "settings.json", text: jsonText(settings) },
5353
+ { name: "slicer.json", text: jsonText(slicer) },
5354
+ { name: "cad.json", text: jsonText(cad) },
5355
+ { name: "tool-errors.log", text: toolErrorsText() || "No tool has failed since this server started.\n" },
5356
+ { name: "server-stderr.log", text: serverLogText() || "Nothing written to stderr since this server started.\n" },
5357
+ ];
5358
+ // The Bambu network plug-in and native helper logs are written by other programs, in forms this server does not
5359
+ // control, and can carry secrets it never held (a cloud token, another printer's code): they stay out.
5360
+ fixedNotes.push("The Bambu network plug-in (fulu) and native helper logs are not included: other programs write them, and they can hold secrets this server cannot recognise.");
5361
+ return buildDiagnostics({ package: SERVER_INFO.name, version: SERVER_INFO.version, sources, notes, fixedNotes, maxBytes, secrets: DEFAULT_BAMBU_TOKEN ? [DEFAULT_BAMBU_TOKEN] : [] });
5362
+ }
5363
+
5283
5364
  async startStdio() {
5284
5365
  const transport = new StdioServerTransport();
5285
5366
  await this.server.connect(transport);
@@ -68,6 +68,7 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
68
68
  get_slice_settings: LOCAL_OUTPUT, // a 3MF's settings are extracted to a fixed file in the temporary directory
69
69
  counterpart_printer_info: READ_LOCAL, // configuration and capabilities; sends nothing to the printer
70
70
  counterpart_self_check: READ_LOCAL, // loads this install's own modules; sends nothing to the printer
71
+ counterpart_diagnostics: READ_LOCAL, // reads this server's own logs and settings, redacted; sends nothing to the printer
71
72
  counterpart_setup_fields: READ_LOCAL, // the settings this server reads; no configured values
72
73
 
73
74
  // Local outputs in the server's temporary directory