mcp-3d-printer-server 0.2.3 → 1.0.1

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.
Files changed (41) hide show
  1. package/README.md +267 -29
  2. package/dist/3mf_parser.d.ts +3 -0
  3. package/dist/3mf_parser.js +216 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +1018 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/printers/bambu.d.ts +42 -0
  8. package/dist/printers/bambu.js +278 -0
  9. package/dist/printers/creality.d.ts +10 -0
  10. package/dist/printers/creality.js +90 -0
  11. package/dist/printers/duet.d.ts +10 -0
  12. package/dist/printers/duet.js +66 -0
  13. package/dist/printers/klipper.d.ts +10 -0
  14. package/dist/printers/klipper.js +62 -0
  15. package/dist/printers/octoprint.d.ts +10 -0
  16. package/dist/printers/octoprint.js +97 -0
  17. package/dist/printers/printer-factory.d.ts +9 -0
  18. package/dist/printers/printer-factory.js +33 -0
  19. package/dist/printers/prusa.d.ts +10 -0
  20. package/dist/printers/prusa.js +93 -0
  21. package/dist/printers/repetier.d.ts +10 -0
  22. package/dist/printers/repetier.js +59 -0
  23. package/dist/stl/stl-manipulator.d.ts +140 -0
  24. package/dist/stl/stl-manipulator.js +1081 -0
  25. package/dist/test/stl-manipulator-test.d.ts +2 -0
  26. package/dist/test/stl-manipulator-test.js +91 -0
  27. package/dist/types.d.ts +75 -0
  28. package/dist/types.js +26 -0
  29. package/package.json +14 -4
  30. package/src/3mf_parser.ts +223 -0
  31. package/src/index.ts +239 -10
  32. package/src/printers/bambu.ts +305 -100
  33. package/src/stl/stl-manipulator.ts +350 -117
  34. package/src/test/3DBenchy.3mf +0 -0
  35. package/src/test/stl-manipulator-test.js +114 -0
  36. package/src/test/stl-manipulator-test.ts +124 -0
  37. package/src/test/tsconfig.json +13 -0
  38. package/src/types.ts +65 -0
  39. package/.env.example +0 -17
  40. package/scripts/mcp-inspector.js +0 -49
  41. package/tsconfig.json +0 -16
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { STLManipulator, ProgressCallback } from '../stl/stl-manipulator.js';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import * as THREE from 'three';
7
+
8
+ // Create a test directory
9
+ const TEST_DIR = path.join(process.cwd(), 'test');
10
+ if (!fs.existsSync(TEST_DIR)) {
11
+ fs.mkdirSync(TEST_DIR, { recursive: true });
12
+ }
13
+
14
+ // Path for a sample STL file
15
+ const sampleStlPath = path.join(TEST_DIR, 'sample_cube.stl');
16
+
17
+ // Create a simple cube STL for testing if it doesn't exist
18
+ async function createSampleCube() {
19
+ if (fs.existsSync(sampleStlPath)) {
20
+ console.log('Sample STL already exists, skipping creation');
21
+ return sampleStlPath;
22
+ }
23
+
24
+ console.log('Creating sample cube STL...');
25
+
26
+ // Create a simple cube geometry
27
+ const geometry = new THREE.BoxGeometry(10, 10, 10);
28
+ const material = new THREE.MeshStandardMaterial();
29
+ const mesh = new THREE.Mesh(geometry, material);
30
+
31
+ // Import STLExporter
32
+ const { STLExporter } = await import('three/examples/jsm/exporters/STLExporter.js');
33
+ const exporter = new STLExporter();
34
+
35
+ // Export as STL
36
+ const stlString = exporter.parse(mesh);
37
+
38
+ // Write to file
39
+ fs.writeFileSync(sampleStlPath, stlString);
40
+ console.log(`Sample cube saved to ${sampleStlPath}`);
41
+
42
+ return sampleStlPath;
43
+ }
44
+
45
+ // Test the STL manipulator
46
+ async function testSTLManipulator() {
47
+ try {
48
+ // Create a sample STL for testing
49
+ const stlPath = await createSampleCube();
50
+
51
+ // Create an instance of the STL manipulator with the test directory
52
+ const manipulator = new STLManipulator(TEST_DIR);
53
+
54
+ // Listen for events from the manipulator
55
+ manipulator.on('operationComplete', (data) => {
56
+ console.log('Operation complete:', data);
57
+ });
58
+
59
+ manipulator.on('operationError', (data) => {
60
+ console.error('Operation error:', data);
61
+ });
62
+
63
+ // Test progress callback
64
+ const progressCallback: ProgressCallback = (progress, message) => {
65
+ console.log(`Progress: ${progress}% - ${message || ''}`);
66
+ };
67
+
68
+ // Test 1: Get information about the STL file
69
+ console.log('\n=== Test 1: Get STL Info ===');
70
+ const stlInfo = await manipulator.getSTLInfo(stlPath);
71
+ console.log('STL Info:', stlInfo);
72
+
73
+ // Test 2: Scale the STL file
74
+ console.log('\n=== Test 2: Scale STL ===');
75
+ const scaledStlPath = await manipulator.scaleSTL(stlPath, 2.0, progressCallback);
76
+ console.log(`Scaled STL saved to: ${scaledStlPath}`);
77
+
78
+ // Test 3: Rotate the STL file
79
+ console.log('\n=== Test 3: Rotate STL ===');
80
+ const rotatedStlPath = await manipulator.rotateSTL(stlPath, [45, 0, 0], progressCallback);
81
+ console.log(`Rotated STL saved to: ${rotatedStlPath}`);
82
+
83
+ // Test 4: Translate the STL file
84
+ console.log('\n=== Test 4: Translate STL ===');
85
+ const translatedStlPath = await manipulator.translateSTL(stlPath, [5, 10, 0], progressCallback);
86
+ console.log(`Translated STL saved to: ${translatedStlPath}`);
87
+
88
+ // Test 5: Extend the base of the STL file
89
+ console.log('\n=== Test 5: Extend Base ===');
90
+ const extendedStlPath = await manipulator.extendBase(stlPath, 0.5, progressCallback);
91
+ console.log(`Extended STL saved to: ${extendedStlPath}`);
92
+
93
+ // Test 6: Modify a section of the STL file
94
+ console.log('\n=== Test 6: Modify Section (Top) ===');
95
+ const modifiedStlPath = await manipulator.modifySection(
96
+ stlPath,
97
+ 'top',
98
+ {
99
+ type: 'scale',
100
+ value: [1.5, 1.5, 1.5]
101
+ },
102
+ progressCallback
103
+ );
104
+ console.log(`Modified STL saved to: ${modifiedStlPath}`);
105
+
106
+ // Test 7: Generate visualization of the STL file
107
+ console.log('\n=== Test 7: Generate Visualization ===');
108
+ const visualizationPath = await manipulator.generateVisualization(
109
+ stlPath,
110
+ 400,
111
+ 400,
112
+ progressCallback
113
+ );
114
+ console.log(`Visualization saved to: ${visualizationPath}`);
115
+
116
+ console.log('\nAll tests completed successfully!');
117
+ } catch (error) {
118
+ console.error('An error occurred during testing:', error);
119
+ process.exit(1);
120
+ }
121
+ }
122
+
123
+ // Run the tests
124
+ testSTLManipulator().catch(console.error);
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/test",
5
+ "rootDir": ".."
6
+ },
7
+ "include": [
8
+ "../**/*.ts"
9
+ ],
10
+ "exclude": [
11
+ "node_modules"
12
+ ]
13
+ }
package/src/types.ts CHANGED
@@ -43,4 +43,69 @@ export class BambuPrinterStore {
43
43
  await printer.disconnect();
44
44
  }
