← Back to atrey.app

Programmatic 3D CAD: Interfacing LLMs with Parametric B-Rep Kernels

Published August 2026 • Mudit Atrey • Systems Engineering & CAD Tooling

The recent wave of 3D generative AI models focuses almost exclusively on neural radiance fields (NeRFs), 3D Gaussian splatting, or unconstrained triangle surface meshes. While these representations excel at video games, visual effects, and digital rendering, they are functionally unusable in real-world mechanical and aerospace engineering.

A physical CNC mill, lathe, waterjet, or 5-axis machining center does not accept an unstructured polygon mesh. Physical fabrication requires Boundary Representation (B-Rep) solids: exact mathematical NURBS surfaces, analytic cylindrical holes, datum planes, geometric dimensioning and tolerancing (GD&T), and fully editable parametric feature trees.

1. The Fundamental Flaws of Polygon Meshes in Physical Engineering

When a machine shop or aerospace manufacturing team inspects a component, the differences between a faceted mesh and a B-Rep kernel become critical:

Onshape Parametric CAD PartStudio Viewport
Figure 1. Fully parametric B-Rep solid model of a tailless blended wing body generated via automated Onshape REST API calls and FeatureScript loft operations (shaded with edges view). Every surface is a continuous NURBS boundary with certified closed volume.

2. Architecture of onshape-mcp: Model Context Protocol for CAD

Release Status: The onshape-mcp server is currently an internal engineering harness and will remain closed source until further validation, API credential security audits, and multi-user stress testing are completed.

To connect large language models with production CAD kernels, I developed onshape-mcp, a Model Context Protocol server that bridges AI agents directly to the Onshape cloud REST API and Parasolid modeling engine.

Instead of prompting an LLM to hallucinate thousands of 3D point coordinates in text, onshape-mcp exposes structured operational primitives backed by schema validation:

// Example 1: MCP Tool Definition for Parametric Loft Construction
{
  "tool": "onshape_create_spline_loft",
  "arguments": {
    "documentId": "dc3730aa5bcfd1048e6085c2",
    "workspaceId": "cdfb7831adeacf36982cc056",
    "elementId": "c59f1c24624648d9ff93075c",
    "featureName": "MainWingLoft",
    "stationProfiles": [
      {
        "stationName": "RootSection",
        "plane": "Right",
        "chord_mm": 620.0,
        "twist_deg": 0.0,
        "airfoil": "Reflex_Centerbody_v4"
      },
      {
        "stationName": "BlendSection",
        "offset_y_mm": 240.0,
        "chord_mm": 410.0,
        "twist_deg": -1.2,
        "airfoil": "Transition_Mod_12"
      },
      {
        "stationName": "TipSection",
        "offset_y_mm": 775.0,
        "chord_mm": 135.0,
        "twist_deg": -3.8,
        "airfoil": "Tip_Reflex_v2"
      }
    ],
    "boundaryConditions": {
      "startCondition": "MATCH_TANGENT",
      "endCondition": "CLAMP_NORMAL"
    }
  }
}

The MCP server translates this high-level call into validated FeatureScript payloads and dispatches them to Onshape's /api/v6/partstudios/d/{did}/w/{wid}/e/{eid}/features endpoint. The Parasolid kernel evaluates the spline lofts, computes intersection curves, and returns the resulting topology or exact error diagnostics.

3. Enforcing Invariants in Cloud FeatureScript

A major benefit of programmatic CAD is writing custom FeatureScript functions that run natively inside Onshape's kernel. Rather than relying on the LLM to remember mechanical design rules, the FeatureScript itself acts as a deterministic guardrail:

FeatureScript 2447;
import(path : "onshape/std/geometry.fs", version : "2447.0");

