@casys/mcp-prusaslicer 0.0.0-stage → 0.6.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Casys AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,353 @@
1
- # Temporary Holding Version
1
+ # @casys/mcp-prusaslicer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Run the real PrusaSlicer CLI behind MCP and return the print-time and material
4
+ statistics written into its generated G-code.
5
+
6
+ The server exposes `prusaslicer_estimate_fff`. The caller owns the STL and the
7
+ PrusaSlicer INI profile. The server snapshots and hashes both inputs, runs PrusaSlicer
8
+ headlessly, parses its G-code comment block, and removes the temporary G-code after the
9
+ call.
10
+
11
+ The geometry contract is deliberately STL-only: an accepted path must end in `.stl` and
12
+ pass a bounded ASCII-or-binary STL identity check before the server snapshots it or
13
+ starts PrusaSlicer.
14
+
15
+ This is a slicing estimate, not printer telemetry or a price quote. It complements
16
+ [`mcp-dfm`](https://github.com/superWorldSavior/mcp-dfm), which measures STEP geometry,
17
+ and [`mcp-calculix`](https://github.com/superWorldSavior/mcp-calculix), which performs
18
+ FEA.
19
+
20
+ ## Widgets
21
+
22
+ Results are shown as small, individual MCP App widgets, one reading each, never a
23
+ dashboard. Each widget is its own `ui://mcp-prusaslicer/<widget>` resource and adapts to
24
+ the width its host grants (a Compose board snaps its resize handle between
25
+ `supportedWidths`; a standalone host gets the widest).
26
+
27
+ | Widget (`ui://mcp-prusaslicer/…`) | Kind | Shows | `supportedWidths` |
28
+ | --------------------------------- | ----- | -------------------------------------------------------------- | ----------------- |
29
+ | `print-estimate` | stat | Print time with 1 to 3 filament numbers (mass, length, volume) | 280, 380, 520 |
30
+ | `slicing-profile` | table | Effective slicing parameters read back from the G-code | 320, 440, 640 |
31
+
32
+ Smallest width: the essential (print time and one number; 4 parameters). Middle: the
33
+ usual reading (8 parameters, units, override markers). Largest: the full detail of that
34
+ one thing (silent-mode time, overrides, not-checked list; all 14 parameters with their
35
+ PrusaSlicer key) with a provenance footer (engine, G-code, STL, profile and config
36
+ SHA-256). `prusaslicer_estimate_fff` and `run_snippet` advertise `print-estimate` by
37
+ default; a board selects the other widget for the same result by resource URI. Mass is
38
+ shown only when the slicer reported it. `SLICER_WIDGETS` (exported from `mod.ts`) lists
39
+ URIs, kinds and `supportedWidths` for a board to read:
40
+
41
+ ```ts
42
+ import { SLICER_WIDGETS } from "jsr:@casys/mcp-prusaslicer";
43
+ // { resourceUri: widget.uri, supportedWidths: widget.supportedWidths }
44
+ ```
45
+
46
+ ## Current release 0.4.0
47
+
48
+ The published 0.4.0 image bundles PrusaSlicer 2.9.2 and runs without a display. It
49
+ defaults to stateless HTTP on `/mcp`, port 3022, protocol `2026-07-28`; pass `stdio` to
50
+ use native MCP stdio instead. Package metadata and server runtime identity are both
51
+ `0.4.0`.
52
+
53
+ ```bash
54
+ docker run --rm \
55
+ -p 127.0.0.1:3022:3022 \
56
+ -v "$PWD/tests/fixtures:/data:ro" \
57
+ ghcr.io/casys-ai/mcp-prusaslicer@sha256:e63093777eff5f766e51acf1afe7cdb3b0e20c133cff93ad0d3e3b9b979e1ab3 http
58
+ ```
59
+
60
+ Point a Streamable HTTP MCP client at `http://127.0.0.1:3022/mcp`.
61
+
62
+ ## HTTP tool call
63
+
64
+ With the source fixture mount above, this complete call slices the committed 20 mm cube
65
+ with the committed test profile. `Mcp-Name` must mirror `params.name`:
66
+
67
+ ```bash
68
+ curl -sS -X POST http://127.0.0.1:3022/mcp \
69
+ -H 'Content-Type: application/json' \
70
+ -H 'Accept: application/json, text/event-stream' \
71
+ -H 'MCP-Protocol-Version: 2026-07-28' \
72
+ -H 'Mcp-Method: tools/call' \
73
+ -H 'Mcp-Name: prusaslicer_estimate_fff' \
74
+ -d '{
75
+ "jsonrpc": "2.0",
76
+ "id": 1,
77
+ "method": "tools/call",
78
+ "params": {
79
+ "name": "prusaslicer_estimate_fff",
80
+ "arguments": {
81
+ "stl_path": "/data/cube_20mm.stl",
82
+ "profile_ini_path": "/data/pla_0.4_0.2.ini",
83
+ "stl_sha256": "f69866e117ef51b57020e628e438723b89fb7a9daa13db238f781b0256a1621f",
84
+ "profile_sha256": "28172b6a4614655eea634cf6448090695cf4b135b0dd4d906c90eec2beebd841"
85
+ },
86
+ "_meta": {
87
+ "io.modelcontextprotocol/protocolVersion": "2026-07-28",
88
+ "io.modelcontextprotocol/clientCapabilities": {}
89
+ }
90
+ }
91
+ }'
92
+ ```
93
+
94
+ The reference HTTP call returns these values in `structuredContent`:
95
+
96
+ ```json
97
+ {
98
+ "print_time_s": 1190,
99
+ "print_time_normal_mode": "19m 50s",
100
+ "print_time_silent_mode": "20m 40s",
101
+ "filament_length_mm": 1487.15,
102
+ "filament_volume_mm3": 3580,
103
+ "filament_mass_g": 4.44
104
+ }
105
+ ```
106
+
107
+ It also returns `gcode_sha256`, `engine_name`, `engine_version`,
108
+ `effective_config_sha256`, the bounded and attested `effective_config_summary`,
109
+ `overrides_applied`, both input attestations, and `not_checked`. The text `content` is
110
+ only a short model-facing summary; use `structuredContent` for automation.
111
+
112
+ The examples above use the published multi-architecture 0.4.0 image
113
+ `ghcr.io/casys-ai/mcp-prusaslicer@sha256:e63093777eff5f766e51acf1afe7cdb3b0e20c133cff93ad0d3e3b9b979e1ab3`.
114
+ `ghcr.io/casys-ai/mcp-prusaslicer:latest` is a mutable convenience tag, not the
115
+ authority for a specific version or capability.
116
+
117
+ The images are published for `linux/amd64` and `linux/arm64`. Pin the OCI digest when a
118
+ deployment must be reproducible.
119
+
120
+ ## Tool contract
121
+
122
+ ### Inputs
123
+
124
+ | Field | Type | Required | Description |
125
+ | ------------------------ | ------- | -------- | ------------------------------------------------------------------- |
126
+ | `stl_path` | string | yes | Absolute `.stl` path that passes bounded ASCII/binary STL admission |
127
+ | `profile_ini_path` | string | yes | Absolute path to the caller-owned PrusaSlicer INI |
128
+ | `stl_sha256` | string | no | Expected 64-character SHA-256 of the STL snapshot |
129
+ | `profile_sha256` | string | no | Expected 64-character SHA-256 of the profile snapshot |
130
+ | `layer_height_mm` | number | no | Positive override forwarded as `--layer-height N` |
131
+ | `infill_percent` | number | no | Integer 0–100 override forwarded as `--fill-density N%` |
132
+ | `filament_density_g_cm3` | number | no | Positive override forwarded as `--filament-density N` |
133
+ | `timeout_ms` | integer | no | Positive integer subprocess timeout in ms; default 120000 |
134
+
135
+ The effective slicing configuration is the supplied INI plus the three explicit
136
+ overrides above. The server injects no bundled production profile or hidden print
137
+ setting. It also does not validate whether an INI is complete; PrusaSlicer owns the
138
+ behavior of omitted keys. For repeatable work, export a complete profile, keep it under
139
+ change control, and supply `profile_sha256`.
140
+
141
+ The included `tests/fixtures/pla_0.4_0.2.ini` is deliberately a small test profile, not
142
+ a recommended production profile.
143
+
144
+ ### Effective configuration summary
145
+
146
+ Each successful slice includes `effective_config_summary`, a closed, raw-value
147
+ projection of selected keys in the exact `; prusaslicer_config = begin` … `end` block
148
+ that PrusaSlicer emitted. Its `config_sha256` is identical to `effective_config_sha256`,
149
+ so the projection is bound to the same attested source. The fixed keys are:
150
+
151
+ `printer_technology`, `nozzle_diameter`, `layer_height`, `first_layer_height`,
152
+ `fill_density`, `fill_pattern`, `perimeters`, `top_solid_layers`, `bottom_solid_layers`,
153
+ `support_material`, `support_material_auto`, `filament_diameter`, `filament_density`,
154
+ and `gcode_flavor`.
155
+
156
+ Values are returned exactly as emitted, including multi-extruder lists; `null` means
157
+ that the selected key was absent from that emitted block. The server does not parse
158
+ those raw values into a different unit or infer a PrusaSlicer default. A duplicated
159
+ selected key is rejected rather than silently choosing one value.
160
+
161
+ ### 3MF project inputs
162
+
163
+ This endpoint accepts an attested STL plus an attested INI, not a 3MF project path. A
164
+ `.3mf` value passed through `stl_path` is refused before any input snapshot or slicer
165
+ process. A file merely renamed to `.stl` is refused unless its bounded head/tail
166
+ identify an ASCII STL or its binary triangle-count layout is exact. ZIP local-file,
167
+ empty-archive, and spanned-archive signatures are refused before the binary-STL size
168
+ predicate, including deliberately colliding payload lengths.
169
+
170
+ The upstream
171
+ [PrusaSlicer CLI documentation](https://github.com/prusa3d/PrusaSlicer/wiki/Command-Line-Interface)
172
+ states that AMF/3MF input can load profiles embedded in the project, but that does not
173
+ by itself establish the precedence and provenance needed by this two-artifact contract.
174
+ A future 3MF contract must snapshot the project bytes, bind the emitted configuration
175
+ hash and summary to that snapshot, and qualify CLI profile/override precedence against a
176
+ pinned engine version.
177
+
178
+ ### Outputs
179
+
180
+ | Field | Always present | Semantics |
181
+ | -------------------------- | -------------- | -------------------------------------------------------------------------------------------- |
182
+ | `print_time_s` | yes | Parsed normal-mode PrusaSlicer estimate in seconds |
183
+ | `print_time_normal_mode` | yes | Raw normal-mode G-code string such as `19m 50s` |
184
+ | `print_time_silent_mode` | yes | Raw silent-mode string, or `null` when the line is absent |
185
+ | `filament_length_mm` | yes | Parsed `filament used [mm]` G-code statistic |
186
+ | `filament_volume_mm3` | yes | Parsed `filament used [cm3]`, converted to mm³ and rounded to two decimals |
187
+ | `filament_mass_g` | no | Positive parsed `filament used [g]`; absent rather than `null` when unavailable or zero |
188
+ | `gcode_sha256` | yes | SHA-256 of the generated G-code before its temporary directory is removed |
189
+ | `engine_name` | yes | Observed slicer name parsed from the G-code `; generated by` header |
190
+ | `engine_version` | yes | Observed slicer version parsed from the G-code `; generated by` header |
191
+ | `effective_config_sha256` | yes | SHA-256 of the exact emitted `prusaslicer_config` block, begin through end markers |
192
+ | `effective_config_summary` | yes | Closed raw-value projection from that same block; its `config_sha256` equals the field above |
193
+ | `overrides_applied` | yes | Caller-provided print overrides that were forwarded; `{}` when none were supplied |
194
+ | `stl_artifact` | yes | `{ sha256, bytes, source_path }` for the exact STL snapshot consumed |
195
+ | `profile_artifact` | yes | `{ sha256, bytes, source_path }` for the exact INI snapshot consumed |
196
+ | `not_checked` | yes | Explicit limits of the result |
197
+
198
+ The mass value is PrusaSlicer's G-code statistic. The server does not recompute mass as
199
+ volume × density. A `filament_density` entry in the profile or the
200
+ `filament_density_g_cm3` override normally causes PrusaSlicer to emit a positive mass;
201
+ if the emitted value is absent or zero, the MCP field is omitted. No density or mass is
202
+ invented.
203
+
204
+ `gcode_sha256` attests the transient output of that call, but it is not a
205
+ reproducibility guarantee or a download handle. PrusaSlicer embeds a build timestamp, so
206
+ identical STL and profile bytes sliced on different dates can produce different hashes.
207
+ The current tool returns statistics and the digest, not the G-code bytes or a persistent
208
+ G-code resource.
209
+
210
+ `engine_name` and `engine_version` are read from the G-code header, not queried from the
211
+ `prusa-slicer` binary on `PATH`. `effective_config_sha256` hashes the exact
212
+ `; prusaslicer_config = begin` … `end` block PrusaSlicer wrote; it is not a hash of the
213
+ input INI. `overrides_applied` contains only the caller-supplied `layer_height_mm`,
214
+ `infill_percent`, and `filament_density_g_cm3` values that were forwarded as CLI flags.
215
+ `effective_config_summary` is a fixed raw projection of this same emitted block, not a
216
+ copy of the input INI or an inferred configuration.
217
+
218
+ ## What the estimate does not establish
219
+
220
+ The `not_checked` array is part of every result. In particular:
221
+
222
+ - print time comes from PrusaSlicer's estimator, not an observed printer run; firmware,
223
+ acceleration, and machine behavior can change the actual duration;
224
+ - this repository provides no calibrated error band between estimated and observed time;
225
+ qualify the selected printer, firmware, and profile when accuracy matters;
226
+ - bed adhesion, warping, shrinkage, and dimensional tolerance are not evaluated;
227
+ - material statistics reflect the generated toolpath: if supports are disabled by the
228
+ profile, no support material is included;
229
+ - multi-material and multi-extruder profiles are not covered by the native test suite;
230
+ use a single-extruder profile unless you qualify another configuration;
231
+ - no filament price, machine rate, labor, or quote is computed.
232
+
233
+ ## Engine and reference evidence
234
+
235
+ The Dockerfile pins Debian's `prusa-slicer=2.9.2+dfsg-1`. The CLI runs headlessly with
236
+ this pattern:
237
+
238
+ ```text
239
+ prusa-slicer --load <profile.ini> [overrides...] \
240
+ --export-gcode --output <out.gcode> <in.stl>
241
+ ```
242
+
243
+ The 20 mm reference above was measured with PrusaSlicer 2.9.2 on aarch64 Debian trixie
244
+ using a 0.4 mm nozzle, 0.2 mm layer height, 20% infill, and PLA density 1.24 g/cm³. The
245
+ committed G-code fixture contains the real header and statistic block used by the
246
+ non-native parser tests.
247
+
248
+ For comparison, the committed 10 mm cube reference with the same profile is:
249
+
250
+ | Field | Value |
251
+ | ------------------------ | --------- |
252
+ | `filament_length_mm` | 426.64 |
253
+ | `filament_volume_mm3` | 1030 |
254
+ | `filament_mass_g` | 1.27 |
255
+ | `print_time_s` | 765 |
256
+ | `print_time_normal_mode` | `12m 45s` |
257
+
258
+ These fixture values demonstrate the parser and one qualified engine/profile
259
+ combination. They are not universal estimates for similarly sized parts.
260
+
261
+ ## Input attestation
262
+
263
+ Before invoking PrusaSlicer, the tool independently:
264
+
265
+ 1. Refuses non-`.stl` geometry paths and content that does not pass bounded ASCII/binary
266
+ STL admission.
267
+ 2. Copies the admitted STL and INI into private temporary directories.
268
+ 3. Revalidates the private STL copy, so a source-path change between preflight and copy
269
+ cannot substitute a ZIP/3MF payload.
270
+ 4. Hashes the private copies with SHA-256.
271
+ 5. Compares them with `stl_sha256` and `profile_sha256`, when supplied.
272
+ 6. Makes both snapshots read-only.
273
+ 7. Passes only those snapshots to PrusaSlicer and returns the digests, byte counts, and
274
+ original source paths.
275
+
276
+ The expectation fields are optional so exploratory calls remain possible;
277
+ provenance-sensitive workflows should require both.
278
+
279
+ ## Run from source or JSR over HTTP
280
+
281
+ An HTTP run requires `prusa-slicer` on `PATH`. From a checkout:
282
+
283
+ ```bash
284
+ deno task serve
285
+ deno task serve -- --port=3099 --hostname=0.0.0.0
286
+ ```
287
+
288
+ This checkout and the published JSR package provide stateless HTTP.
289
+
290
+ ```bash
291
+ deno run -A jsr:@casys/mcp-prusaslicer/server --port=3022
292
+ ```
293
+
294
+ ## Native stdio from a checkout or released artifact
295
+
296
+ The current source and the published 0.4.0 JSR/image use native stdio.
297
+
298
+ From a checkout:
299
+
300
+ ```bash
301
+ deno run -A server.ts --stdio
302
+ ```
303
+
304
+ Or from JSR 0.4.0:
305
+
306
+ ```bash
307
+ deno run -A jsr:@casys/mcp-prusaslicer@0.4.0/server --stdio
308
+ ```
309
+
310
+ Or use the published image with `stdio` as its argument:
311
+
312
+ ```bash
313
+ docker run --rm -i \
314
+ -v "$PWD/tests/fixtures:/data:ro" \
315
+ ghcr.io/casys-ai/mcp-prusaslicer@sha256:e63093777eff5f766e51acf1afe7cdb3b0e20c133cff93ad0d3e3b9b979e1ab3 stdio
316
+ ```
317
+
318
+ The source path and the published 0.4.0 artifacts use the MCP server's native transport
319
+ and accept legacy `2025-06-18` initialization from classic MCP clients.
320
+
321
+ ## Development
322
+
323
+ ```bash
324
+ deno task release:check
325
+ PRUSASLICER_RUN_NATIVE=1 deno task test
326
+ ```
327
+
328
+ `release:check` covers formatting, type checking, linting, non-native tests, and the
329
+ stdio wire tests. Native tests additionally require PrusaSlicer 2.9.2 on `PATH`.
330
+
331
+ Relevant implementation boundaries:
332
+
333
+ ```text
334
+ server.ts stateless HTTP and native stdio composition root
335
+ src/api/input-artifact.ts private snapshots and SHA-256 attestation
336
+ src/api/prusa-slicer.ts subprocess bridge and G-code statistic parser
337
+ src/tools/estimate.ts prusaslicer_estimate_fff contract
338
+ tests/fixtures/ qualified test STL, profile, and G-code stats
339
+ ```
340
+
341
+ The main-branch workflow publishes a new JSR version only when the version in
342
+ `deno.json` is not already present. A separate workflow publishes the multi-arch GHCR
343
+ image from `main` and creates a semantic image tag when a `v*` Git tag is pushed.
344
+
345
+ ## Security
346
+
347
+ This server invokes a native slicer on caller-supplied files. Keep HTTP bound to
348
+ loopback unless it is protected by an appropriate trusted boundary. See
349
+ [`SECURITY.md`](SECURITY.md) for private vulnerability reporting.
350
+
351
+ ## License
352
+
353
+ MIT