Skip to main content

mesh2cad

mesh2cad converts an STL mesh of a simple mechanical part into editable parametric CAD: STEP, CadQuery, OpenSCAD, and FreeCAD scripts. It is also an MCP server.

ci PyPI emirmrkaljevic/mesh2cad MCP server

Support my open-source work: get a SkinToScan pack
If you find this useful, you can support me by getting a SkinToScan pack, my other project. It's a one-time purchase that directly funds my open-source work.

Buy Single Picture Check, €4.49 Buy 5 Picture Pack, €19.99 (popular) Buy 15 Picture Pack, €54.99

OBJ and PLY meshes work the same way. The fit runs on your machine. Nothing is uploaded.

A STEP file is the solid. When the fit is exact, a hole is one cylindrical face, not a ring of triangles. A script is for changing a dimension and rebuilding. CadQuery is Python. OpenSCAD is the text the Customizer on Thingiverse and Printables edits. The FreeCAD file is a macro. All three use the same names, so hole_1_d is the same hole in each of them.

before/after

Left: a 21k-triangle mesh with 0.1 mm noise. Right: the STEP file mesh2cad writes, 10 planes and 2 cylinders, max deviation 0.05 mm from the true part.

demo

Four printer parts, with the STEP files and the generated scripts, are in the example gallery.

Hackaday wrote about it: Mesh2Cad Automates Re-Modelling.

Install

pip install mesh2cad

Python 3.10 or newer. That install is the command line tool and STEP export. OpenCascade comes in with the package (cadquery-ocp).

pip install "mesh2cad[mcp]" adds the server. pip install "mesh2cad[cadquery]" lets mesh2cad run a generated .py and check it before the file is written. OpenSCAD and FreeCAD are separate programs, not pip packages. Without openscad on PATH, a .scad file is still written and the command says it was not verified. A .FCMacro is written only when a check passes. What happens when freecadcmd is missing is in Install.

Quick start

mesh2cad convert plate.stl --cadquery plate.py
mesh2cad edit plate.py --set hole_grid_1_d=8 --in-place -o plate.step

The first command writes plate.py. Diameters, thicknesses, and positions are names at the top of the file. A four-hole grid is hole_grid_1_d. The second sets that diameter to 8 mm, rewrites the script, and writes plate.step. Every other byte of the file stays as it was.

mesh2cad edit bracket.py --set base_x=+2 adds 2 mm to the current length. A leading + or - is a change from the current number, not how you set a negative value. mesh2cad params bracket.py prints each name, its value, and the unit when there is one.

A STEP file on its own is mesh2cad convert part.stl -o part.step. Add --report report.md for the numbers: Hausdorff and RMS deviation, volume error, face types, and the method (exact, faceted-hybrid, or faceted). Open that STEP file in FreeCAD, Fusion, Onshape, or another CAD tool and select a face.

If the part is outside what a script can express, or the rebuilt solid misses the check, the script is not written and the command exits with code 2. The reason is printed. The same convert can write .scad and .FCMacro. Flags are in the CLI reference. What the scripts contain is in CadQuery, OpenSCAD, and FreeCAD. The edit rules are in Parameters.

What it handles

It is meant for simple mechanical parts: plates, brackets, and boxes with holes, bolt circles, slots, bosses (including on an extruded outline), countersunk and counterbored holes on that outline, and fillets. A Z extrusion can also carry one radius on every vertical corner of the outline. It fits planes, cylinders, spheres, cones, and constant-radius rounds, and writes those as faces you can select.

It does not recover organic or sculpted shapes, scans, or free-form surfaces. When a fit is poor it does not invent a surface. STEP output falls back to a faceted solid that is still valid, and the report names that fallback. A script is held to a tighter check: deviation at most max(4 times the tolerance, 0.1 mm), and volume error at most 1%. Miss that, and the script is refused.

Six Original Prusa i3 MK3S printed parts in the test set come back as exact STEP, and all six also as a script. The measurements, including the small belt-profile patches that stay faceted, are in Real parts. Synthetic noise tests are in Benchmarks. The fitted-surface list, the parameter names, and the refusals are in Limits (v0.31.0). The pipeline is in How it works.

MCP

pip install "mesh2cad[mcp]"
mesh2cad mcp

That starts the server on stdio. Point a client at it like this:

{ "mcpServers": { "mesh2cad": { "command": "mesh2cad", "args": ["mcp"] } } }

The tools are convert, analyze, report, to_cadquery, to_openscad, to_freecad, list_params, and edit_params. Arguments, return values, and the directory listings are in MCP.

Docs

Install is the extras and the OpenSCAD and FreeCAD programs. CLI is every command. CadQuery, OpenSCAD, and FreeCAD are the parameter lists and the checks. Parameters is params and edit. MCP is the tool reference. How it works, Limits, Benchmarks, and Real parts are the fit, the refusals, and the numbers. Development is how to run the tests. The changelog is the version history.

Shorter pages on the project site: overview, STL to STEP, STL to OpenSCAD and CadQuery, and FAQ.

A mesh that converts badly can go in a GitHub issue. There is a template for an STL that fails.

License

MIT. See LICENSE.

Metadata

Release files for mesh2cad 0.32.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mesh2cad 0.32.0
File Size Uploaded Provenance Actions
mesh2cad-0.32.0.tar.gz 1.1 MB With provenance Details for mesh2cad-0.32.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mesh2cad 0.32.0
File Interpreter ABI Platform Actions
mesh2cad-0.32.0-py3-none-any.whl Python 3 none any Details for mesh2cad-0.32.0-py3-none-any.whl

Total release size: 1.3 MB

Release files / mesh2cad-0.32.0.tar.gz

Download URL mesh2cad-0.32.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
48dc37e4dc24487d353149783d4195f8c6591d8afe24b1fc28f65880f2c9ca4f
BLAKE2b-256 checksum
How to use checksums
79b73e6b7d07a4b674fc0d334d28bd2194665c9c4287c29bb76ccdf8abafe0d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / mesh2cad-0.32.0-py3-none-any.whl

Download URL mesh2cad-0.32.0-py3-none-any.whl
Size 213.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18aaa81ed3143821a6b1d8e197fc9c1f95369179f55f33d647bf09ef30fbefb3
BLAKE2b-256 checksum
How to use checksums
5f06a3379e8392775fe3160db5513c5ed9a7499129eab736b54cb313ad357ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for mesh2cad 0.32.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mesh2cad-0.32.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.32.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page