# cad-agent: an agent that designs parts with FreeCAD

**Question.** Which open-source CAD system does both production 2D drafting and 3D solid modelling well enough for
an agent to drive it? How should that agent work, when should it call NVIDIA simulation, and does it work in practice?

**Answer, in short.** Use **FreeCAD 1.1.4** (LGPL). It is the only open-source package with a parametric B-rep
modeller, a constraint sketcher, production drawings (TechDraw), FEM, and a Python API that runs with no display.
An agent built on it works: a fresh LLM agent that could reach CAD only through our MCP server designed a
bearing flange in 9 tool calls. The volume matched the hand calculation exactly, every check passed, and a
parametric edit passed too. CPU FEA (CalculiX) settles parts of this size in seconds, so NVIDIA tools are planned
for big, nonlinear, flow, or many-variant problems. Warp's FEM agrees with beam theory to 0.9 % on CPU, but no GPU
run has been done.

Everything below was run on Linux x86_64 without a display on 2026-11-29 unless it says otherwise.

## 1. Recommendation: FreeCAD ([docs/01-cad-comparison.md](docs/01-cad-comparison.md))

Eight systems compared: FreeCAD, BRL-CAD, SolveSpace, LibreCAD, QCAD, OpenSCAD, CadQuery and build123d. Licence, 2D, 3D, scripting, formats and activity were checked; activity was measured from
the GitHub API. FreeCAD wins on breadth (Sketcher + PartDesign + TechDraw + FEM + Python) and activity (1,301
commits in 90 days). Runners-up by job:
- **CadQuery/build123d**: code-first 3D on the same OpenCASCADE kernel, but no drafting.
- **LibreCAD/QCAD**: pure 2D drafting.
- **SolveSpace**: small constraint-based 3D.

Only FreeCAD was run; the other systems' feature lists come from their documentation.

## 2. Agent design ([docs/02-agent-design.md](docs/02-agent-design.md), [mcp/](mcp/))

- **The script is the design.** Each part is a Python build script plus a parameter spreadsheet. The FCStd is a
  build product.
- **Measure, never trust a recompute.** Every build ends in numeric checks: bbox, volume vs hand calculation,
  holes by diameter, inside/outside probe points, valid single solid, fully constrained sketches, and no
  feature in error.
- **Tools come from an MCP server** (`mcp/cad_mcp_server.py`, JSON-RPC over stdio). Each call runs one fresh
  `freecadcmd` process, so a FreeCAD crash costs one call. The 12 tools are `cad_run_script`,
  `cad_inspect`, `cad_set_params`, `cad_check`, `cad_export` (STEP re-read and compared), `cad_drawing`,
  `cad_render` (PNG returned to the model as image content), `cad_fem`, `cad_interference` (overlaps, contacts and
  gaps between assembly parts), `cad_assembly_drawing` (exploded view, balloons, parts list), `cad_fit` (ISO 286
  fits) and `cad_joint_check` (joint angles, distances and limit violations after a solve). Any MCP client can use it
  (Claude Code, Claude Desktop, …).
- **The agent looks at its drawings.** The first flange sheet was wrong and the agent could not see it.
  `cad_render` now returns the image to the model.

## 3. NVIDIA simulation plan ([docs/03-nvidia-simulation.md](docs/03-nvidia-simulation.md), [nvidia/](nvidia/))

The agent goes through three gates in order:
1. **No simulation** when a standard, a fit, or a hand calculation with a safety factor of 3 or more settles it.
2. **CPU FEA**: FreeCAD FEM + Gmsh + CalculiX, which ship in the AppImage.
3. **NVIDIA** only when a part is above ~2M DOF, nonlinear or transient (a CPU run over ~10 min), needs more than
   ~50 variants, or involves flow. The tools for that gate:
   - **Warp FEM**: GPU elasticity and heat; differentiable, so it gives gradients for optimisation.
   - **cuDSS**: GPU sparse direct solver under an implicit FEA code.
   - **AmgX + OpenFOAM**: GPU-accelerated flow solves.
   - **PhysicsNeMo**: surrogates for sweeps.
   - **DoMINO-Automotive-Aero NIM**: pretrained external-aero surrogate.

