propermesh-mcp 0.1.0__tar.gz
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.
- propermesh_mcp-0.1.0/.gitignore +36 -0
- propermesh_mcp-0.1.0/LICENSE +21 -0
- propermesh_mcp-0.1.0/PKG-INFO +159 -0
- propermesh_mcp-0.1.0/README.md +139 -0
- propermesh_mcp-0.1.0/pyproject.toml +44 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/__init__.py +1 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/config.py +42 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/errors.py +23 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/layers.py +40 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/output.py +34 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/parts.py +93 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/report.py +187 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/server.py +196 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/session.py +107 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/static/viewer.html +607 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/summaries.py +446 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_config.py +32 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_errors.py +37 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_layers.py +57 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_output.py +49 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_parts.py +63 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_report.py +114 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_server_stdio.py +109 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_session.py +87 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_summaries.py +253 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_tools_integration.py +302 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_viewer_server.py +341 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/test_visualize.py +249 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/tools.py +364 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/viewer_server.py +403 -0
- propermesh_mcp-0.1.0/src/propermesh_mcp/visualize.py +208 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Thisll just be a directory where I throw scrap code in that i might want to reference at some
|
|
2
|
+
# point but isnt worth committing
|
|
3
|
+
scrap
|
|
4
|
+
|
|
5
|
+
personal_notes/*
|
|
6
|
+
|
|
7
|
+
__pycache__
|
|
8
|
+
|
|
9
|
+
# This can be a good place to store test mesh files that you dont want to commit to the repo
|
|
10
|
+
testdata/private/*
|
|
11
|
+
testdata/parts/auto-orient-tests/output/*
|
|
12
|
+
|
|
13
|
+
.env*
|
|
14
|
+
|
|
15
|
+
# The provider lock file is committed so every machine and CI use the same provider versions
|
|
16
|
+
*terraform.tfstate*
|
|
17
|
+
.terraform
|
|
18
|
+
|
|
19
|
+
# runner-* is my convention for scripts that would only be used on my local machine that set up an
|
|
20
|
+
# environment before calling out to another script that would normally be executed by a CICD runner
|
|
21
|
+
# or something
|
|
22
|
+
etc/**/runner-*
|
|
23
|
+
|
|
24
|
+
.propermesh*
|
|
25
|
+
|
|
26
|
+
tmp/*
|
|
27
|
+
|
|
28
|
+
# Committed, non-secret local test config
|
|
29
|
+
!.env.test
|
|
30
|
+
|
|
31
|
+
# Saved terraform plans contain secrets
|
|
32
|
+
infrastructure/tfplan
|
|
33
|
+
|
|
34
|
+
# Claude Code: per-machine settings and its own worktrees
|
|
35
|
+
.claude/settings.local.json
|
|
36
|
+
.claude/worktrees/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Propermesh
|
|
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.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: propermesh-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server that lets AI agents run Propermesh 3D-printing checks on local meshes
|
|
5
|
+
Project-URL: Homepage, https://propermesh.com
|
|
6
|
+
Project-URL: Documentation, https://pypi.org/project/propermesh-mcp/
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: 3d-printing,claude,cursor,mcp,mesh,printability,stl
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: anyio>=4
|
|
14
|
+
Requires-Dist: mcp<2,>=1.30
|
|
15
|
+
Requires-Dist: propermesh<0.2,>=0.1.0
|
|
16
|
+
Requires-Dist: pydantic>=2
|
|
17
|
+
Requires-Dist: requests>=2
|
|
18
|
+
Requires-Dist: typing-extensions>=4.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# propermesh-mcp
|
|
22
|
+
|
|
23
|
+
An [MCP](https://modelcontextprotocol.io) server that lets AI agents (Claude, Cursor, and other MCP
|
|
24
|
+
clients) run Propermesh's 3D-printing checks on local mesh files. It runs locally over stdio, wraps
|
|
25
|
+
the `propermesh` Python SDK, and returns compact JSON summaries with a link to the part in the
|
|
26
|
+
Propermesh analyzer.
|
|
27
|
+
|
|
28
|
+
## Setup
|
|
29
|
+
|
|
30
|
+
You need [uv](https://docs.astral.sh/uv/) (`uvx` runs the server from PyPI, no install step) and an
|
|
31
|
+
access key and secret from your [account page](https://propermesh.com/account).
|
|
32
|
+
|
|
33
|
+
### Claude Code
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
claude mcp add propermesh \
|
|
37
|
+
-e PROPERMESH_ACCESS_KEY=... -e PROPERMESH_SECRET_KEY=... \
|
|
38
|
+
-- uvx propermesh-mcp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then ask: "Can I print `~/models/bracket.stl`?"
|
|
42
|
+
|
|
43
|
+
### Claude Desktop
|
|
44
|
+
|
|
45
|
+
Add this to `claude_desktop_config.json` (Settings, Developer, Edit Config) and restart:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"mcpServers": {
|
|
50
|
+
"propermesh": {
|
|
51
|
+
"command": "uvx",
|
|
52
|
+
"args": ["propermesh-mcp"],
|
|
53
|
+
"env": {"PROPERMESH_ACCESS_KEY": "...", "PROPERMESH_SECRET_KEY": "..."}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Cursor
|
|
60
|
+
|
|
61
|
+
Add the same block to `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project).
|
|
62
|
+
|
|
63
|
+
### Other clients
|
|
64
|
+
|
|
65
|
+
Any MCP client that launches stdio servers works: the command is `uvx propermesh-mcp`, with the keys in
|
|
66
|
+
its environment.
|
|
67
|
+
|
|
68
|
+
## Run it from a checkout
|
|
69
|
+
|
|
70
|
+
To develop the server, run it from a checkout of the repository instead:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
PROPERMESH_ACCESS_KEY=... PROPERMESH_SECRET_KEY=... uvx --from ./mcp-server propermesh-mcp
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`uvx` builds the package and uses the SDK in `../sdk` through `[tool.uv.sources]`, so SDK changes
|
|
77
|
+
apply without publishing. In a client, replace `uvx propermesh-mcp` with
|
|
78
|
+
`uvx --from /abs/path/propermesh/mcp-server propermesh-mcp`.
|
|
79
|
+
|
|
80
|
+
## Environment
|
|
81
|
+
|
|
82
|
+
| Variable | |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `PROPERMESH_ACCESS_KEY` | Required. An API key's access key |
|
|
85
|
+
| `PROPERMESH_SECRET_KEY` | Required. The key's secret |
|
|
86
|
+
| `PROPERMESH_DOMAIN` | Optional, defaults to `https://propermesh.com`. Point it at a local API (`http://localhost:5005`) or a preview environment |
|
|
87
|
+
|
|
88
|
+
Without the keys the server still starts and lists its tools, and every tool call returns an error
|
|
89
|
+
naming the missing variables.
|
|
90
|
+
|
|
91
|
+
## Tools
|
|
92
|
+
|
|
93
|
+
Each tool takes exactly one of `path` (a local STL, OBJ, 3MF or STEP file; `~` is expanded) or
|
|
94
|
+
`part_id` (from an earlier result), plus `units` (`mm` or `inches`, used only when uploading). A file
|
|
95
|
+
uploads once per server session: calling another tool on the same unchanged file reuses its part.
|
|
96
|
+
|
|
97
|
+
- `analyze_geometry`: whether the mesh is watertight, manifold and consistently wound, its shells,
|
|
98
|
+
the non-zero defect counts, volume, surface area and bounding box, and `printable_as_is`.
|
|
99
|
+
- `check_wall_thickness` (`min_thickness_mm`, default 0.8): whether any wall is thinner than that,
|
|
100
|
+
the thin area and its percent of the surface, and the thinnest wall. Lengths and areas are in mm.
|
|
101
|
+
- `check_overhangs` (`critical_angle_deg`, default 45): whether the part needs supports. A face
|
|
102
|
+
overhangs when its slope from horizontal is below the angle (PrusaSlicer's convention). Returns the
|
|
103
|
+
overhang area and percent, face and cluster counts, and the flattest overhang.
|
|
104
|
+
- `printability_report` (`min_thickness_mm`, default 0.8; `critical_angle_deg`, default 45;
|
|
105
|
+
`oriented_output_path`): **the tool to call first.** Runs geometry, thickness, overhang and orientation
|
|
106
|
+
and returns one verdict (`ready`, `needs_attention` or `not_printable`), the `issues` behind it, and the
|
|
107
|
+
key numbers of each check. A check that fails shows as `{"error": ...}` in its section and a warning;
|
|
108
|
+
the rest still return. It writes the oriented STL like `find_print_orientation`, and takes a minute or two.
|
|
109
|
+
- `find_print_orientation` (`output_path`): the best print orientation as a 3x3 `rotation_matrix`, whether the part is
|
|
110
|
+
`already_optimal`, and `oriented_part_id` (the oriented mesh is a part: pass it as `part_id` to other
|
|
111
|
+
tools).
|
|
112
|
+
- `repair_mesh` (`output_path`): repairs holes and bad triangles, and reports whether the result is watertight,
|
|
113
|
+
manifold and consistently wound, plus `repaired_part_id`. A mesh that stays open is reported, not an error.
|
|
114
|
+
|
|
115
|
+
`find_print_orientation`, `repair_mesh` and `printability_report` can save the STL they download. Given a `path` and no output path, they
|
|
116
|
+
write `<name>-oriented.stl` / `<name>-repaired.stl` next to the input; given a `part_id` and no
|
|
117
|
+
output path, they write nothing. They never overwrite the input file.
|
|
118
|
+
|
|
119
|
+
`analyze_geometry`, `check_wall_thickness` and `check_overhangs` also return the analysis's `job_id`.
|
|
120
|
+
|
|
121
|
+
- `visualize_parts` (`items`, `title`, `open_browser`, default true): opens an interactive 3D view of 1 to
|
|
122
|
+
4 parts in the browser, side by side with a "Sync cameras" toggle. Each item takes `path` or `part_id`,
|
|
123
|
+
and optionally `layer` (`overhang`, `thickness` or `defects`, colored with a live threshold slider or
|
|
124
|
+
defect toggles), `job_id`, `label` and `stats` (short callouts). A layer comes from the analysis this
|
|
125
|
+
session ran last on the part, else the part's latest. The view is served from `127.0.0.1` while the
|
|
126
|
+
server runs, and Three.js loads from cdn.jsdelivr.net. Returns the `url`, whether a browser `opened`
|
|
127
|
+
it, and the parts' `analyzer_urls`.
|
|
128
|
+
|
|
129
|
+
Instead of `items`, pass `groups` (titled sections of thumbnail cards, e.g. "No overhangs" and "Has
|
|
130
|
+
overhangs") or `rows` (one row of 1 to 4 thumbnails per comparison, e.g. before/after orienting each
|
|
131
|
+
part, with row-level `stats`) to lay out many parts. Clicking a card opens it in 3D; ticking 2 to 4
|
|
132
|
+
cards in groups, or a row's "Compare in 3D", opens them side by side. A layer the session didn't run
|
|
133
|
+
is looked up when the part is opened.
|
|
134
|
+
|
|
135
|
+
## Example
|
|
136
|
+
|
|
137
|
+
`printability_report` on a cube with a thin ridge:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"part_id": "8b1f0c52-4d0e-4a53-9e0e-0d2a1b3c4d5e",
|
|
142
|
+
"analyzer_url": "https://propermesh.com/analysis/8b1f0c52-4d0e-4a53-9e0e-0d2a1b3c4d5e",
|
|
143
|
+
"verdict": "needs_attention",
|
|
144
|
+
"issues": [
|
|
145
|
+
{"severity": "warning", "check": "thickness",
|
|
146
|
+
"message": "Walls thinner than 0.8 mm: thinnest_wall is 0.4 mm, 4.5% of the surface"}
|
|
147
|
+
],
|
|
148
|
+
"geometry": {"units": "mm", "volume": 1234.567, "surface_area": 987.654,
|
|
149
|
+
"bounding_box": {"x": 10.0, "y": 12.5, "z": 8.25}, "is_watertight": true,
|
|
150
|
+
"is_manifold": true, "is_winding_consistent": true, "num_shells": 1,
|
|
151
|
+
"defects": {}, "printable_as_is": true},
|
|
152
|
+
"thickness": {"min_thickness_mm": 0.8, "has_thin_walls": true, "thin_surface_area": 12.3,
|
|
153
|
+
"thin_area_percent": 4.5, "thinnest_wall": 0.4},
|
|
154
|
+
"overhang": {"critical_angle_deg": 45, "needs_supports": false, "overhang_surface_area": 0,
|
|
155
|
+
"overhang_area_percent": 0, "worst_overhang_angle_deg": null},
|
|
156
|
+
"orientation": {"rotation_matrix": [[1, 0, 0], [0, 1, 0], [0, 0, 1]], "already_optimal": true,
|
|
157
|
+
"oriented_part_id": "c2d3...", "oriented_stl_path": "/models/ridge-oriented.stl"}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# propermesh-mcp
|
|
2
|
+
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server that lets AI agents (Claude, Cursor, and other MCP
|
|
4
|
+
clients) run Propermesh's 3D-printing checks on local mesh files. It runs locally over stdio, wraps
|
|
5
|
+
the `propermesh` Python SDK, and returns compact JSON summaries with a link to the part in the
|
|
6
|
+
Propermesh analyzer.
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
You need [uv](https://docs.astral.sh/uv/) (`uvx` runs the server from PyPI, no install step) and an
|
|
11
|
+
access key and secret from your [account page](https://propermesh.com/account).
|
|
12
|
+
|
|
13
|
+
### Claude Code
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
claude mcp add propermesh \
|
|
17
|
+
-e PROPERMESH_ACCESS_KEY=... -e PROPERMESH_SECRET_KEY=... \
|
|
18
|
+
-- uvx propermesh-mcp
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then ask: "Can I print `~/models/bracket.stl`?"
|
|
22
|
+
|
|
23
|
+
### Claude Desktop
|
|
24
|
+
|
|
25
|
+
Add this to `claude_desktop_config.json` (Settings, Developer, Edit Config) and restart:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"mcpServers": {
|
|
30
|
+
"propermesh": {
|
|
31
|
+
"command": "uvx",
|
|
32
|
+
"args": ["propermesh-mcp"],
|
|
33
|
+
"env": {"PROPERMESH_ACCESS_KEY": "...", "PROPERMESH_SECRET_KEY": "..."}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Cursor
|
|
40
|
+
|
|
41
|
+
Add the same block to `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project).
|
|
42
|
+
|
|
43
|
+
### Other clients
|
|
44
|
+
|
|
45
|
+
Any MCP client that launches stdio servers works: the command is `uvx propermesh-mcp`, with the keys in
|
|
46
|
+
its environment.
|
|
47
|
+
|
|
48
|
+
## Run it from a checkout
|
|
49
|
+
|
|
50
|
+
To develop the server, run it from a checkout of the repository instead:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
PROPERMESH_ACCESS_KEY=... PROPERMESH_SECRET_KEY=... uvx --from ./mcp-server propermesh-mcp
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`uvx` builds the package and uses the SDK in `../sdk` through `[tool.uv.sources]`, so SDK changes
|
|
57
|
+
apply without publishing. In a client, replace `uvx propermesh-mcp` with
|
|
58
|
+
`uvx --from /abs/path/propermesh/mcp-server propermesh-mcp`.
|
|
59
|
+
|
|
60
|
+
## Environment
|
|
61
|
+
|
|
62
|
+
| Variable | |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `PROPERMESH_ACCESS_KEY` | Required. An API key's access key |
|
|
65
|
+
| `PROPERMESH_SECRET_KEY` | Required. The key's secret |
|
|
66
|
+
| `PROPERMESH_DOMAIN` | Optional, defaults to `https://propermesh.com`. Point it at a local API (`http://localhost:5005`) or a preview environment |
|
|
67
|
+
|
|
68
|
+
Without the keys the server still starts and lists its tools, and every tool call returns an error
|
|
69
|
+
naming the missing variables.
|
|
70
|
+
|
|
71
|
+
## Tools
|
|
72
|
+
|
|
73
|
+
Each tool takes exactly one of `path` (a local STL, OBJ, 3MF or STEP file; `~` is expanded) or
|
|
74
|
+
`part_id` (from an earlier result), plus `units` (`mm` or `inches`, used only when uploading). A file
|
|
75
|
+
uploads once per server session: calling another tool on the same unchanged file reuses its part.
|
|
76
|
+
|
|
77
|
+
- `analyze_geometry`: whether the mesh is watertight, manifold and consistently wound, its shells,
|
|
78
|
+
the non-zero defect counts, volume, surface area and bounding box, and `printable_as_is`.
|
|
79
|
+
- `check_wall_thickness` (`min_thickness_mm`, default 0.8): whether any wall is thinner than that,
|
|
80
|
+
the thin area and its percent of the surface, and the thinnest wall. Lengths and areas are in mm.
|
|
81
|
+
- `check_overhangs` (`critical_angle_deg`, default 45): whether the part needs supports. A face
|
|
82
|
+
overhangs when its slope from horizontal is below the angle (PrusaSlicer's convention). Returns the
|
|
83
|
+
overhang area and percent, face and cluster counts, and the flattest overhang.
|
|
84
|
+
- `printability_report` (`min_thickness_mm`, default 0.8; `critical_angle_deg`, default 45;
|
|
85
|
+
`oriented_output_path`): **the tool to call first.** Runs geometry, thickness, overhang and orientation
|
|
86
|
+
and returns one verdict (`ready`, `needs_attention` or `not_printable`), the `issues` behind it, and the
|
|
87
|
+
key numbers of each check. A check that fails shows as `{"error": ...}` in its section and a warning;
|
|
88
|
+
the rest still return. It writes the oriented STL like `find_print_orientation`, and takes a minute or two.
|
|
89
|
+
- `find_print_orientation` (`output_path`): the best print orientation as a 3x3 `rotation_matrix`, whether the part is
|
|
90
|
+
`already_optimal`, and `oriented_part_id` (the oriented mesh is a part: pass it as `part_id` to other
|
|
91
|
+
tools).
|
|
92
|
+
- `repair_mesh` (`output_path`): repairs holes and bad triangles, and reports whether the result is watertight,
|
|
93
|
+
manifold and consistently wound, plus `repaired_part_id`. A mesh that stays open is reported, not an error.
|
|
94
|
+
|
|
95
|
+
`find_print_orientation`, `repair_mesh` and `printability_report` can save the STL they download. Given a `path` and no output path, they
|
|
96
|
+
write `<name>-oriented.stl` / `<name>-repaired.stl` next to the input; given a `part_id` and no
|
|
97
|
+
output path, they write nothing. They never overwrite the input file.
|
|
98
|
+
|
|
99
|
+
`analyze_geometry`, `check_wall_thickness` and `check_overhangs` also return the analysis's `job_id`.
|
|
100
|
+
|
|
101
|
+
- `visualize_parts` (`items`, `title`, `open_browser`, default true): opens an interactive 3D view of 1 to
|
|
102
|
+
4 parts in the browser, side by side with a "Sync cameras" toggle. Each item takes `path` or `part_id`,
|
|
103
|
+
and optionally `layer` (`overhang`, `thickness` or `defects`, colored with a live threshold slider or
|
|
104
|
+
defect toggles), `job_id`, `label` and `stats` (short callouts). A layer comes from the analysis this
|
|
105
|
+
session ran last on the part, else the part's latest. The view is served from `127.0.0.1` while the
|
|
106
|
+
server runs, and Three.js loads from cdn.jsdelivr.net. Returns the `url`, whether a browser `opened`
|
|
107
|
+
it, and the parts' `analyzer_urls`.
|
|
108
|
+
|
|
109
|
+
Instead of `items`, pass `groups` (titled sections of thumbnail cards, e.g. "No overhangs" and "Has
|
|
110
|
+
overhangs") or `rows` (one row of 1 to 4 thumbnails per comparison, e.g. before/after orienting each
|
|
111
|
+
part, with row-level `stats`) to lay out many parts. Clicking a card opens it in 3D; ticking 2 to 4
|
|
112
|
+
cards in groups, or a row's "Compare in 3D", opens them side by side. A layer the session didn't run
|
|
113
|
+
is looked up when the part is opened.
|
|
114
|
+
|
|
115
|
+
## Example
|
|
116
|
+
|
|
117
|
+
`printability_report` on a cube with a thin ridge:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"part_id": "8b1f0c52-4d0e-4a53-9e0e-0d2a1b3c4d5e",
|
|
122
|
+
"analyzer_url": "https://propermesh.com/analysis/8b1f0c52-4d0e-4a53-9e0e-0d2a1b3c4d5e",
|
|
123
|
+
"verdict": "needs_attention",
|
|
124
|
+
"issues": [
|
|
125
|
+
{"severity": "warning", "check": "thickness",
|
|
126
|
+
"message": "Walls thinner than 0.8 mm: thinnest_wall is 0.4 mm, 4.5% of the surface"}
|
|
127
|
+
],
|
|
128
|
+
"geometry": {"units": "mm", "volume": 1234.567, "surface_area": 987.654,
|
|
129
|
+
"bounding_box": {"x": 10.0, "y": 12.5, "z": 8.25}, "is_watertight": true,
|
|
130
|
+
"is_manifold": true, "is_winding_consistent": true, "num_shells": 1,
|
|
131
|
+
"defects": {}, "printable_as_is": true},
|
|
132
|
+
"thickness": {"min_thickness_mm": 0.8, "has_thin_walls": true, "thin_surface_area": 12.3,
|
|
133
|
+
"thin_area_percent": 4.5, "thinnest_wall": 0.4},
|
|
134
|
+
"overhang": {"critical_angle_deg": 45, "needs_supports": false, "overhang_surface_area": 0,
|
|
135
|
+
"overhang_area_percent": 0, "worst_overhang_angle_deg": null},
|
|
136
|
+
"orientation": {"rotation_matrix": [[1, 0, 0], [0, 1, 0], [0, 0, 1]], "already_optimal": true,
|
|
137
|
+
"oriented_part_id": "c2d3...", "oriented_stl_path": "/models/ridge-oriented.stl"}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "propermesh-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "MCP server that lets AI agents run Propermesh 3D-printing checks on local meshes"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
# Everything the server imports directly. The SDK pin follows its minor version: bump it when the server
|
|
10
|
+
# needs a newer SDK, and publish the SDK first
|
|
11
|
+
dependencies = [
|
|
12
|
+
"propermesh>=0.1.0,<0.2",
|
|
13
|
+
"mcp>=1.30,<2",
|
|
14
|
+
"anyio>=4",
|
|
15
|
+
"pydantic>=2",
|
|
16
|
+
"requests>=2",
|
|
17
|
+
"typing_extensions>=4.10",
|
|
18
|
+
]
|
|
19
|
+
keywords = ["mcp", "3d-printing", "stl", "mesh", "printability", "claude", "cursor"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Topic :: Multimedia :: Graphics :: 3D Modeling",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
propermesh-mcp = "propermesh_mcp.server:main"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://propermesh.com"
|
|
30
|
+
Documentation = "https://pypi.org/project/propermesh-mcp/"
|
|
31
|
+
|
|
32
|
+
# Development only: use the SDK from this checkout. Published packages depend on propermesh from PyPI
|
|
33
|
+
[tool.uv.sources]
|
|
34
|
+
propermesh = { path = "../sdk", editable = true }
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["hatchling"]
|
|
38
|
+
build-backend = "hatchling.build"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/propermesh_mcp"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.sdist]
|
|
44
|
+
include = ["LICENSE", "src/propermesh_mcp", "README.md"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""MCP server that wraps the Propermesh API (https://propermesh.com) for AI agents"""
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""The server's settings, read from the environment the MCP client launches it with"""
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
ACCESS_KEY_VAR = 'PROPERMESH_ACCESS_KEY'
|
|
6
|
+
SECRET_KEY_VAR = 'PROPERMESH_SECRET_KEY'
|
|
7
|
+
DOMAIN_VAR = 'PROPERMESH_DOMAIN'
|
|
8
|
+
DEFAULT_DOMAIN = 'https://propermesh.com'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class Settings:
|
|
13
|
+
# Empty when the variable isn't set. The server still starts so the client can list its tools, and
|
|
14
|
+
# every tool call says which variables are missing
|
|
15
|
+
access_key: str
|
|
16
|
+
secret_key: str
|
|
17
|
+
# Without a trailing slash
|
|
18
|
+
domain: str
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def missing_variables(self) -> list[str]:
|
|
22
|
+
return [name for name, value in ((ACCESS_KEY_VAR, self.access_key), (SECRET_KEY_VAR, self.secret_key))
|
|
23
|
+
if not value]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def settings_from_env(env: Mapping[str, str]) -> Settings:
|
|
27
|
+
domain = env.get(DOMAIN_VAR, '').strip() or DEFAULT_DOMAIN
|
|
28
|
+
return Settings(
|
|
29
|
+
access_key=env.get(ACCESS_KEY_VAR, '').strip(),
|
|
30
|
+
secret_key=env.get(SECRET_KEY_VAR, '').strip(),
|
|
31
|
+
domain=domain.rstrip('/'),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def missing_keys_message(settings: Settings) -> str | None:
|
|
36
|
+
"""The error every tool returns while the API keys aren't set, or None when they are"""
|
|
37
|
+
missing = settings.missing_variables
|
|
38
|
+
if not missing:
|
|
39
|
+
return None
|
|
40
|
+
return (f'{" and ".join(missing)} {"is" if len(missing) == 1 else "are"} not set. Set '
|
|
41
|
+
f'{ACCESS_KEY_VAR} and {SECRET_KEY_VAR} to a Propermesh API key in the MCP server\'s '
|
|
42
|
+
'environment (e.g. claude mcp add -e), then restart the server')
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Agent-readable messages for the errors a tool call can hit"""
|
|
2
|
+
from propermesh import ProperMeshAPIError
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ToolFailure(Exception):
|
|
6
|
+
"""A tool call that can't return a result. The MCP server turns it into a tool error (isError) with
|
|
7
|
+
this message, which is written for the agent that called the tool"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def api_error_message(err: ProperMeshAPIError) -> str:
|
|
11
|
+
status, detail = err.status_code, err.detail
|
|
12
|
+
if status in (401, 403):
|
|
13
|
+
return (f'Propermesh rejected the API key ({status}: {detail}). Check PROPERMESH_ACCESS_KEY and '
|
|
14
|
+
'PROPERMESH_SECRET_KEY')
|
|
15
|
+
if status == 413:
|
|
16
|
+
return f'The file is too big for your Propermesh plan: {detail}'
|
|
17
|
+
if status == 429:
|
|
18
|
+
retry = (f' Retry after {err.retry_after} seconds.' if err.retry_after is not None
|
|
19
|
+
else ' Waiting won\'t help until the limit resets or the plan changes.')
|
|
20
|
+
return f'A Propermesh usage limit was reached: {detail}.{retry}'
|
|
21
|
+
if status >= 500:
|
|
22
|
+
return f'Propermesh had a server error ({status}: {detail}). Try again in a minute'
|
|
23
|
+
return f'Propermesh refused the request ({status}): {detail}'
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Reads the per-face value layers the API serves and reduces them to the numbers the checks report. Pure"""
|
|
2
|
+
import math
|
|
3
|
+
import sys
|
|
4
|
+
from array import array
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
MM_PER_INCH = 25.4
|
|
8
|
+
MAX_THICKNESS_MM = 1000.0 # the API's bound on a thickness threshold
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def decode_layer(data: bytes, face_count: Optional[int] = None) -> array:
|
|
12
|
+
"""The float32 values of a layer (little-endian on the wire). Later API versions may append data after
|
|
13
|
+
the first face_count values, so only those are read when the count is given"""
|
|
14
|
+
values = array('f')
|
|
15
|
+
usable = len(data) - len(data) % values.itemsize
|
|
16
|
+
values.frombytes(data[:usable])
|
|
17
|
+
if sys.byteorder == 'big':
|
|
18
|
+
values.byteswap()
|
|
19
|
+
return values[:face_count] if face_count is not None else values
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def thinnest(values: array) -> Optional[float]:
|
|
23
|
+
"""The smallest finite value (NaN is unknown), or None when there is none"""
|
|
24
|
+
finite = [v for v in values if math.isfinite(v)]
|
|
25
|
+
return min(finite) if finite else None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def worst_overhang(values: array, critical_angle: float) -> Optional[float]:
|
|
29
|
+
"""The smallest angle below critical_angle, ignoring build-plate faces (Infinity) and unknown ones
|
|
30
|
+
(NaN). None when no face is below it"""
|
|
31
|
+
below = [v for v in values if math.isfinite(v) and v < critical_angle]
|
|
32
|
+
return min(below) if below else None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def length_to_mm(value: Optional[float], units: Optional[str]) -> Optional[float]:
|
|
36
|
+
return value * MM_PER_INCH if value is not None and units == 'inches' else value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def area_to_mm2(value: Optional[float], units: Optional[str]) -> Optional[float]:
|
|
40
|
+
return value * MM_PER_INCH ** 2 if value is not None and units == 'inches' else value
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Where a tool writes the STL it downloads, and the write itself"""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from propermesh_mcp.errors import ToolFailure
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def output_path_for(input_path: Optional[Path], explicit: Optional[str], suffix: str) -> Optional[Path]:
|
|
9
|
+
"""The file to write, or None to write nothing.
|
|
10
|
+
|
|
11
|
+
explicit (~ expanded) wins. Otherwise a file input gets `<stem>-<suffix>.stl` next to it, and a part_id
|
|
12
|
+
input (input_path None) gets nothing. Raises ToolFailure if the target is the input file"""
|
|
13
|
+
explicit = (explicit or '').strip() or None
|
|
14
|
+
if explicit:
|
|
15
|
+
target = Path(explicit).expanduser().resolve()
|
|
16
|
+
elif input_path is not None:
|
|
17
|
+
target = input_path.with_name(f'{input_path.stem}-{suffix}.stl')
|
|
18
|
+
else:
|
|
19
|
+
return None
|
|
20
|
+
if input_path is not None and target == input_path.resolve():
|
|
21
|
+
raise ToolFailure(f'The output path {target} is the input file. Pick another output_path: '
|
|
22
|
+
'the input is never overwritten')
|
|
23
|
+
return target
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def write_stl(target: Path, data: bytes) -> bool:
|
|
27
|
+
"""Writes data to target, creating parent directories. Returns whether it replaced an existing file"""
|
|
28
|
+
replaced = target.exists()
|
|
29
|
+
try:
|
|
30
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
target.write_bytes(data)
|
|
32
|
+
except OSError as e:
|
|
33
|
+
raise ToolFailure(f'Couldn\'t write {target}: {e}') from e
|
|
34
|
+
return replaced
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Turns a tool's path or part_id input into a part id, uploading a path once per server process"""
|
|
2
|
+
import threading
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Literal, NamedTuple, Protocol, Union
|
|
6
|
+
|
|
7
|
+
from propermesh import ProperMeshClient
|
|
8
|
+
|
|
9
|
+
from propermesh_mcp.errors import ToolFailure
|
|
10
|
+
|
|
11
|
+
UnitsName = Literal['mm', 'inches']
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class PathInput:
|
|
16
|
+
path: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class PartIdInput:
|
|
21
|
+
part_id: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
PartInput = Union[PathInput, PartIdInput]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def choose_input(path: str | None, part_id: str | None) -> PartInput:
|
|
28
|
+
"""The one input the tool was given. Raises ToolFailure for both or neither (blank counts as unset)"""
|
|
29
|
+
path = (path or '').strip() or None
|
|
30
|
+
part_id = (part_id or '').strip() or None
|
|
31
|
+
if path and part_id:
|
|
32
|
+
raise ToolFailure('Pass either path or part_id, not both')
|
|
33
|
+
if path:
|
|
34
|
+
return PathInput(path)
|
|
35
|
+
if part_id:
|
|
36
|
+
return PartIdInput(part_id)
|
|
37
|
+
raise ToolFailure('Pass path (a local STL, OBJ, 3MF or STEP file) or the part_id of an uploaded part')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class CacheKey(NamedTuple):
|
|
41
|
+
path: str
|
|
42
|
+
size: int
|
|
43
|
+
mtime_ns: int
|
|
44
|
+
units: str
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class FileStat(Protocol):
|
|
48
|
+
"""The parts of os.stat_result the cache key reads"""
|
|
49
|
+
@property
|
|
50
|
+
def st_size(self) -> int: ...
|
|
51
|
+
@property
|
|
52
|
+
def st_mtime_ns(self) -> int: ...
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def cache_key(path: Path, stat: FileStat, units: str) -> CacheKey:
|
|
56
|
+
"""The upload cache's key for an absolute path. A file with a new size or mtime is a new key, so an
|
|
57
|
+
edited file uploads again"""
|
|
58
|
+
return CacheKey(str(path), stat.st_size, stat.st_mtime_ns, units)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def existing_file(path: str) -> Path:
|
|
62
|
+
"""The absolute path of a file input, with ~ expanded. Raises ToolFailure if it isn't a file"""
|
|
63
|
+
resolved = Path(path).expanduser().resolve()
|
|
64
|
+
if not resolved.is_file():
|
|
65
|
+
raise ToolFailure(f'No file at {resolved}' if not resolved.exists() else f'{resolved} is not a file')
|
|
66
|
+
return resolved
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class PartResolver:
|
|
70
|
+
"""Remembers the part each uploaded file became, for as long as the server runs, so the same file
|
|
71
|
+
uploads once across tool calls. Nothing is written to disk"""
|
|
72
|
+
|
|
73
|
+
def __init__(self) -> None:
|
|
74
|
+
self._parts: dict[CacheKey, str] = {}
|
|
75
|
+
self._lock = threading.Lock()
|
|
76
|
+
|
|
77
|
+
def part_id(self, client: ProperMeshClient, path: str | None, part_id: str | None,
|
|
78
|
+
units: UnitsName) -> str:
|
|
79
|
+
chosen = choose_input(path, part_id)
|
|
80
|
+
if isinstance(chosen, PartIdInput):
|
|
81
|
+
return chosen.part_id
|
|
82
|
+
|
|
83
|
+
file = existing_file(chosen.path)
|
|
84
|
+
key = cache_key(file, file.stat(), units)
|
|
85
|
+
with self._lock:
|
|
86
|
+
cached = self._parts.get(key)
|
|
87
|
+
if cached is not None:
|
|
88
|
+
return cached
|
|
89
|
+
|
|
90
|
+
uploaded = client.upload_part_file(str(file), units)
|
|
91
|
+
with self._lock:
|
|
92
|
+
self._parts[key] = uploaded
|
|
93
|
+
return uploaded
|