bambu-studio-mcp 0.0.0-stage → 0.0.0

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +6 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/cli.d.ts +15 -0
  7. package/dist/cli.js +132 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/confirm.d.ts +7 -0
  10. package/dist/confirm.js +24 -0
  11. package/dist/confirm.js.map +1 -0
  12. package/dist/errors.d.ts +14 -0
  13. package/dist/errors.js +38 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.js +11 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/mcp.d.ts +10 -0
  19. package/dist/mcp.js +98 -0
  20. package/dist/mcp.js.map +1 -0
  21. package/dist/osa.d.ts +15 -0
  22. package/dist/osa.js +40 -0
  23. package/dist/osa.js.map +1 -0
  24. package/dist/parse.d.ts +15 -0
  25. package/dist/parse.js +241 -0
  26. package/dist/parse.js.map +1 -0
  27. package/dist/runner.d.ts +31 -0
  28. package/dist/runner.js +50 -0
  29. package/dist/runner.js.map +1 -0
  30. package/dist/screen.d.ts +26 -0
  31. package/dist/screen.js +61 -0
  32. package/dist/screen.js.map +1 -0
  33. package/dist/studio.d.ts +131 -0
  34. package/dist/studio.js +329 -0
  35. package/dist/studio.js.map +1 -0
  36. package/dist/types.d.ts +70 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/version.d.ts +2 -0
  40. package/dist/version.js +5 -0
  41. package/dist/version.js.map +1 -0
  42. package/jxa/click.js +21 -0
  43. package/jxa/close-window.js +9 -0
  44. package/jxa/colour.js +27 -0
  45. package/jxa/instances.js +9 -0
  46. package/jxa/keystroke.js +14 -0
  47. package/jxa/ocr.js +25 -0
  48. package/jxa/permissions.js +11 -0
  49. package/jxa/prelude.js +114 -0
  50. package/jxa/wait-window.js +15 -0
  51. package/package.json +69 -4