Measured: our Warp FEM cantilever on **CPU** gives a tip deflection of 0.5801 mm. Timoshenko beam theory gives
0.5852 mm (−0.9 %) and CalculiX gives 0.5814 mm. The CalculiX bracket solve grew from 2.9 s at 25k nodes to
264 s at 276k nodes, which is where a GPU would start to pay. **No GPU was available, so there is no GPU timing**
(see the Wishlist).

## 4. Working examples

| | what | result |
|---|---|---|
| [example/](example/) L-bracket | script → spreadsheet params → constrained sketch → Pad → parametric holes → checks → STEP/STL/FCStd → drawing (SVG/PNG/DXF) → FEA | volume 37,727.94 mm³ = hand calc; variant (thicker, longer) passes; FEA at 500 N: 0.128 mm, 42.3 MPa at the upright root, SF 6.5 on yield there and 4.4 at 1 mm from the bolted hole edge (converged to 0.3 %); the 102-144 MPa peak on that edge is the singularity of the rigid hole fixture and grows with every refinement ([fem_singularity.md](example/fem_singularity.md); with bolts as washer rings the hole edge settles and SF outside the clamped area is 4.8-6.4, [fem_washer.md](example/fem_washer.md)); 4 meshes + 3 local refinements |
| [example2-flange/](example2-flange/) 608 bearing flange | designed by an LLM agent through MCP only, full transcript | 9 tool calls; 18,620.244 mm³ = hand calc; all checks pass; edit to 70 mm / PCD 52 passes; FEA SF 36 away from the fixed holes (21 on the singular fixture-edge peak) |
| [example3-assembly/](example3-assembly/) bolted assembly | plate + linked bracket + 3 M6 bolts/nuts via MCP; new `cad_interference` tool | nominal: 0 interferences, 10 contacts, 0.3 mm bolt gaps; a 1 mm bolt shift and a stale assembly after a bracket edit are both caught; STEP 8 solids |
| [example4-joints/](example4-joints/) assembly by joints | same parts placed by 7 Fixed joints in FreeCAD's Assembly workbench, solved headless from 10 random starts | 10/10 assemble to within 7e-13 mm after flipping wrongly oriented joints; follow a bracket edit; `cad_interference` passes (same 112,736.31 mm³ as example 3) and fails the solver's unflipped first guess; `cad_assembly_drawing` makes the exploded-view sheet with balloons, parts list and a front view with hidden lines; its 7 MCP calls replay identically; a **hinge**: an arm on a Revolute joint swept 0-180 degrees keeps its angle and axis, first touches the plate at 125.777 degrees by bisection (125.761 by hand), `cad_interference` passes at 0/45/90 and fails at 135/180; FreeCAD's joint angle limits are passed to the solver but not enforced by `solve()` (GUI drag only), so the script checks the joint angle after each solve and flags 121/150/-150/180 against ±120; a **slider** on a Slider joint in a channel travels 70 mm between its end walls (bisection 70.0 = hand 70), `cad_interference` fails at -1 and 71 mm, and the new `cad_joint_check` tool reads each joint's angle or distance, axis alignment and limit violations from the solved file; a **slider-crank** (a closed loop of 3 Revolute joints and a Slider joint) turned through 360 degrees puts the slider where the hand formula does at all 13 angles (max difference 1.4e-14 mm, stroke 40.000 mm = 2r), driven either by holding the crank during each solve or by FreeCAD's own kinematic simulation (a Motion on the crank joint, run headless after working around an import that needs the GUI); turned alone, the solver closes the loop by turning the crank back; a pin on a **Cylindrical** joint (turn and slide) and a rod on a **Ball** joint keep every set position, and their ends of travel by bisection match hand values (head on the bushing at -30.000 mm, rod on the cup's rim at 65.60 against 65.59 degrees) |
| [example5-bracket-sf/](example5-bracket-sf/) bracket sized to a safety factor | a fresh agent, through MCP only, given SF >= 4.5 at 500 N | as-given 8 mm fails the gate at SF 4.36; it chose 8.5 mm (SF 5.0, three fine meshes within 3 %); found the gate compared a rounded SF (fixed) |
| [example6-tolerances/](example6-tolerances/) fits and threads on the drawing | `cad_drawing` with `hole_specs`, `datums` and `general_tolerance`; `cad_fit` | `3x M6x1-6H THRU` with ISO 6410 thread arcs, `Ø10 H7 (+0.015/0) THRU`, ISO 2768-mK note; datums A, B, C and position frames `POSITION Ø0.2 \| A \| B \| C` with boxed basic dimensions equal to the model's hole positions (rows 9 mm apart, values centred, measured from the SVG); `FLATNESS 0.05` on datum A and `PERPENDICULARITY 0.1 \| A` on B, beside their datum symbols and clear of everything else; ISO 286 hole and shaft limits match the published tables (20 limits, 5 fits: H7/g6 Ø10 clearance 0.005-0.029 mm); an M8 request on the M6 tap drill, or a frame naming an undefined datum, comes back as a warning; a fresh agent given the request in words modelled the M6 holes at the Ø5 tap drill itself and chose a g6 pin with `cad_fit` |
| [interchange/](interchange/) | other tools read the outputs | STEP re-read by OCP (CadQuery's OpenCASCADE): same volumes, valid solids; and by truck (Rust kernel, no OpenCASCADE): same faces and bbox, mesh volume converges to within 0.006 %; DXF opened in LibreCAD 2.2 |

Drawings carry four views (third angle), overall dimensions, centre marks, hole callouts ("4x Ø5.5 THRU"), a PCD
circle, notes and a title block; on request, hole fits with their limits, tapped holes and a general-tolerance note. The DXF matches the SVG sheet, with layers; dimensions are plain lines, arrowheads and text
in model mm, so every DXF reader shows the same values.

## What worked

- FreeCAD runs headless from the AppImage, with no install and no display. The Sketcher, PartDesign, TechDraw,
  FEM, Gmsh and CalculiX are all usable from Python.
- Parametric edits via the spreadsheet recompute correctly, and the checks catch it when they do not.
- An LLM agent given only the MCP tools designed a correct part on its first attempt. It needed one fix, to its own
  error-scan code.
- CalculiX results converge and agree with Warp FEM and with beam theory.
- STEP round-trips exactly (FreeCAD → FreeCAD and FreeCAD → OCP).
- The Assembly workbench's joints and solver work headless; 10 random starts all assemble once wrongly oriented
  joints are flipped.

## What did not work (and what we did about it)

- **Topological naming:** a 3D fillet broke silently after an edit, with no object in error. The fix was to move
  the fillet into the sketch; the agent rule is to avoid edge-picking features or to re-select edges by geometry.
- **The agent's first drawing was wrong** (wrong scale, touching views, a dropped note) and the agent could not
  see it. Fixed in the tool, and the render now goes back to the model.
- **"Holes" counted every cylinder**, including corner rounds. Fixed: a hole is now a concave cylinder that
  closes 360°.
- **TechDraw's DXF export was wrong:** the views were 1:1 at 1:2 positions and overlapped, yet ezdxf's audit
  passed. LibreCAD exposed it. Fixed by writing the DXF ourselves. Lesson: check a drawing by looking at it in a
  second program, not by auditing the file.
- **SVG/PDF export of TechDraw pages needs the GUI**, so the sheet is composed from TechDraw's projected views plus
  our own dimensions. Its dimensions are not associative to the model.
- **Removing a TechDraw page in `freecadcmd` with its views attached segfaulted FreeCAD 1.1.4**, so old pages piled up
  (10–12 per part). Fixed: `cad_drawing` now detaches and removes dimensions, then views, then the template, then the
  page, and each FCStd keeps one current page (volumes unchanged).
- **DXF DIMENSION entities did not survive LibreCAD.** It recomputes their text from the sheet length, ignoring
  `dimlfac` and explicit text, and drew vertical ones as a dot. The sheet DXF now writes dimensions as plain geometry
  and text, which reads right everywhere but is no longer an editable dimension in a CAD program.
- **The assembly solver reports success for wrong assemblies.** From random starts it put some parts upside down
  (260 mm³ overlaps) and still returned 0; after a part edit it kept stale joint frames. The script now checks
  placements after every solve, flips wrong joints and recomputes joint frames after edits (example 4).
- **`cad_interference` passed an Assembly container as one part** (0 contacts). Fixed: its children are checked one by one.

## What is left

1. **A GPU run.** `sh nvidia/gpu_run.sh` does all of it in one command on an NVIDIA machine (tested on this CPU host):
   it solves the bracket's own CalculiX decks with Warp FEM (`nvidia/warp_bracket.py`) up to the 1 mm mesh (about 830k
   DOFs; add a smaller size to MESHES for 10⁶+) and writes the speedup over CalculiX to `nvidia/gpu_results.json`.
   This needs an A100- or H100-class GPU (float64) for about 1 hour (Wishlist). On CPU, Warp already
   matches CalculiX on the bracket (max displacement −0.44 %, node-by-node RMS difference 0.18 µm), but its CG
   takes 149 s (FSAI preconditioner; 336 s with Jacobi) where CalculiX's direct solver takes 2.9 s, so the GPU run
   should use cuDSS or an AMG preconditioner. On the 2 mm mesh (131,643 DOFs) FSAI takes 338 s against 7.3 s: the gap
   stays near 50x as the mesh grows (`nvidia/README.md`). The script's CPU test at 4 mm (53,862 DOFs) gave FSAI 89 s and
   Jacobi 208 s against CalculiX 1.8 s, both −0.43 % on max displacement. The agent can already ask for this
   solver: `cad_fem` with `solver: "warp"` returns Warp's answer next to CalculiX's (`nvidia/mcp_warp_transcript.jsonl`).