annotation { "Feature Type Name" : "AeroLoftGuard" }
export const aeroLoftGuard = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Profile Sketches", "Filter" : EntityType.FACE }
        definition.profiles is Query;

        annotation { "Name" : "Minimum Shell Wall Thickness" }
        isLength(definition.minWallThickness, LENGTH_BOUNDS);
    }
    {
        // 1. Enforce monotonic spanwise chord reduction
        var sketches = evaluateQuery(context, definition.profiles);
        for (var i = 1; i < size(sketches); i += 1)
        {
            var prevBox = evBox3d(context, { "topology" : sketches[i - 1] });
            var currBox = evBox3d(context, { "topology" : sketches[i] });
            var prevChord = prevBox.maxCorner[0] - prevBox.minCorner[0];
            var currChord = currBox.maxCorner[0] - currBox.minCorner[0];
            
            if (currChord > prevChord)
            {
                throw regenError("Geometry Error: Outboard chord exceeds inboard chord. Monotonicity violated.");
            }
        }

        // 2. Execute B-Rep loft with G1 curvature matching at symmetry plane
        opLoft(context, id + "loft", {
            "profileSubfeatures" : sketches,
            "derivativeInfo" : [{ "profileIndex" : 0, "matchCurvature" : true }]
        });
    });

If the LLM generates a design with inverted chords or discontinuous transitions, the Onshape compiler immediately throws a regenError, preventing corrupted geometry from entering the CAD tree.

Exploded Parametric Multi-Body Assembly
Figure 2. Programmatically generated multi-body B-Rep assembly. The parametric kernel coordinates individual component bodies: nose payload pod, canopy hatch, carbon spar pass-through tunnels, elevons, and wing skin panels, each maintaining independent manufacturing tolerances.

4. Closed-Loop Mass Properties & Aerodynamic Sizing

In autonomous flight vehicle design, aerodynamic lofting and internal structural packaging are deeply coupled. An aerodynamically optimal loft is useless if the internal cavities cannot accommodate the required battery cells or payload volume.

Pneumatic Launch Rail Assembly in Onshape
Figure 3. Complex mechanical assembly generated programmatically via the Onshape API: the PL-40 pneumatic catapult launcher showing mated structural extrusion rails, tensioner carriage, and tripod stand geometry.
Onshape Parametric Planform Top View
Figure 4. Planform projection generated in Onshape PartStudio verifying symmetric chord lofting, elevon hinge line offsets, and zero-thickness trailing edge elimination.

Through onshape-mcp, the optimization engine queries the exact mass and inertia tensor via /api/v6/partstudios/.../massproperties after every geometry mutation:

// Example 2: Structured Mass Properties Output from Onshape Kernel
{
  "status": "SUCCESS",
  "hasSingleSolid": true,
  "volume_m3": 0.00784219,
  "surfaceArea_m2": 0.841203,
  "mass_kg": 1.4328,
  "centroid_m": {
    "x": 0.34215,
    "y": 0.00000,
    "z": 0.01842
  },
  "inertiaTensor_kg_m2": [
    [0.089201, 0.000000, -0.001240],
    [0.000000, 0.142055,  0.000000],
    [-0.001240, 0.000000, 0.218540]
  ],
  "watertightSolid": true
}

This exact feedback allows the optimizer to balance the physical center of gravity directly against the aerodynamic neutral point ($x_{\mathrm{np}}$), guaranteeing longitudinal stability ($SM = 18.5\%$) before committing to tooling.

5. Error Handling and Kernel Rollback Strategies

When an AI agent modifies CAD trees, geometric operations inevitably encounter edge cases. The MCP server handles these through structured feedback loops:

6. Conclusion & Availability

The future of AI in mechanical and aerospace engineering will not be built on text-to-mesh generators. Engineering requires deterministic, inspectable, and manufacturing-ready geometry. By interfacing language models with cloud B-Rep kernels through structured protocols like MCP, software agents can construct real mechanical mechanisms that transition directly from computation to CNC fabrication.

The onshape-mcp server remains closed source while undergoing continued reliability testing, regression hardening, and geometry validation across new vehicle configurations. Access will remain restricted until further testing and safety sandboxing are complete.