package/jxa/prelude.js ADDED
@@ -0,0 +1,114 @@
1
+ // Shared by every script in jxa/: src/osa.ts prepends this file to the script it runs.
2
+ // This is JavaScript for Automation, run by `osascript -l JavaScript`, not Node. Each script ends in
3
+ // a `run(argv)` that returns one JSON string. Errors are thrown as "BSM_<CODE>: message"; src/errors.ts
4
+ // turns them into BsmError.
5
+ ObjC.import("CoreGraphics");
6
+ ObjC.import("AppKit");
7
+ ObjC.import("Vision");
8
+ ObjC.bindFunction("CGPreflightScreenCaptureAccess", ["bool", []]);
9
+
10
+ let SE = Application("System Events");
11
+
12
+ // The pids of every Bambu Studio process. Read as one property of the whole collection: a list of
13
+ // the processes themselves would come back as references by name, and with several instances open
14
+ // (one per project, all named BambuStudio) every reference resolves to the first.
15
+ function studioPids() {
16
+ return SE.processes.whose({ name: "BambuStudio" }).unixId();
17
+ }
18
+
19
+ // One process by its pid, as a reference that stays on that pid.
20
+ function studioProcess(pid) {
21
+ let proc = SE.processes.whose({ unixId: pid })[0];
22
+ let ok = false;
23
+ try {
24
+ ok = proc.exists() && proc.name() === "BambuStudio";
25
+ } catch (e) {}
26
+ if (!ok) throw new Error(`BSM_NO_PROCESS: Bambu Studio process ${pid} is not running`);
27
+ return proc;
28
+ }
29
+
30
+ function windowInfo(w) {
31
+ let info = { name: "", x: 0, y: 0, w: 0, h: 0 };
32
+ try {
33
+ info.name = w.name() || "";
34
+ } catch (e) {}
35
+ try {
36
+ let p = w.position();
37
+ let s = w.size();
38
+ info.x = p[0];
39
+ info.y = p[1];
40
+ info.w = s[0];
41
+ info.h = s[1];
42
+ } catch (e) {}
43
+ return info;
44
+ }
45
+
46
+ // Windows are read as properties of the whole collection (proc.windows.name()) and reached by index
47
+ // (proc.windows[i]): a list from proc.windows() holds references by name, which land in whichever
48
+ // Bambu Studio instance comes first.
49
+ function windowList(proc) {
50
+ let names = [];
51
+ let pos = [];
52
+ let size = [];
53
+ try {
54
+ names = proc.windows.name();
55
+ pos = proc.windows.position();
56
+ size = proc.windows.size();
57
+ } catch (e) {}
58
+ return names.map((n, i) => {
59
+ let p = pos[i] || [0, 0];
60
+ let s = size[i] || [0, 0];
61
+ return { name: n || "", x: p[0], y: p[1], w: s[0], h: s[1] };
62
+ });
63
+ }
64
+
65
+ function findWindow(proc, name) {
66
+ let names = [];
67
+ try {
68
+ names = proc.windows.name();
69
+ } catch (e) {}
70
+ let i = names.indexOf(name);
71
+ return i < 0 ? null : proc.windows[i];
72
+ }
73
+
74
+ // Keystrokes go to whatever is frontmost, so nothing is typed until this process is.
75
+ function bringToFront(proc) {
76
+ proc.frontmost = true;
77
+ for (let i = 0; i < 30; i++) {
78
+ if (proc.frontmost()) return;
79
+ delay(0.1);
80
+ }
81
+ throw new Error("BSM_FOCUS: could not bring Bambu Studio to the front");
82
+ }
83
+
84
+ function expectOnly(proc, name) {
85
+ let ws = windowList(proc);
86
+ if (ws.length !== 1 || ws[0].name !== name) {
87
+ let names = ws.map((w) => w.name);
88
+ throw new Error(`BSM_WINDOWS: expected only the window '${name}', found ${JSON.stringify(names)}`);
89
+ }
90
+ return ws[0];
91
+ }
92
+
93
+ // A real mouse click, through Quartz: Bambu Studio draws its own controls, which take no AXPress.
94
+ function postClick(x, y) {
95
+ let pt = $.CGPointMake(x, y);
96
+ $.CGEventPost(
97
+ $.kCGHIDEventTap,
98
+ $.CGEventCreateMouseEvent(null, $.kCGEventMouseMoved, pt, $.kCGMouseButtonLeft),
99
+ );
100
+ delay(0.1);
101
+ $.CGEventPost(
102
+ $.kCGHIDEventTap,
103
+ $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseDown, pt, $.kCGMouseButtonLeft),
104
+ );
105
+ delay(0.08);
106
+ $.CGEventPost(
107
+ $.kCGHIDEventTap,
108
+ $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseUp, pt, $.kCGMouseButtonLeft),
109
+ );
110
+ }
111
+
112
+ function emit(value) {
113
+ return JSON.stringify(value);
114
+ }
@@ -0,0 +1,15 @@
1
+ // argv: pid, window name, "appear" | "vanish", timeout in seconds.
2
+ // Waits for a window to open or close. Read-only.
3
+ function run(argv) {
4
+ let proc = studioProcess(parseInt(argv[0], 10));
5
+ let name = argv[1];
6
+ let appear = argv[2] === "appear";
7
+ let tries = Math.max(1, Math.round(parseFloat(argv[3]) * 4));
8
+ for (let i = 0; i < tries; i++) {
9
+ let w = findWindow(proc, name);
10
+ if (appear && w) return emit({ done: true, window: windowInfo(w) });
11
+ if (!appear && !w) return emit({ done: true, window: null });
12
+ delay(0.25);
13
+ }
14
+ return emit({ done: false, windows: windowList(proc) });
15
+ }
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "bambu-studio-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "Drive Bambu Studio on macOS from a CLI or an MCP client: open, slice, preview and send a plate, and read the printer's status. Unofficial.",
5
+ "keywords": [
6
+ "bambu",
7
+ "bambu-studio",
8
+ "3d-printing",
9
+ "mcp",
10
+ "model-context-protocol",
11
+ "macos",
12
+ "automation"
13
+ ],
14
+ "homepage": "https://github.com/alexnodeland/bambu-studio-mcp#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/alexnodeland/bambu-studio-mcp/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/alexnodeland/bambu-studio-mcp.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Alex Nodeland",
24
+ "type": "module",
25
+ "packageManager": "bun@1.4.3",
26
+ "os": [
27
+ "darwin"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20"
31
+ },
32
+ "bin": {
33
+ "bambu-studio-mcp": "dist/bin.js"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "jxa",
44
+ "README.md",
45
+ "LICENSE"
46
+ ],
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit",
50
+ "lint": "biome check .",
51
+ "fmt": "biome check --write .",
52
+ "test": "vitest run",
53
+ "cov": "vitest run --coverage",
54
+ "knip": "knip",
55
+ "publint": "publint --strict",
56
+ "prepack": "tsc -p tsconfig.build.json"
57
+ },
58
+ "dependencies": {
59
+ "@modelcontextprotocol/sdk": "1.32.2",
60
+ "zod": "4.6.7"
61
+ },
62
+ "devDependencies": {
63
+ "@biomejs/biome": "2.6.9",
64
+ "@types/node": "24.19.4",
65
+ "@vitest/coverage-v8": "5.1.2",
66
+ "knip": "6.49.0",
67
+ "publint": "0.3.25",
68
+ "typescript": "7.0.2",
69
+ "vitest": "5.1.2"
70
+ }
71
+ }