2. Not done: joint limits enforced by the solver (FreeCAD's `solve()` ignores them;
   `cad_joint_check` flags them), mechanisms with more than one degree of freedom (Fixed, Revolute, Slider, Cylindrical and Ball joints and a
   one-degree-of-freedom closed loop, a slider-crank, are done, example 4); GD&T
   other than position and flatness/perpendicularity/parallelism of datum faces (profile, runout,
   MMC modifiers; hole fits, tapped holes, datums, position frames such as POSITION Ø0.05 | A | C with their basic
   dimensions, FLATNESS 0.05, PERPENDICULARITY 0.1 | A and PARALLELISM 0.05 | A are done, example 6); and review of the drawings by a
   human draftsperson.

Details and every measured number: [STATUS.md](STATUS.md).

## Key numbers

Generated from the committed result files by `python3 make_report.py`; `run_all.sh` fails if this table, or a number the text above quotes from it, no longer matches its source.

<!-- report:begin (generated by make_report.py; do not edit by hand) -->

| number | value | source |
|---|---|---|
| Test run | 20/20 pass, 0 skipped, 662 s of checks | `test_report.json` |
| Bracket volume | 37,727.94 mm³ (hand calc 37,727.94) | `example/out/report.json` |
| Flange volume (STEP re-read by OCP) | 18,620.244 mm³ | `interchange/step_check.json` |
| Bracket FEA, 500 N: max displacement | 0.128 mm at 1 mm mesh | `example/out/fem_report.json` |
| Bracket FEA: upright root stress | 42.3 MPa, SF 6.5 | `example/out/fem_report.json` |
| CalculiX solve time | 2.9 s at 25k nodes -> 264 s at 276k | `example/out/fem_report.json` |
| Flange STEP re-read by truck, mesh volume | 18,621.341 mm³ (0.006 % off) | `interchange/truck_check.json` |
| Bracket stress 1 mm from the bolted hole edge (hole faces 0.3 mm) | 62.6 MPa, SF 4.4 | `example/fem_singularity.json` |
| Hole-edge peak, hole faces 1 / 0.5 / 0.3 mm | 96 -> 128 -> 144 MPa (singular) | `example/fem_singularity.json` |
| Washer-ring bolts: stress outside the rings | 57.6 MPa stiff / 43.4 MPa compliant, SF 4.8-6.4 | `example/fem_washer.json` |
| Flange, fresh agent with the FEA pass/fail check | pass, SF 35.7, moved -1.8 %, 4 tool calls | `example2-flange/gate_rerun/mcp_transcript.jsonl` |
| Bracket sized by a fresh agent to SF >= 4.5 | thickness 8 -> 8.5 mm; gate pass at SF 5.0; 2 of 4 gate runs pass, 11 tool calls | `example5-bracket-sf/mcp_transcript.jsonl` |
| Flange, first agent run | 9 tool calls | `example2-flange/mcp_transcript.jsonl` |
| Assembly by joints | 10/10 random starts assemble and follow the edit, max error 7e-13 mm | `example4-joints/results.json` |
| Assembly total volume | 112,736.3 mm³, 8 parts in 4 parts-list rows, leader crossings 0 | `example4-joints/results.json` |
| truck (Rust) STEP re-read, bracket mesh volume | 37,729.932 mm³ (0.005 % off) at tolerance 3e-05 | `interchange/truck_check.json` |
| NVIDIA Warp FEM on the bracket's CalculiX deck (CPU) | max displacement −0.44 % at 74,172 DOFs, −0.40 % at 131,643; nodal RMS 0.18 µm | `nvidia/warp_bracket_h3_fsai.json, nvidia/warp_bracket_h2_fsai.json` |
| Warp CG solve time vs CalculiX (CPU) | 336 s Jacobi / 149 s FSAI vs 3.0 s at 74k DOFs; 338 s FSAI vs 7.3 s at 132k | `nvidia/warp_bracket_h*.json` |
| Drawing tolerances (example 6) | 3x M6x1-6H THRU; POSITION Ø0.2 | A | B | C; Ø10 H7 (+0.015/0) THRU; POSITION Ø0.05 | A | C; FLATNESS 0.05; PERPENDICULARITY 0.1 | A; PARALLELISM 0.05 | A; ISO 2768-mK; ISO 286 checked on 10 hole and 10 shaft limits, 5 fits | `example6-tolerances/result.json` |
| gpu_run.sh tested on CPU, 4 mm mesh | 53,862 DOFs: FSAI 89 s, Jacobi 208 s vs CalculiX 1.8 s; −0.43 % | `nvidia/gpu_run_cpu_test_4mm.json` |
| MCP cad_fem with solver warp (L-bracket, 3 mm) | 76,068 DOFs: Warp 0.10363 mm vs CalculiX 0.10398 mm (−0.34 %), 1,030 CG its, 148 s CPU | `nvidia/mcp_warp_transcript.jsonl` |