45
45
  }
46
+ }
47
+
48
+ export interface SectionBounds {
49
+ minX: number; minY: number; minZ: number;
50
+ maxX: number; maxY: number; maxZ: number;
51
+ }
52
+
53
+ // New types for 3MF support
54
+ export interface ThreeMFMetadata {
55
+ // Basic metadata often found in 3dmodel.model
56
+ [key: string]: string; // Example: unit, title, etc.
57
+ }
58
+
59
+ export interface ThreeMFObject {
60
+ id: string;
61
+ name?: string;
62
+ type?: string; // e.g., model, support, modifier
63
+ mesh?: any; // Placeholder for parsed mesh data if needed later
64
+ // Add other relevant object properties
65
+ }
66
+
67
+ export interface ThreeMFBuildItem {
68
+ objectId: string;
69
+ transform?: string; // Matrix transform
70
+ // Add other relevant build item properties
71
+ }
72
+
73
+ export interface AMSFilamentMapping {
74
+ [filamentId: string]: number; // e.g., { "PLA_1": 0, "SUPPORT_W": 3 } maps filament ID to AMS slot (0-indexed)
75
+ }
76
+
77
+ // Represents the Bambu-specific slicer settings often found in a separate config file within the 3MF
78
+ export interface BambuSlicerConfig {
79
+ // Common slicing parameters (add more as needed)
80
+ layer_height?: number;
81
+ first_layer_height?: number;
82
+ sparse_infill_density?: number; // Percentage
83
+ sparse_infill_pattern?: string;
84
+ support_enabled?: boolean;
85
+ support_type?: string; // e.g., 'normal', 'tree'
86
+ support_threshold_angle?: number;
87
+ raft_layers?: number;
88
+ brim_width?: number;
89
+ wall_loops?: number;
90
+ top_shell_layers?: number;
91
+ bottom_shell_layers?: number;
92
+ // Temperatures and filament settings
93
+ nozzle_temperature?: number[]; // Array for multiple extruders/tools if applicable
94
+ bed_temperature?: number;
95
+ filament_type?: string[]; // Array of filament types used
96
+ flow_ratio?: number[]; // Array of flow ratios
97
+ ams_mapping?: AMSFilamentMapping; // Mapping of filament profiles to AMS slots
98
+ // Add other relevant Bambu settings: speeds, cooling, etc.
99
+ [key: string]: any; // Allow for arbitrary key-value pairs found in the config
100
+ }
101
+
102
+ // Main structure for parsed 3MF data
103
+ export interface ThreeMFData {
104
+ metadata: ThreeMFMetadata;
105
+ objects: ThreeMFObject[];
106
+ build: { items: ThreeMFBuildItem[] }; // Structure might vary based on 3dmodel.model parsing
107
+ slicerConfig?: Partial<BambuSlicerConfig>; // Slicer-specific settings (optional, may not be present)
108
+ // Raw XML data if needed for debugging or complex scenarios?
109
+ // rawModelXml?: any;
110
+ // rawSlicerConfig?: string;
46
111
  }
