bambu-printer-mcp 1.1.65 → 1.1.66
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 +1 -1
- package/dist/3mf_parser.d.ts +12 -1
- package/dist/3mf_parser.js +47 -17
- package/dist/index.js +13 -6
- package/package.json +1 -1
- package/src/3mf_parser.ts +51 -17
- package/src/index.ts +12 -6
package/README.md
CHANGED
|
@@ -1139,7 +1139,7 @@ Inspect the slicer settings embedded in a saved 3MF template or in an extracted
|
|
|
1139
1139
|
}
|
|
1140
1140
|
```
|
|
1141
1141
|
|
|
1142
|
-
This returns a compact summary of the high-signal settings such as printer preset, default print profile, filament profiles, layer height, infill density, shell counts, support mode, and bed type. It accepts either `source_path` or `template_name`. For 3MF inputs it also writes the extracted settings blob to a temp path so the result can be reused directly, and returns `own_process`. With `source_path`, pass the slice's other arguments too (`slicer_profile`, `template_name`, `template_3mf_path`, `layer_height`, `wall_loops`, `sparse_infill_density`, `quality`, `strength`). `own_process` is then true when that `slice_stl` call prints the process the 3MF carries (a designer's project) unchanged.
|
|
1142
|
+
This returns a compact summary of the high-signal settings such as printer preset, default print profile, filament profiles, layer height, infill density, shell counts, support mode, and bed type. It accepts either `source_path` or `template_name`. For 3MF inputs it also writes the extracted settings blob to a temp path so the result can be reused directly, and returns `own_process`. With `source_path`, pass the slice's other arguments too (`slicer_profile`, `template_name`, `template_3mf_path`, `layer_height`, `wall_loops`, `sparse_infill_density`, `quality`, `strength`). `own_process` is then true when that `slice_stl` call prints the process the 3MF carries (a designer's project) unchanged. A 3MF with no slicer settings returns `raw_key_count` 0 and no extracted path; a file that can't be read is an error.
|
|
1143
1143
|
|
|
1144
1144
|
#### slice_with_template
|
|
1145
1145
|
|
package/dist/3mf_parser.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { ThreeMFData, CollarCharmAnalysis, ThreeMFAmsRequirements, ThreeMFPlateObjects } from './types.js';
|
|
2
|
+
/** Whether a 3MF carries a slicer settings file at all (readable or not). */
|
|
3
|
+
export declare function hasSlicerSettingsFile(filePath: string): Promise<boolean>;
|
|
2
4
|
export { ThreeMFData };
|
|
3
5
|
export declare function parse3MF(filePath: string): Promise<ThreeMFData>;
|
|
4
6
|
/** Whether a 3MF carries its own Bambu Studio/Orca process (a designer's project, not a bare mesh archive). */
|
|
5
7
|
export declare function hasBambuProjectSettings(filePath: string): Promise<boolean>;
|
|
6
|
-
|
|
8
|
+
/** Runs one operation; the directory of every settings file extracted during it is removed when it settles. */
|
|
9
|
+
export declare function withExtractedSettingsCleanup<T>(operation: () => Promise<T>): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Writes a 3MF's slicer settings to a file of their own and returns its path. Each extraction gets its own directory,
|
|
12
|
+
* removed when the surrounding withExtractedSettingsCleanup operation settles. `keep` is for a path handed back to the
|
|
13
|
+
* caller: it is named by content, so repeat calls reuse one file, and written whole before it is renamed into place.
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractBambuTemplateSettings(filePath: string, outputDir: string, options?: {
|
|
16
|
+
keep?: boolean;
|
|
17
|
+
}): Promise<string>;
|
|
7
18
|
export declare function analyzeCollarCharm3MF(filePath: string, plateIndex?: number): Promise<CollarCharmAnalysis>;
|
|
8
19
|
export declare function getCollarCharmRolePolicy(): {
|
|
9
20
|
colors: {
|
package/dist/3mf_parser.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import JSZip from 'jszip';
|
|
2
2
|
import { parseStringPromise } from 'xml2js';
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
|
-
import {
|
|
4
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
6
|
+
import * as path from 'node:path';
|
|
5
7
|
// Parses Bambu Studio's JSON config data
|
|
6
8
|
function parseBambuJSONConfig(jsonData) {
|
|
7
9
|
const config = {};
|
|
@@ -76,14 +78,21 @@ function parseBambuJSONConfig(jsonData) {
|
|
|
76
78
|
}
|
|
77
79
|
return config;
|
|
78
80
|
}
|
|
81
|
+
/** The files a 3MF's slicer settings are read from, first found wins. */
|
|
82
|
+
const SLICER_SETTINGS_FILES = [
|
|
83
|
+
'Metadata/project_settings.config',
|
|
84
|
+
'Metadata/Slic3r_PE.config',
|
|
85
|
+
'Metadata/model_settings.config',
|
|
86
|
+
'Metadata/slice_info.config'
|
|
87
|
+
];
|
|
88
|
+
/** Whether a 3MF carries a slicer settings file at all (readable or not). */
|
|
89
|
+
export async function hasSlicerSettingsFile(filePath) {
|
|
90
|
+
const zip = await JSZip.loadAsync(await fs.readFile(filePath));
|
|
91
|
+
return SLICER_SETTINGS_FILES.some(name => zip.file(name));
|
|
92
|
+
}
|
|
79
93
|
async function parseBambuConfig(zip) {
|
|
80
94
|
// Look for common Bambu config file names
|
|
81
|
-
const potentialFiles =
|
|
82
|
-
'Metadata/project_settings.config',
|
|
83
|
-
'Metadata/Slic3r_PE.config',
|
|
84
|
-
'Metadata/model_settings.config',
|
|
85
|
-
'Metadata/slice_info.config'
|
|
86
|
-
];
|
|
95
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
87
96
|
let configFile = null;
|
|
88
97
|
let configContent = '';
|
|
89
98
|
for (const name of potentialFiles) {
|
|
@@ -234,23 +243,44 @@ export async function hasBambuProjectSettings(filePath) {
|
|
|
234
243
|
return false;
|
|
235
244
|
}
|
|
236
245
|
}
|
|
237
|
-
|
|
246
|
+
const extractionScope = new AsyncLocalStorage();
|
|
247
|
+
/** Runs one operation; the directory of every settings file extracted during it is removed when it settles. */
|
|
248
|
+
export async function withExtractedSettingsCleanup(operation) {
|
|
249
|
+
const dirs = [];
|
|
250
|
+
try {
|
|
251
|
+
return await extractionScope.run(dirs, operation);
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
await Promise.all(dirs.map(dir => fs.rm(dir, { recursive: true, force: true }).catch(() => undefined)));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Writes a 3MF's slicer settings to a file of their own and returns its path. Each extraction gets its own directory,
|
|
259
|
+
* removed when the surrounding withExtractedSettingsCleanup operation settles. `keep` is for a path handed back to the
|
|
260
|
+
* caller: it is named by content, so repeat calls reuse one file, and written whole before it is renamed into place.
|
|
261
|
+
*/
|
|
262
|
+
export async function extractBambuTemplateSettings(filePath, outputDir, options = {}) {
|
|
238
263
|
const data = await fs.readFile(filePath);
|
|
239
264
|
const zip = await JSZip.loadAsync(data);
|
|
240
|
-
const potentialFiles =
|
|
241
|
-
'Metadata/project_settings.config',
|
|
242
|
-
'Metadata/Slic3r_PE.config',
|
|
243
|
-
'Metadata/model_settings.config',
|
|
244
|
-
'Metadata/slice_info.config'
|
|
245
|
-
];
|
|
265
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
246
266
|
for (const name of potentialFiles) {
|
|
247
267
|
const file = zip.file(name);
|
|
248
268
|
if (!file)
|
|
249
269
|
continue;
|
|
250
270
|
const content = await file.async('string');
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
271
|
+
if (options.keep) {
|
|
272
|
+
const digest = createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
273
|
+
const outputPath = path.join(outputDir, `${digest}_${name.replace(/\//g, '_')}`);
|
|
274
|
+
const partial = `${outputPath}.${randomUUID()}.partial`;
|
|
275
|
+
await fs.writeFile(partial, content, 'utf8');
|
|
276
|
+
await fs.rename(partial, outputPath);
|
|
277
|
+
return outputPath;
|
|
278
|
+
}
|
|
279
|
+
// Its own directory for every extraction, so two slices at once (of different projects or the same one)
|
|
280
|
+
// never share, overwrite or half-read one settings file.
|
|
281
|
+
const dir = await fs.mkdtemp(path.join(outputDir, 'slicer-settings-'));
|
|
282
|
+
extractionScope.getStore()?.push(dir);
|
|
283
|
+
const outputPath = path.join(dir, name.replace(/\//g, '_'));
|
|
254
284
|
await fs.writeFile(outputPath, content, 'utf8');
|
|
255
285
|
return outputPath;
|
|
256
286
|
}
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import { importFileViaBambuConnect } from "./bambu-connect.js";
|
|
|
29
29
|
import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
|
|
30
30
|
import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
|
|
31
31
|
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
|
|
32
|
-
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, parse3MF } from './3mf_parser.js';
|
|
32
|
+
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, hasSlicerSettingsFile, parse3MF, withExtractedSettingsCleanup } from './3mf_parser.js';
|
|
33
33
|
import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
|
|
34
34
|
import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-options.js";
|
|
35
35
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
@@ -1708,12 +1708,18 @@ class BambuPrinterMCPServer {
|
|
|
1708
1708
|
fs.mkdirSync(tempDir, { recursive: true });
|
|
1709
1709
|
if (extension === ".3mf") {
|
|
1710
1710
|
const parsed = await parse3MF(sourcePath);
|
|
1711
|
-
const extractedSettingsPath = await extractBambuTemplateSettings(sourcePath, tempDir);
|
|
1712
1711
|
const config = (parsed.slicerConfig || {});
|
|
1712
|
+
// A 3MF with no settings file says so (raw_key_count 0) rather than failing, so a client can tell a file with
|
|
1713
|
+
// none to keep from one whose settings couldn't be read, which stays an error.
|
|
1714
|
+
const hasSettingsFile = await hasSlicerSettingsFile(sourcePath);
|
|
1715
|
+
if (hasSettingsFile && !Object.keys(config).length)
|
|
1716
|
+
throw new Error(`The slicer settings in ${sourcePath} couldn't be read.`);
|
|
1717
|
+
// Returned to the caller, so it stays.
|
|
1718
|
+
const extractedSettingsPath = hasSettingsFile ? await extractBambuTemplateSettings(sourcePath, tempDir, { keep: true }) : undefined;
|
|
1713
1719
|
return {
|
|
1714
1720
|
source_path: sourcePath,
|
|
1715
1721
|
source_type: "3mf",
|
|
1716
|
-
extracted_settings_path: extractedSettingsPath,
|
|
1722
|
+
...(extractedSettingsPath ? { extracted_settings_path: extractedSettingsPath } : {}),
|
|
1717
1723
|
object_count: parsed.objects.length,
|
|
1718
1724
|
build_item_count: parsed.build.items.length,
|
|
1719
1725
|
metadata_keys: Object.keys(parsed.metadata),
|
|
@@ -2134,7 +2140,7 @@ class BambuPrinterMCPServer {
|
|
|
2134
2140
|
},
|
|
2135
2141
|
{
|
|
2136
2142
|
name: "get_slice_settings",
|
|
2137
|
-
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.",
|
|
2143
|
+
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.",
|
|
2138
2144
|
inputSchema: {
|
|
2139
2145
|
type: "object",
|
|
2140
2146
|
properties: {
|
|
@@ -3141,7 +3147,8 @@ class BambuPrinterMCPServer {
|
|
|
3141
3147
|
].map(withAnnotations).map(withRemote)
|
|
3142
3148
|
};
|
|
3143
3149
|
});
|
|
3144
|
-
this
|
|
3150
|
+
// A designer's settings extracted for this call are removed when it settles.
|
|
3151
|
+
this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
|
|
3145
3152
|
const { name, arguments: args } = request.params;
|
|
3146
3153
|
const sendNativeCommand = (options, execution = {}) => sendCommandWithBambuNative(options, { signal: extra.signal, ...execution });
|
|
3147
3154
|
const progressToken = extra._meta?.progressToken;
|
|
@@ -4349,7 +4356,7 @@ class BambuPrinterMCPServer {
|
|
|
4349
4356
|
isError: true,
|
|
4350
4357
|
};
|
|
4351
4358
|
}
|
|
4352
|
-
});
|
|
4359
|
+
}));
|
|
4353
4360
|
}
|
|
4354
4361
|
async startStdio() {
|
|
4355
4362
|
const transport = new StdioServerTransport();
|
package/package.json
CHANGED
package/src/3mf_parser.ts
CHANGED
|
@@ -2,7 +2,9 @@ import JSZip from 'jszip';
|
|
|
2
2
|
import { parseStringPromise } from 'xml2js';
|
|
3
3
|
import { ThreeMFData, BambuSlicerConfig, ThreeMFMetadata, ThreeMFObject, ThreeMFBuildItem, AMSFilamentMapping, CollarCharmAnalysis, CollarCharmRole, ThreeMFAmsRequirements, ThreeMFPlateObjects } from './types.js';
|
|
4
4
|
import * as fs from 'fs/promises';
|
|
5
|
-
import {
|
|
5
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
7
|
+
import * as path from 'node:path';
|
|
6
8
|
|
|
7
9
|
// Parses Bambu Studio's JSON config data
|
|
8
10
|
function parseBambuJSONConfig(jsonData: any): Partial<BambuSlicerConfig> {
|
|
@@ -71,14 +73,23 @@ function parseBambuJSONConfig(jsonData: any): Partial<BambuSlicerConfig> {
|
|
|
71
73
|
return config;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
/** The files a 3MF's slicer settings are read from, first found wins. */
|
|
77
|
+
const SLICER_SETTINGS_FILES = [
|
|
78
|
+
'Metadata/project_settings.config',
|
|
79
|
+
'Metadata/Slic3r_PE.config',
|
|
80
|
+
'Metadata/model_settings.config',
|
|
81
|
+
'Metadata/slice_info.config'
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/** Whether a 3MF carries a slicer settings file at all (readable or not). */
|
|
85
|
+
export async function hasSlicerSettingsFile(filePath: string): Promise<boolean> {
|
|
86
|
+
const zip = await JSZip.loadAsync(await fs.readFile(filePath));
|
|
87
|
+
return SLICER_SETTINGS_FILES.some(name => zip.file(name));
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
async function parseBambuConfig(zip: JSZip): Promise<Partial<BambuSlicerConfig>> {
|
|
75
91
|
// Look for common Bambu config file names
|
|
76
|
-
const potentialFiles =
|
|
77
|
-
'Metadata/project_settings.config',
|
|
78
|
-
'Metadata/Slic3r_PE.config',
|
|
79
|
-
'Metadata/model_settings.config',
|
|
80
|
-
'Metadata/slice_info.config'
|
|
81
|
-
];
|
|
92
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
82
93
|
let configFile = null;
|
|
83
94
|
let configContent = '';
|
|
84
95
|
|
|
@@ -241,27 +252,50 @@ export async function hasBambuProjectSettings(filePath: string): Promise<boolean
|
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
|
|
255
|
+
const extractionScope = new AsyncLocalStorage<string[]>();
|
|
256
|
+
|
|
257
|
+
/** Runs one operation; the directory of every settings file extracted during it is removed when it settles. */
|
|
258
|
+
export async function withExtractedSettingsCleanup<T>(operation: () => Promise<T>): Promise<T> {
|
|
259
|
+
const dirs: string[] = [];
|
|
260
|
+
try {
|
|
261
|
+
return await extractionScope.run(dirs, operation);
|
|
262
|
+
} finally {
|
|
263
|
+
await Promise.all(dirs.map(dir => fs.rm(dir, { recursive: true, force: true }).catch(() => undefined)));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Writes a 3MF's slicer settings to a file of their own and returns its path. Each extraction gets its own directory,
|
|
269
|
+
* removed when the surrounding withExtractedSettingsCleanup operation settles. `keep` is for a path handed back to the
|
|
270
|
+
* caller: it is named by content, so repeat calls reuse one file, and written whole before it is renamed into place.
|
|
271
|
+
*/
|
|
244
272
|
export async function extractBambuTemplateSettings(
|
|
245
273
|
filePath: string,
|
|
246
|
-
outputDir: string
|
|
274
|
+
outputDir: string,
|
|
275
|
+
options: { keep?: boolean } = {}
|
|
247
276
|
): Promise<string> {
|
|
248
277
|
const data = await fs.readFile(filePath);
|
|
249
278
|
const zip = await JSZip.loadAsync(data);
|
|
250
|
-
const potentialFiles =
|
|
251
|
-
'Metadata/project_settings.config',
|
|
252
|
-
'Metadata/Slic3r_PE.config',
|
|
253
|
-
'Metadata/model_settings.config',
|
|
254
|
-
'Metadata/slice_info.config'
|
|
255
|
-
];
|
|
279
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
256
280
|
|
|
257
281
|
for (const name of potentialFiles) {
|
|
258
282
|
const file = zip.file(name);
|
|
259
283
|
if (!file) continue;
|
|
260
284
|
|
|
261
285
|
const content = await file.async('string');
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
286
|
+
if (options.keep) {
|
|
287
|
+
const digest = createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
288
|
+
const outputPath = path.join(outputDir, `${digest}_${name.replace(/\//g, '_')}`);
|
|
289
|
+
const partial = `${outputPath}.${randomUUID()}.partial`;
|
|
290
|
+
await fs.writeFile(partial, content, 'utf8');
|
|
291
|
+
await fs.rename(partial, outputPath);
|
|
292
|
+
return outputPath;
|
|
293
|
+
}
|
|
294
|
+
// Its own directory for every extraction, so two slices at once (of different projects or the same one)
|
|
295
|
+
// never share, overwrite or half-read one settings file.
|
|
296
|
+
const dir = await fs.mkdtemp(path.join(outputDir, 'slicer-settings-'));
|
|
297
|
+
extractionScope.getStore()?.push(dir);
|
|
298
|
+
const outputPath = path.join(dir, name.replace(/\//g, '_'));
|
|
265
299
|
await fs.writeFile(outputPath, content, 'utf8');
|
|
266
300
|
return outputPath;
|
|
267
301
|
}
|
package/src/index.ts
CHANGED
|
@@ -59,7 +59,7 @@ import { importFileViaBambuConnect } from "./bambu-connect.js";
|
|
|
59
59
|
import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
|
|
60
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";
|
|
61
61
|
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';
|
|
62
|
+
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, hasSlicerSettingsFile, parse3MF, withExtractedSettingsCleanup } from './3mf_parser.js';
|
|
63
63
|
import type { ThreeMFAmsRequirements } from "./types.js";
|
|
64
64
|
import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
|
|
65
65
|
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "./studio-print-options.js";
|
|
@@ -2148,12 +2148,17 @@ class BambuPrinterMCPServer {
|
|
|
2148
2148
|
|
|
2149
2149
|
if (extension === ".3mf") {
|
|
2150
2150
|
const parsed = await parse3MF(sourcePath);
|
|
2151
|
-
const extractedSettingsPath = await extractBambuTemplateSettings(sourcePath, tempDir);
|
|
2152
2151
|
const config = (parsed.slicerConfig || {}) as Record<string, any>;
|
|
2152
|
+
// A 3MF with no settings file says so (raw_key_count 0) rather than failing, so a client can tell a file with
|
|
2153
|
+
// none to keep from one whose settings couldn't be read, which stays an error.
|
|
2154
|
+
const hasSettingsFile = await hasSlicerSettingsFile(sourcePath);
|
|
2155
|
+
if (hasSettingsFile && !Object.keys(config).length) throw new Error(`The slicer settings in ${sourcePath} couldn't be read.`);
|
|
2156
|
+
// Returned to the caller, so it stays.
|
|
2157
|
+
const extractedSettingsPath = hasSettingsFile ? await extractBambuTemplateSettings(sourcePath, tempDir, { keep: true }) : undefined;
|
|
2153
2158
|
return {
|
|
2154
2159
|
source_path: sourcePath,
|
|
2155
2160
|
source_type: "3mf",
|
|
2156
|
-
extracted_settings_path: extractedSettingsPath,
|
|
2161
|
+
...(extractedSettingsPath ? { extracted_settings_path: extractedSettingsPath } : {}),
|
|
2157
2162
|
object_count: parsed.objects.length,
|
|
2158
2163
|
build_item_count: parsed.build.items.length,
|
|
2159
2164
|
metadata_keys: Object.keys(parsed.metadata),
|
|
@@ -2651,7 +2656,7 @@ class BambuPrinterMCPServer {
|
|
|
2651
2656
|
},
|
|
2652
2657
|
{
|
|
2653
2658
|
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.",
|
|
2659
|
+
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
2660
|
inputSchema: {
|
|
2656
2661
|
type: "object",
|
|
2657
2662
|
properties: {
|
|
@@ -3659,7 +3664,8 @@ class BambuPrinterMCPServer {
|
|
|
3659
3664
|
};
|
|
3660
3665
|
});
|
|
3661
3666
|
|
|
3662
|
-
this
|
|
3667
|
+
// A designer's settings extracted for this call are removed when it settles.
|
|
3668
|
+
this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
|
|
3663
3669
|
const { name, arguments: args } = request.params;
|
|
3664
3670
|
const sendNativeCommand = (
|
|
3665
3671
|
options: Parameters<typeof sendCommandWithBambuNative>[0],
|
|
@@ -5094,7 +5100,7 @@ class BambuPrinterMCPServer {
|
|
|
5094
5100
|
isError: true,
|
|
5095
5101
|
};
|
|
5096
5102
|
}
|
|
5097
|
-
});
|
|
5103
|
+
}));
|
|
5098
5104
|
}
|
|
5099
5105
|
|
|
5100
5106
|
async startStdio() {
|