<!-- report:end -->

## Reproduce

One command runs every example and check and writes `test_report.json` (exit 0 only if all that ran pass;
checks whose tool is not given are listed as skipped). Last run: see `test_report.json` (2026-11-29, 20-core
x86_64 host without a GPU: **20/20 pass in about 11 min**: bracket FEA 64 s, the flange gate re-run 153 s, the gate rejection 44 s, the Warp check 163 s, the Warp MCP replay 168 s); with only FreeCAD given, the checks that need
OCP, truck and Warp are skipped and the rest pass.

```sh
FCDIR=<dir with usr/bin/freecadcmd> PYLIB=<ezdxf+trimesh for py3.11> OCPLIB=<OCP for python3> \
  TRUCK=<ricosjp/truck checkout> PY313LIB=<trimesh+pillow for python3> WLIB=<warp-lang for py3.11> sh run_all.sh
```

| check | what it compares |
|---|---|
| example1_bracket | build, variant and reopen-edit checks (`all_ok` in three reports) |
| example1_fem | CalculiX peak stress, upright-root peak and deflection within 2 % of the committed `fem_report.json` at the same mesh |
| example1_independent | mesh and DXF re-read with trimesh and ezdxf |
| example2_replay | the agent's 15 MCP calls replayed in a fresh workspace, results compared |
| example3_assembly | nominal assembly passes, 1 mm bolt shift and stale assembly caught |
| example4_joints_drawing | 10 random starts assemble, edit followed, interference, drawing parts list and balloons |
| example4_hinge | Revolute joint: arm swept 0-180 degrees keeps angle and axis, first contact by bisection equals the hand value, `cad_interference` passes at 0/45/90 and fails at 135/180; FreeCAD's joint angle limits are passed to the solver but not enforced by `solve()` (GUI drag only), so the script checks the joint angle after each solve and flags 121/150/-150/180 against ±120 |
| example4_slider | Slider joint: slider in a guide channel swept -1 to 71 mm, bisection travel 70.0 mm = hand 70, `cad_interference` fails only at -1 and 71; `cad_joint_check` (MCP) reports distance = position, LengthMin/LengthMax violations at -1/71 and the hinge's 121/150/-150/180 against its angle limits |
| example4_crank | slider-crank (r 20, L 60 mm) from a scrambled start, crank 0-360 degrees in 30 degree steps held by a temporary grounded joint and again by an Assembly simulation Motion (2 pi time): slider x and rod angle equal the hand formula, stroke 40 mm, an unheld turn is undone by the solver; `cad_joint_check` gives each joint's angle (crank pin = rod - crank) and the guide distance, `cad_interference` 0 overlaps and 4 contacts at every angle |
| example4_pivots | Cylindrical joint (pin d 10 in a 10.2 bore): 6 (angle, distance) pairs kept exactly, travel end -30.000008 mm = hand -30, overlap at -31 mm 119.349 mm³ = π(8² - 5.1²); Ball joint (rod in a half-sphere cup): 12 tilt/azimuth pairs kept with the centres together, rim contact at 65.603 degrees against acos(2.5/6.05) = 65.593; `cad_joint_check` reads angle, distance, ball centre gap and tilt at all 18, LengthMin flagged only at -31 |
| example4_replay | example 4's 7 MCP calls (bracket, joints, interference, unflipped guess, drawing, render) replayed in an empty workspace |
| example2_gate_replay | the fresh agent's flange re-run with the FEA pass/fail check (4 calls, gate pass, SF 35.7) replayed in an empty workspace |
| fem_gate_rejects | the pass/fail check rejects the bracket at a 2 mm hole mesh (stress away from the holes moves -13 % against 1 mm) |
| readme_numbers | `make_report.py --check`: the Key numbers table and the numbers quoted in the prose match the committed result files |
| warp_bracket | NVIDIA Warp FEM (FSAI CG) solves the bracket's 3 mm CalculiX deck; max displacement within 1 % of CalculiX and node-by-node RMS difference under 1 % of it |
| warp_mcp_replay | the agent's MCP call `cad_fem` with `solver: "warp"` (L-bracket, 3 mm mesh, 76,068 DOFs) replayed in an empty workspace; requires `agrees: true` (Warp max displacement within 1 % of CalculiX, node-by-node RMS under 1 %) |
| example6_tolerances | ISO 286 limits for 10 fit/size pairs against the published table; the `cad_drawing` call with an H7 bore and M6 tapped holes: callouts in SVG and DXF, thread arcs concentric at the major diameter, tolerance table; flatness, perpendicularity and parallelism frames clear of the sheet, datum symbols on their own face and 7 mm apart; basic-dimension rows 8 mm or more apart with values centred; a wrong M8 request, a perpendicularity to a parallel or undefined datum and a parallelism to a perpendicular one warn |
| interchange_step_ocp | both STEPs re-read by OCP equal `step_check.json` |
| interchange_dxf_librecad | both DXF drawings converted to PDF by LibreCAD |
| interchange_truck | both STEPs read and meshed by truck (Rust) |

`example/run.sh` regenerates `example/out*` in place; `git checkout -- example` restores the committed files.

Step by step:

```sh
example/decode_binaries.sh        # restore *.b64 binaries (FCStd, STL, PNG)
cd example && ./run.sh            # downloads FreeCAD 1.1.4 AppImage (sha256-checked), builds, checks, renders
sh example3-assembly/run.sh && sh example4-joints/run.sh   # assemblies (need FCBIN)
python3 example2-flange/replay.py  # replays the agent's 15 MCP calls and compares results (needs FCBIN, CAD_PYLIB)
python3 example2-flange/replay.py example4-joints/mcp_transcript.jsonl   # example 4's 7 calls (record.sh re-records)
# MCP server: FCBIN=<freecad>/usr/bin CAD_WORKSPACE=./ws CAD_PYLIB=<dir with ezdxf> python3 mcp/mcp_call.py list
```