package/.env.example DELETED
@@ -1,17 +0,0 @@
1
- # Printer configuration
2
- PRINTER_HOST=localhost
3
- PRINTER_PORT=80
4
- PRINTER_TYPE=octoprint
5
- API_KEY=your_api_key_here
6
-
7
- # Bambu-specific configuration
8
- BAMBU_SERIAL=your_bambu_serial_here
9
- BAMBU_TOKEN=your_bambu_token_here
10
-
11
- # Temp directory for file processing
12
- TEMP_DIR=./temp
13
-
14
- # Slicer configuration
15
- SLICER_TYPE=prusaslicer
16
- SLICER_PATH=/path/to/slicer/executable
17
- SLICER_PROFILE=/path/to/slicer/profile
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { MCP } from '@modelcontextprotocol/sdk';
4
- import dotenv from 'dotenv';
5
-
6
- dotenv.config();
7
-
8
- // Configuration from environment variables
9
- const MCP_PORT = process.env.MCP_PORT || 3000;
10
- const MCP_HOST = process.env.MCP_HOST || 'localhost';
11
-
12
- async function inspectMCP() {
13
- console.log('MCP Inspector Starting...');
14
- console.log(`Connecting to MCP server at ${MCP_HOST}:${MCP_PORT}`);
15
-
16
- try {
17
- const mcp = new MCP({
18
- port: MCP_PORT,
19
- host: MCP_HOST,
20
- });
21
-
22
- // Get available services
23
- const services = await mcp.getServices();
24
- console.log('\nAvailable Services:');
25
- console.table(services);
26
-
27
- // Test connection status
28
- const status = await mcp.getStatus();
29
- console.log('\nMCP Connection Status:');
30
- console.table(status);
31
-
32
- // Get capabilities if supported
33
- try {
34
- const capabilities = await mcp.getCapabilities();
35
- console.log('\nMCP Capabilities:');
36
- console.table(capabilities);
37
- } catch (e) {
38
- console.log('\nCapabilities endpoint not supported or error occurred');
39
- }
40
-
41
- console.log('\nMCP Inspection Complete');
42
- } catch (error) {
43
- console.error('\nError connecting to MCP server:');
44
- console.error(error.message);
45
- process.exit(1);
46
- }
47
- }
48
-
49
- inspectMCP();
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "esModuleInterop": true,
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "declaration": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true
13
- },
14
- "include": ["src/**/*"],
15
- "exclude": ["node_modules", "dist"]
16
- }