bambu-printer-mcp 1.1.62 → 1.1.63
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.
- package/README.md +8 -0
- package/dist/counterpart/discovery.d.ts +85 -0
- package/dist/counterpart/discovery.js +119 -0
- package/dist/counterpart/filaments.d.ts +307 -0
- package/dist/counterpart/filaments.js +273 -0
- package/dist/counterpart/setup.d.ts +292 -0
- package/dist/counterpart/setup.js +91 -0
- package/dist/index.js +128 -0
- package/dist/safety/printer-state.d.ts +1 -0
- package/dist/safety/printer-state.js +1 -1
- package/dist/tool-annotations.js +3 -0
- package/package.json +1 -1
- package/src/counterpart/discovery.ts +111 -0
- package/src/counterpart/filaments.ts +297 -0
- package/src/counterpart/setup.ts +127 -0
- package/src/index.ts +120 -0
- package/src/safety/printer-state.ts +1 -1
- package/src/tool-annotations.ts +3 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* counterpart_setup_fields (counterpart/1): the printers this server drives and the settings it reads for each, by the
|
|
3
|
+
* environment variable names it reads (`env`, and older `aliases` it reads first). A client renders these fields, writes the values
|
|
4
|
+
* to this server's .env and never needs its own printer or model tables. Pure: no printer traffic, no secrets returned.
|
|
5
|
+
*/
|
|
6
|
+
import { normalizeModel } from "../safety/limits.js";
|
|
7
|
+
import { SERIAL_MODELS } from "../safety/printer-state.js";
|
|
8
|
+
import { COUNTERPART_CONTRACT, PRINTER_KINDS } from "./schemas.js";
|
|
9
|
+
|
|
10
|
+
export const SETUP_FIELD_NAMES = ["host", "port", "serial", "model", "secret", "slicer", "slicer-path", "profiles"] as const;
|
|
11
|
+
export type SetupField = {
|
|
12
|
+
/** The client's form field this is: an address, a port, a serial number, a model choice or a secret. */
|
|
13
|
+
name: typeof SETUP_FIELD_NAMES[number];
|
|
14
|
+
/** The variable to write. */
|
|
15
|
+
env: string;
|
|
16
|
+
/** Older names for it that this server reads before `env`: a client writing `env` removes these lines, or the old value wins. */
|
|
17
|
+
aliases?: string[];
|
|
18
|
+
label: string; hint?: string; required: boolean;
|
|
19
|
+
/** A path on this computer (a slicer app, a profiles folder): a client may offer a file chooser. */
|
|
20
|
+
input?: "path";
|
|
21
|
+
/** Written as typed, or upper-cased (Bambu serial numbers). */
|
|
22
|
+
transform?: "uppercase";
|
|
23
|
+
choices?: Array<{ value: string; label: string }>;
|
|
24
|
+
/** A model field: the model a serial number names, by its first `prefixLength` characters. */
|
|
25
|
+
fromSerial?: { prefixLength: number; models: Record<string, string> };
|
|
26
|
+
};
|
|
27
|
+
export type SetupKind = {
|
|
28
|
+
kind: typeof PRINTER_KINDS[number]; label: string;
|
|
29
|
+
/** Values this server needs for the kind whatever the person enters (MCP_TRANSPORT, PRINTER_TYPE). */
|
|
30
|
+
env: Record<string, string>;
|
|
31
|
+
fields: SetupField[];
|
|
32
|
+
};
|
|
33
|
+
/** The slicer this server runs, as it resolves it now, and the settings that choose it (for every printer). */
|
|
34
|
+
export type SlicerSetup = {
|
|
35
|
+
type: string;
|
|
36
|
+
/** The slicer app it would run, and whether that app is there. */
|
|
37
|
+
path?: string; found: boolean;
|
|
38
|
+
/** The Bambu profiles folder it would read (Bambu Studio and Orca), and whether it has BBL's profiles. */
|
|
39
|
+
profilesRoot?: string; profilesFound?: boolean;
|
|
40
|
+
fields: SetupField[];
|
|
41
|
+
};
|
|
42
|
+
export type SetupFields = { contract: typeof COUNTERPART_CONTRACT; server: { name: string; version: string }; kinds: SetupKind[]; model?: string; slicer?: SlicerSetup };
|
|
43
|
+
|
|
44
|
+
const SLICER_LABELS: Record<string, string> = {
|
|
45
|
+
bambustudio: "Bambu Studio", orcaslicer: "OrcaSlicer", "orcaslicer-bambulab": "OrcaSlicer-bambulab (FULU)", "orca-slicer-api": "OrcaSlicer API (remote)",
|
|
46
|
+
prusaslicer: "PrusaSlicer", cura: "Cura", slic3r: "Slic3r",
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The slicer settings, with what this server resolves now: a client shows "Bambu Studio isn't installed" or asks for
|
|
50
|
+
* its location instead of the person editing SLICER_PATH by hand. A setting is required only when what it would
|
|
51
|
+
* default to isn't there.
|
|
52
|
+
*/
|
|
53
|
+
export function slicerSetup(options: { types: readonly string[]; type: string; path?: string; found: boolean; profilesRoot?: string; profilesFound?: boolean; remote?: boolean }): SlicerSetup {
|
|
54
|
+
const label = SLICER_LABELS[options.type] ?? options.type;
|
|
55
|
+
const fields: SetupField[] = [
|
|
56
|
+
{ name: "slicer", env: "SLICER_TYPE", label: "Slicer", required: false, choices: options.types.map(value => ({ value, label: SLICER_LABELS[value] ?? value })) },
|
|
57
|
+
];
|
|
58
|
+
if (!options.remote) fields.push({ name: "slicer-path", env: "SLICER_PATH", label: `${label} app`, input: "path", required: !options.found,
|
|
59
|
+
hint: options.found ? `Found at ${options.path}. Set this only to use another copy.`
|
|
60
|
+
: options.path ? `${label} isn't at ${options.path}. Install it, or choose where it is.` : `Where ${label} is installed.` });
|
|
61
|
+
if (options.profilesFound !== undefined) fields.push({ name: "profiles", env: "BAMBU_PROFILES_ROOT", label: "Bambu profiles folder", input: "path", required: !options.profilesFound,
|
|
62
|
+
hint: options.profilesFound ? `Found at ${options.profilesRoot}. Set this only to use other profiles.` : `The folder with ${label}'s BBL profiles (it holds BBL/machine). Install ${label}, or choose the folder.` });
|
|
63
|
+
return { type: options.type, ...(options.path !== undefined ? { path: options.path } : {}), found: options.found,
|
|
64
|
+
...(options.profilesRoot !== undefined ? { profilesRoot: options.profilesRoot } : {}), ...(options.profilesFound !== undefined ? { profilesFound: options.profilesFound } : {}), fields };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Each serial prefix's model in this server's values (bambu_model), where it has one. */
|
|
68
|
+
export function serialModelValues(valid: readonly string[]): Record<string, string> {
|
|
69
|
+
return Object.fromEntries(Object.entries(SERIAL_MODELS).flatMap(([prefix, name]) => {
|
|
70
|
+
const model = normalizeModel(name);
|
|
71
|
+
return model && valid.includes(model) ? [[prefix, model]] : [];
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Bambu's display names for this server's model values ("a1mini" → "A1 Mini"). */
|
|
76
|
+
export function modelChoices(valid: readonly string[]): Array<{ value: string; label: string }> {
|
|
77
|
+
const names = new Map(Object.values(SERIAL_MODELS).map(name => [normalizeModel(name), name]));
|
|
78
|
+
return valid.map(value => ({ value, label: names.get(value) ?? value.toUpperCase() }));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function bambuSetupFields(options: { server: { name: string; version: string }; models: readonly string[]; serial?: string; slicer?: SlicerSetup }): SetupFields {
|
|
82
|
+
const fromSerial = { prefixLength: 3, models: serialModelValues(options.models) };
|
|
83
|
+
const model = options.serial ? fromSerial.models[options.serial.trim().slice(0, 3).toUpperCase()] : undefined;
|
|
84
|
+
return {
|
|
85
|
+
contract: COUNTERPART_CONTRACT,
|
|
86
|
+
server: options.server,
|
|
87
|
+
kinds: [{
|
|
88
|
+
kind: "bambu", label: "Bambu Lab", env: { MCP_TRANSPORT: "stdio" },
|
|
89
|
+
fields: [
|
|
90
|
+
{ 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
|
+
{ name: "serial", env: "BAMBU_SERIAL", aliases: ["BAMBU_PRINTER_SERIAL"], label: "Serial number", hint: "On the printer: Settings → Device", required: true, transform: "uppercase" },
|
|
92
|
+
{ name: "model", env: "BAMBU_MODEL", aliases: ["BAMBU_PRINTER_MODEL"], label: "Model", required: true, choices: modelChoices(options.models), fromSerial },
|
|
93
|
+
{ name: "secret", env: "BAMBU_TOKEN", aliases: ["BAMBU_PRINTER_ACCESS_TOKEN"], label: "Access code", hint: "On the printer: Settings → WLAN → Access Code", required: true },
|
|
94
|
+
],
|
|
95
|
+
}],
|
|
96
|
+
...(model ? { model } : {}),
|
|
97
|
+
...(options.slicer ? { slicer: options.slicer } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const field = {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
name: { type: "string", enum: [...SETUP_FIELD_NAMES] }, env: { type: "string" }, aliases: { type: "array", items: { type: "string" }, description: "Older names this server reads before env: a client writing env removes these, or the old value wins." },
|
|
105
|
+
label: { type: "string" }, hint: { type: "string" }, required: { type: "boolean" }, input: { type: "string", enum: ["path"] }, transform: { type: "string", enum: ["uppercase"] },
|
|
106
|
+
choices: { type: "array", items: { type: "object", properties: { value: { type: "string" }, label: { type: "string" } }, required: ["value", "label"] } },
|
|
107
|
+
fromSerial: { type: "object", properties: { prefixLength: { type: "integer" }, models: { type: "object", additionalProperties: { type: "string" } } }, required: ["prefixLength", "models"] },
|
|
108
|
+
},
|
|
109
|
+
required: ["name", "env", "label", "required"],
|
|
110
|
+
};
|
|
111
|
+
export const SETUP_FIELDS_OUTPUT_SCHEMA = {
|
|
112
|
+
type: "object" as const,
|
|
113
|
+
properties: {
|
|
114
|
+
contract: { type: "string", const: COUNTERPART_CONTRACT },
|
|
115
|
+
server: { type: "object", properties: { name: { type: "string" }, version: { type: "string" } }, required: ["name", "version"] },
|
|
116
|
+
kinds: { type: "array", items: { type: "object", properties: {
|
|
117
|
+
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"] } },
|
|
120
|
+
model: { type: "string" },
|
|
121
|
+
slicer: { type: "object", properties: {
|
|
122
|
+
type: { type: "string" }, path: { type: "string" }, found: { type: "boolean" }, profilesRoot: { type: "string" }, profilesFound: { type: "boolean" },
|
|
123
|
+
fields: { type: "array", items: field },
|
|
124
|
+
}, required: ["type", "found", "fields"] },
|
|
125
|
+
},
|
|
126
|
+
required: ["contract", "server", "kinds"],
|
|
127
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,9 @@ import { isDualNozzleModel } from "./safety/limits.js";
|
|
|
60
60
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName } from "./safety/artifact.js";
|
|
61
61
|
import { detectProfilesRoot } from "./slicer/profile-flatten.js";
|
|
62
62
|
import { bambuPrinterInfo, bambuSliceCapabilities } from "./counterpart/info.js";
|
|
63
|
+
import { DISCOVER_OUTPUT_SCHEMA, discoverBambu } from "./counterpart/discovery.js";
|
|
64
|
+
import { SETUP_FIELDS_OUTPUT_SCHEMA, bambuSetupFields, slicerSetup, type SlicerSetup } from "./counterpart/setup.js";
|
|
65
|
+
import { PROPOSE_FILAMENTS_INPUT_PROPERTIES, PROPOSE_FILAMENTS_OUTPUT_SCHEMA, NO_COLOUR_NAMES, bambuTrayLabel, loadColourNames, proposeFilaments, spoolName, type ColourNames, type ProposalTray } from "./counterpart/filaments.js";
|
|
63
66
|
import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_CAPABILITY_URI, SERVER_INSTRUCTIONS } from "./design-guidance.js";
|
|
64
67
|
import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
65
68
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
@@ -135,6 +138,7 @@ const SERVER_INFO = {
|
|
|
135
138
|
/** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
|
|
136
139
|
const OUTPUT_SCHEMA_TOOLS = new Set([
|
|
137
140
|
"counterpart_printer_info", "counterpart_print_progress", "counterpart_make_3mf",
|
|
141
|
+
"counterpart_discover_printers", "counterpart_setup_fields", "counterpart_propose_filaments",
|
|
138
142
|
"fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
|
|
139
143
|
"camera_stream_start", "camera_frame", "camera_stream_stop",
|
|
140
144
|
]);
|
|
@@ -318,6 +322,10 @@ type PrinterFilamentInventory = {
|
|
|
318
322
|
profile_resolution: "exact-model-nozzle" | "model" | "generic" | "unresolved";
|
|
319
323
|
match_confidence: "high" | "medium" | "low" | "none";
|
|
320
324
|
display_name: string;
|
|
325
|
+
/** Where the tray sits, as Bambu Studio labels it ("A2"). */
|
|
326
|
+
label: string | null;
|
|
327
|
+
/** The spool as a person names it: Bambu's colour name and product ("Sunflower Yellow PLA Basic"). */
|
|
328
|
+
spool_name: string | null;
|
|
321
329
|
profile_candidates: string[];
|
|
322
330
|
}>;
|
|
323
331
|
recommended: {
|
|
@@ -335,6 +343,44 @@ const COLLAR_CHARM_POLICY = getCollarCharmRolePolicy();
|
|
|
335
343
|
|
|
336
344
|
let filamentProfileIndexCache: FilamentProfileIndex | null = null;
|
|
337
345
|
|
|
346
|
+
/** The configured slicer's BBL filament profile folder, when the slicer configuration resolves. */
|
|
347
|
+
function filamentProfileDirectory(): string | undefined {
|
|
348
|
+
try {
|
|
349
|
+
const { slicerType, slicerPath } = resolveSlicerConfig(undefined);
|
|
350
|
+
return path.join(detectProfilesRoot(slicerPath, slicerType), "BBL", "filament");
|
|
351
|
+
} catch { return undefined; }
|
|
352
|
+
}
|
|
353
|
+
/** An executable path, or a bare command found on PATH. */
|
|
354
|
+
function executableExists(command: string): boolean {
|
|
355
|
+
if (!command) return false;
|
|
356
|
+
if (command.includes("/") || command.includes("\\")) return fs.existsSync(command);
|
|
357
|
+
return (process.env.PATH ?? "").split(path.delimiter).some(dir => dir && fs.existsSync(path.join(dir, command)));
|
|
358
|
+
}
|
|
359
|
+
/** A Bambu profile tree: BBL's machine profiles, or Orca's packed BBL.opc. */
|
|
360
|
+
function bblProfilesAt(root: string): boolean {
|
|
361
|
+
return fs.existsSync(path.join(root, "BBL", "machine")) || fs.existsSync(path.join(root, "BBL.opc"));
|
|
362
|
+
}
|
|
363
|
+
/** The slicer this server would run now and the settings that choose it, for counterpart_setup_fields. */
|
|
364
|
+
function slicerSetupNow(): SlicerSetup {
|
|
365
|
+
let config: { slicerType: string; slicerPath: string };
|
|
366
|
+
try { config = resolveSlicerConfig(undefined); } catch { config = { slicerType: String(DEFAULT_SLICER_TYPE), slicerPath: "" }; }
|
|
367
|
+
if (config.slicerType === "orca-slicer-api") return slicerSetup({ types: SLICER_TYPES, type: config.slicerType, found: Boolean(process.env.SLICER_API_URL), remote: true });
|
|
368
|
+
const bbl = ["bambustudio", "orcaslicer", "orcaslicer-bambulab"].includes(config.slicerType);
|
|
369
|
+
let profilesRoot: string | undefined;
|
|
370
|
+
try { profilesRoot = bbl ? detectProfilesRoot(config.slicerPath, config.slicerType) : undefined; } catch { profilesRoot = undefined; }
|
|
371
|
+
return slicerSetup({ types: SLICER_TYPES, type: config.slicerType, path: config.slicerPath, found: executableExists(config.slicerPath),
|
|
372
|
+
...(bbl ? { profilesFound: Boolean(profilesRoot && bblProfilesAt(profilesRoot)), ...(profilesRoot ? { profilesRoot } : {}) } : {}) });
|
|
373
|
+
}
|
|
374
|
+
let colourNamesCache: ColourNames | null = null;
|
|
375
|
+
/** Bambu Studio's own colour names for its filaments, read once from the configured slicer's profiles. */
|
|
376
|
+
function colourNames(): ColourNames {
|
|
377
|
+
if (colourNamesCache) return colourNamesCache;
|
|
378
|
+
const names = loadColourNames(filamentProfileDirectory());
|
|
379
|
+
// A slicer installed later still names its colours: only a table that loaded is kept.
|
|
380
|
+
if (names !== NO_COLOUR_NAMES) colourNamesCache = names;
|
|
381
|
+
return names;
|
|
382
|
+
}
|
|
383
|
+
|
|
338
384
|
function buildFilamentProfileIndex(): FilamentProfileIndex {
|
|
339
385
|
const byName = new Map<string, string>();
|
|
340
386
|
const baseNameByFilamentId = new Map<string, string>();
|
|
@@ -501,6 +547,9 @@ function normalizePrinterFilamentInventory(
|
|
|
501
547
|
profile_resolution: profileResolution.resolution,
|
|
502
548
|
match_confidence: matchConfidence,
|
|
503
549
|
display_name: displayParts.length > 0 ? displayParts.join(" ") : "empty/unknown",
|
|
550
|
+
label: amsId !== null && trayId !== null ? bambuTrayLabel(amsId, trayId) : null,
|
|
551
|
+
spool_name: trayType ? spoolName(traySubBrands || trayType,
|
|
552
|
+
trayInfoIdx && trayColor ? colourNames().spool(trayInfoIdx, trayColor) : undefined) : null,
|
|
504
553
|
profile_candidates: profileResolution.paths,
|
|
505
554
|
});
|
|
506
555
|
}
|
|
@@ -3416,6 +3465,44 @@ class BambuPrinterMCPServer {
|
|
|
3416
3465
|
},
|
|
3417
3466
|
outputSchema: PRINTER_INFO_OUTPUT_SCHEMA
|
|
3418
3467
|
},
|
|
3468
|
+
{
|
|
3469
|
+
name: "counterpart_discover_printers",
|
|
3470
|
+
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.",
|
|
3471
|
+
inputSchema: {
|
|
3472
|
+
type: "object",
|
|
3473
|
+
properties: { duration_ms: { type: "integer", minimum: 500, maximum: 15000, description: "How long to listen (default 4000)." } },
|
|
3474
|
+
additionalProperties: false
|
|
3475
|
+
},
|
|
3476
|
+
outputSchema: DISCOVER_OUTPUT_SCHEMA
|
|
3477
|
+
},
|
|
3478
|
+
{
|
|
3479
|
+
name: "counterpart_setup_fields",
|
|
3480
|
+
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.",
|
|
3481
|
+
inputSchema: {
|
|
3482
|
+
type: "object",
|
|
3483
|
+
properties: { serial: { type: "string", maxLength: 64, description: "A Bambu serial number: model is the one it names, when known." } },
|
|
3484
|
+
additionalProperties: false
|
|
3485
|
+
},
|
|
3486
|
+
outputSchema: SETUP_FIELDS_OUTPUT_SCHEMA
|
|
3487
|
+
},
|
|
3488
|
+
{
|
|
3489
|
+
name: "counterpart_propose_filaments",
|
|
3490
|
+
description: "Counterpart contract (counterpart/1): which loaded AMS spool prints each of a model's colours, before slicing. Reads the live AMS once. trays lists the spools a person may choose (label like \"A2\", a person-readable name, colour, material, feed). proposal gives each filament its nearest spool in OKLab colour with the asked-for material preferred, and a verdict: same-colour, closest (that colour isn't loaded; note says so), no-colour or none. One print feeds from one source. Pass chosen to check the person's spools against what is loaded now; mapping then lists every filament slot's spool (painted slots included), and problems says why a choice can't print.",
|
|
3491
|
+
inputSchema: {
|
|
3492
|
+
type: "object",
|
|
3493
|
+
properties: {
|
|
3494
|
+
...PROPOSE_FILAMENTS_INPUT_PROPERTIES,
|
|
3495
|
+
bambu_model: { type: "string", description: "Printer model; defaults to BAMBU_MODEL. Selects the filament profiles that decide which spools can slice." },
|
|
3496
|
+
nozzle_diameter: { type: "string", description: "Nozzle diameter (default NOZZLE_DIAMETER or 0.4)." },
|
|
3497
|
+
host: { type: "string", description: "Hostname or IP of the printer (default: value from env)" },
|
|
3498
|
+
bambu_serial: { type: "string", description: "Serial number (default: value from env)" },
|
|
3499
|
+
bambu_token: { type: "string", description: "Access token (default: value from env); never returned." }
|
|
3500
|
+
},
|
|
3501
|
+
required: ["filaments"],
|
|
3502
|
+
additionalProperties: false
|
|
3503
|
+
},
|
|
3504
|
+
outputSchema: PROPOSE_FILAMENTS_OUTPUT_SCHEMA
|
|
3505
|
+
},
|
|
3419
3506
|
{
|
|
3420
3507
|
name: "counterpart_print_route",
|
|
3421
3508
|
description: "Counterpart contract (counterpart/1): how this server reaches the printer for prints and for Stop/Pause/Resume. route is \"lan\" (the local network through FULU's BambuNetwork bridge, or the configured X2D native or Bambu Connect mode), \"cloud\" (Bambu Cloud through FULU's bridge) or \"developer\" (the local network straight to a printer in LAN Only + Developer Mode, whose Pause, Resume and Stop need no Bambu app). options lists each with its label, whether it can be chosen here (and why not) and what controls do on it; choices lists the ids that can be chosen. mode and type are BAMBU_DEFAULT_CONNECTION_MODE and BAMBU_DEFAULT_CONNECTION_TYPE as resolved. Pass route to change it: the change applies to the next print and control at once, and is saved to the .env file in this server's working directory when that file exists (savedTo; null otherwise). Sends nothing to the printer.",
|
|
@@ -4819,6 +4906,39 @@ class BambuPrinterMCPServer {
|
|
|
4819
4906
|
);
|
|
4820
4907
|
break;
|
|
4821
4908
|
|
|
4909
|
+
case "counterpart_discover_printers": {
|
|
4910
|
+
const requested = Number(args?.duration_ms);
|
|
4911
|
+
const found = await discoverBambu(Number.isFinite(requested) ? requested : 4000);
|
|
4912
|
+
// Only models bambu_model accepts: the X1 (serial 00W) has none, so it stays unset.
|
|
4913
|
+
result = { contract: "counterpart/1", network: found.state, printers: found.printers.map(({ model, ...printer }) =>
|
|
4914
|
+
({ ...printer, ...(model && (VALID_BAMBU_MODELS as readonly string[]).includes(model) ? { model } : {}) })) };
|
|
4915
|
+
break;
|
|
4916
|
+
}
|
|
4917
|
+
|
|
4918
|
+
case "counterpart_setup_fields":
|
|
4919
|
+
result = bambuSetupFields({ server: SERVER_INFO, models: VALID_BAMBU_MODELS, slicer: slicerSetupNow(), ...(typeof args?.serial === "string" ? { serial: args.serial } : {}) });
|
|
4920
|
+
break;
|
|
4921
|
+
|
|
4922
|
+
case "counterpart_propose_filaments": {
|
|
4923
|
+
const requestedModel = (String(args?.bambu_model ?? DEFAULT_BAMBU_MODEL ?? "")).trim().toLowerCase();
|
|
4924
|
+
const normalizedModel = requestedModel ? validateBambuModel(requestedModel) : undefined;
|
|
4925
|
+
const inventory = await this.getResolvedPrinterFilamentInventory(host, bambuSerial, bambuToken, normalizedModel,
|
|
4926
|
+
String(args?.nozzle_diameter || DEFAULT_NOZZLE_DIAMETER));
|
|
4927
|
+
const trays: ProposalTray[] = inventory.trays.flatMap(tray => {
|
|
4928
|
+
const colour = normalizeRgbColor(tray.tray_color);
|
|
4929
|
+
if (!tray.loaded || tray.slot === null || !colour || !tray.tray_type || !tray.label) return [];
|
|
4930
|
+
// print_3mf's tray value: an AMS-HT unit (id 128 and up, one tray) is its unit id, not ams_id × 4 + tray.
|
|
4931
|
+
const slot = tray.ams_id !== null && tray.ams_id >= 128 ? tray.ams_id : tray.slot;
|
|
4932
|
+
return [{ slot, label: tray.label, name: tray.spool_name ?? tray.tray_type, colour: `#${colour.toUpperCase()}`,
|
|
4933
|
+
material: tray.tray_type, filamentId: tray.tray_info_idx ?? "", feed: "ams", sliceable: Boolean(tray.resolved_profile_path),
|
|
4934
|
+
...(tray.resolved_profile_path ? { profile: tray.resolved_profile_path } : {}) }];
|
|
4935
|
+
});
|
|
4936
|
+
result = proposeFilaments({ trays, filaments: Array.isArray(args?.filaments) ? args.filaments : [],
|
|
4937
|
+
...(Array.isArray(args?.painted) ? { painted: args.painted } : {}), ...(Array.isArray(args?.chosen) ? { chosen: args.chosen } : {}),
|
|
4938
|
+
sliced: args?.sliced === true, names: colourNames() });
|
|
4939
|
+
break;
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4822
4942
|
case "counterpart_printer_info":
|
|
4823
4943
|
result = bambuPrinterInfo({ server: SERVER_INFO, host, serial: bambuSerial, model: this.displayModel(args, bambuSerial), slicerType: normalizeSlicerType(DEFAULT_SLICER_TYPE) });
|
|
4824
4944
|
break;
|
|
@@ -4,7 +4,7 @@ import { BambuClient, GetVersionCommand, PushAllCommand } from "bambu-node";
|
|
|
4
4
|
import { isDualNozzleModel, normalizeMaterial, normalizeModel } from "./limits.js";
|
|
5
5
|
|
|
6
6
|
const MAX_REPORT_AGE_MS = 15_000;
|
|
7
|
-
const MODEL_IDS: Record<string, string> = {
|
|
7
|
+
export const MODEL_IDS: Record<string, string> = {
|
|
8
8
|
O1C: "H2C", O1C2: "H2C", O1D: "H2D", O1E: "H2D Pro", O1S: "H2S", N6: "X2D",
|
|
9
9
|
N2S: "A1", A1M: "A1 Mini", C11: "P1P", C12: "P1S", C13: "X1E", "BL-P001": "X1C", "BL-P002": "X1",
|
|
10
10
|
};
|
package/src/tool-annotations.ts
CHANGED
|
@@ -40,6 +40,8 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
|
|
|
40
40
|
resolve_3mf_ams_slots: READ_OUTSIDE, // reads the live AMS inventory
|
|
41
41
|
list_printer_files: READ_OUTSIDE,
|
|
42
42
|
counterpart_print_progress: READ_OUTSIDE,
|
|
43
|
+
counterpart_discover_printers: READ_OUTSIDE, // listens for the printers' own SSDP announcements
|
|
44
|
+
counterpart_propose_filaments: READ_OUTSIDE, // reads the live AMS inventory
|
|
43
45
|
// connect: true starts the bridge agent, which writes its configuration and device identity and can replace certificates.
|
|
44
46
|
bambu_network_bridge_status: hints(false, true, true, true),
|
|
45
47
|
camera_frame: READ_OUTSIDE,
|
|
@@ -56,6 +58,7 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
|
|
|
56
58
|
list_templates: READ_LOCAL,
|
|
57
59
|
get_slice_settings: LOCAL_OUTPUT, // a 3MF's settings are extracted to a fixed file in the temporary directory
|
|
58
60
|
counterpart_printer_info: READ_LOCAL, // configuration and capabilities; sends nothing to the printer
|
|
61
|
+
counterpart_setup_fields: READ_LOCAL, // the settings this server reads; no configured values
|
|
59
62
|
|
|
60
63
|
// Local outputs in the server's temporary directory
|
|
61
64
|
extend_stl_base: LOCAL_OUTPUT,
|