mcp-3d-printer-server 0.1.0 → 0.2.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.
- package/.env.example +17 -0
- package/README.md +226 -1
- package/dist/index.js +487 -0
- package/dist/stl/stl-manipulator.d.ts +127 -0
- package/dist/stl/stl-manipulator.js +870 -0
- package/dist/test/stl-manipulator-test.d.ts +2 -0
- package/dist/test/stl-manipulator-test.js +91 -0
- package/package.json +8 -5
- package/src/index.ts +585 -0
- package/src/stl/stl-manipulator.ts +1119 -0
- package/src/test/stl-manipulator-test.js +114 -0
- package/src/test/stl-manipulator-test.ts +124 -0
- package/src/test/tsconfig.json +13 -0
- package/test/sample_cube.stl +86 -0
- package/test/sample_cube_extended.stl +172 -0
- package/test/sample_cube_modified.stl +86 -0
- package/test/sample_cube_rotated.stl +86 -0
- package/test/sample_cube_scaled.stl +86 -0
- package/test/sample_cube_translated.stl +86 -0
- package/test/sample_cube_visualization.svg +52 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { STLManipulator } from '../stl/stl-manipulator.js';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
// Create a test directory
|
|
7
|
+
const TEST_DIR = path.join(process.cwd(), 'test');
|
|
8
|
+
if (!fs.existsSync(TEST_DIR)) {
|
|
9
|
+
fs.mkdirSync(TEST_DIR, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
// Path for a sample STL file
|
|
12
|
+
const sampleStlPath = path.join(TEST_DIR, 'sample_cube.stl');
|
|
13
|
+
// Create a simple cube STL for testing if it doesn't exist
|
|
14
|
+
async function createSampleCube() {
|
|
15
|
+
if (fs.existsSync(sampleStlPath)) {
|
|
16
|
+
console.log('Sample STL already exists, skipping creation');
|
|
17
|
+
return sampleStlPath;
|
|
18
|
+
}
|
|
19
|
+
console.log('Creating sample cube STL...');
|
|
20
|
+
// Create a simple cube geometry
|
|
21
|
+
const geometry = new THREE.BoxGeometry(10, 10, 10);
|
|
22
|
+
const material = new THREE.MeshStandardMaterial();
|
|
23
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
24
|
+
// Import STLExporter
|
|
25
|
+
const { STLExporter } = await import('three/examples/jsm/exporters/STLExporter.js');
|
|
26
|
+
const exporter = new STLExporter();
|
|
27
|
+
// Export as STL
|
|
28
|
+
const stlString = exporter.parse(mesh);
|
|
29
|
+
// Write to file
|
|
30
|
+
fs.writeFileSync(sampleStlPath, stlString);
|
|
31
|
+
console.log(`Sample cube saved to ${sampleStlPath}`);
|
|
32
|
+
return sampleStlPath;
|
|
33
|
+
}
|
|
34
|
+
// Test the STL manipulator
|
|
35
|
+
async function testSTLManipulator() {
|
|
36
|
+
try {
|
|
37
|
+
// Create a sample STL for testing
|
|
38
|
+
const stlPath = await createSampleCube();
|
|
39
|
+
// Create an instance of the STL manipulator with the test directory
|
|
40
|
+
const manipulator = new STLManipulator(TEST_DIR);
|
|
41
|
+
// Listen for events from the manipulator
|
|
42
|
+
manipulator.on('operationComplete', (data) => {
|
|
43
|
+
console.log('Operation complete:', data);
|
|
44
|
+
});
|
|
45
|
+
manipulator.on('operationError', (data) => {
|
|
46
|
+
console.error('Operation error:', data);
|
|
47
|
+
});
|
|
48
|
+
// Test progress callback
|
|
49
|
+
const progressCallback = (progress, message) => {
|
|
50
|
+
console.log(`Progress: ${progress}% - ${message || ''}`);
|
|
51
|
+
};
|
|
52
|
+
// Test 1: Get information about the STL file
|
|
53
|
+
console.log('\n=== Test 1: Get STL Info ===');
|
|
54
|
+
const stlInfo = await manipulator.getSTLInfo(stlPath);
|
|
55
|
+
console.log('STL Info:', stlInfo);
|
|
56
|
+
// Test 2: Scale the STL file
|
|
57
|
+
console.log('\n=== Test 2: Scale STL ===');
|
|
58
|
+
const scaledStlPath = await manipulator.scaleSTL(stlPath, 2.0, progressCallback);
|
|
59
|
+
console.log(`Scaled STL saved to: ${scaledStlPath}`);
|
|
60
|
+
// Test 3: Rotate the STL file
|
|
61
|
+
console.log('\n=== Test 3: Rotate STL ===');
|
|
62
|
+
const rotatedStlPath = await manipulator.rotateSTL(stlPath, [45, 0, 0], progressCallback);
|
|
63
|
+
console.log(`Rotated STL saved to: ${rotatedStlPath}`);
|
|
64
|
+
// Test 4: Translate the STL file
|
|
65
|
+
console.log('\n=== Test 4: Translate STL ===');
|
|
66
|
+
const translatedStlPath = await manipulator.translateSTL(stlPath, [5, 10, 0], progressCallback);
|
|
67
|
+
console.log(`Translated STL saved to: ${translatedStlPath}`);
|
|
68
|
+
// Test 5: Extend the base of the STL file
|
|
69
|
+
console.log('\n=== Test 5: Extend Base ===');
|
|
70
|
+
const extendedStlPath = await manipulator.extendBase(stlPath, 0.5, progressCallback);
|
|
71
|
+
console.log(`Extended STL saved to: ${extendedStlPath}`);
|
|
72
|
+
// Test 6: Modify a section of the STL file
|
|
73
|
+
console.log('\n=== Test 6: Modify Section (Top) ===');
|
|
74
|
+
const modifiedStlPath = await manipulator.modifySection(stlPath, 'top', {
|
|
75
|
+
type: 'scale',
|
|
76
|
+
value: [1.5, 1.5, 1.5]
|
|
77
|
+
}, progressCallback);
|
|
78
|
+
console.log(`Modified STL saved to: ${modifiedStlPath}`);
|
|
79
|
+
// Test 7: Generate visualization of the STL file
|
|
80
|
+
console.log('\n=== Test 7: Generate Visualization ===');
|
|
81
|
+
const visualizationPath = await manipulator.generateVisualization(stlPath, 400, 400, progressCallback);
|
|
82
|
+
console.log(`Visualization saved to: ${visualizationPath}`);
|
|
83
|
+
console.log('\nAll tests completed successfully!');
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('An error occurred during testing:', error);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Run the tests
|
|
91
|
+
testSTLManipulator().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-3d-printer-server",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "MCP server for connecting Claude with 3D printer management systems",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "node
|
|
9
|
-
"dev": "nodemon src/index.
|
|
10
|
-
"
|
|
8
|
+
"start": "node dist/index.js",
|
|
9
|
+
"dev": "nodemon src/index.ts --exec \"npm run build && npm start\"",
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "npm run build && node dist/test/stl-manipulator-test.js"
|
|
11
12
|
},
|
|
12
13
|
"bin": {
|
|
13
14
|
"mcp-3d-printer-server": "./src/index.js"
|
|
@@ -31,10 +32,12 @@
|
|
|
31
32
|
"axios": "^1.6.2",
|
|
32
33
|
"bambu-js": "^2.2.2",
|
|
33
34
|
"dotenv": "^16.3.1",
|
|
34
|
-
"form-data": "^4.0.0"
|
|
35
|
+
"form-data": "^4.0.0",
|
|
36
|
+
"three": "^0.173.0"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@types/node": "^18.0.0",
|
|
40
|
+
"@types/three": "^0.173.0",
|
|
38
41
|
"nodemon": "^2.0.22"
|
|
39
42
|
}
|
|
40
43
|
}
|