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