/onshape-mcp:onshape-featurescriptfrom onshape-mcp
Authoring custom FeatureScript features for Onshape CAD. Covers syntax, imports, standard boilerplate, precondition schemas, unit discipline, query patterns, and proven recipes (threads, helical sweeps, revolves, multi-body assemblies). Use whenever writing custom FeatureScript or compiling complex parametric geometry into a single Onshape operation.
Ships in onshape-mcp. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
FeatureScript is Onshape's open-source procedural language used to create native parametric features. Every built-in feature (extrude, revolve, fillet) in Onshape runs on FeatureScript.
[!TIP] API Quota Efficiency Rather than calling 15-20 individual REST API endpoints to sketch, extrude, revolve, cut, and fillet a multi-step part, authoring a single FeatureScript custom feature compiles and generates all geometry in 1 single API call (
write_featurescript_feature). This is critical for staying within the account's 2,500 annual API limit.
Every FeatureScript file must declare the version and import the standard geometry library:
FeatureScript 2931;
import(path : "onshape/std/geometry.fs", version : "2931.0");
A custom feature consists of:
annotation { "Feature Type Name" : "Display Name" }export const featureIdentifier = defineFeature(function(context is Context, id is Id, definition is map)precondition block declaring user-editable parameters.op* and sk* functions.FeatureScript 2931;
import(path : "onshape/std/geometry.fs", version : "2931.0");
annotation { "Feature Type Name" : "My Parametric Part" }
export const myParametricPart = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Outer Diameter" }
isLength(definition.outerDiameter, LENGTH_BOUNDS);
annotation { "Name" : "Total Length" }
isLength(definition.totalLength, LENGTH_BOUNDS);
annotation { "Name" : "Wall Thickness" }
isLength(definition.wallThickness, LENGTH_BOUNDS);
annotation { "Name" : "Hollow Out" }
definition.isHollow is boolean;
}
{
// Feature implementation code goes here
});
Declare inputs within precondition using standard bounds and predicates:
| Parameter Type | Declaration | Example |
|---|---|---|
| Length | isLength(definition.paramName, LENGTH_BOUNDS); | Dimensions in mm / in |
| Angle | isAngle(definition.paramName, ANGLE_BOUNDS); | Sweep angles, tapers |
| Real / Float | isReal(definition.paramName, POSITIVE_REAL_BOUNDS); | Ratios, pitch multipliers |
| Integer | isInteger(definition.paramName, POSITIVE_COUNT_BOUNDS); | Hole counts, fin counts |
| Boolean | definition.paramName is boolean; | Checkboxes (toggles) |
| Entity Query | annotation { "Filter" : EntityType.FACE } definition.targetFace is Query; | Selected faces/edges |
Onshape internally computes all lengths in meters and angles in radians.
sin(), cos(), sqrt()) will produce errors or silent failures if units are not explicitly stripped.The Golden Pattern:
const lengthM = definition.totalLength / meter;
const diamM = definition.outerDiameter / meter;
const radiusM = diamM / 2.0;
const taperAngleRad = atan2((baseRadiusM - tipRadiusM), lengthM);
const centerPoint = vector(0, 0, lengthM) * meter;
In FeatureScript, you track geometry using queries and IDs rather than hardcoded names.
qCreatedBy(id + "opName", EntityType.BODY): Targets bodies created by a specific operation.qCreatedBy(id + "opName", EntityType.FACE): Targets faces created by a specific operation.qGeometry(query, GeometryType.PLANE): Filters a set of faces to only planar faces.qGeometry(query, GeometryType.CYLINDER): Filters to cylindrical faces (e.g. bores, shafts).qSketchRegion(id + "sketchName"): Grabs the closed profile face generated by a sketch.qAllNonMeshSolidBodies(): Selects all active solid bodies in the Part Studio.qSubtraction(queryA, queryB): Set difference between two query sets.qUnion([queryA, queryB]): Combines query sets.qLargest(query): Selects the entity with the largest area/length.To sketch inside FeatureScript:
newSketchOnPlane:
var sketch = newSketchOnPlane(context, id + "sketch1", {
"sketchPlane" : plane(vector(0, 0, 0) * meter, vector(0, 0, 1), vector(1, 0, 0))
});
skLineSegment(sketch, "line1", { "start" : vector(0, 0) * meter, "end" : vector(40, 0) * millimeter });skCircle(sketch, "circle1", { "center" : vector(0, 0) * meter, "radius" : 10 * millimeter });skRectangle(sketch, "rect1", { "firstCorner" : vector(-10, -10) * millimeter, "secondCorner" : vector(10, 10) * millimeter });skSolve(sketch);
opRevolve(context, id + "revolve1", {
"entities" : qSketchRegion(id + "profileSketch"),
"axis" : line(vector(0, 0, 0) * meter, vector(0, 0, 1)), // Z axis
"angleForward" : 360 * degree
});
Avoid opHelix (known to produce obscure REGEN_ERRORs). Use opFitSpline + opSweep:
// 1. Sample helical points
var pts = [];
for (var i = 0; i < nPts; i += 1) {
const t = i / (nPts - 1);
const z = zStart + t * totalLen;
const theta = -2 * PI * turns * t; // negative for right-handed
pts = append(pts, vector(r * cos(theta), r * sin(theta), z) * meter);
}
opFitSpline(context, id + "helixPath", { "points" : pts });
// 2. Sketch thread profile on normal plane at start
var profile = newSketchOnPlane(context, id + "threadProfile", {
"sketchPlane" : plane(vector(0, 0, zStart) * meter, vector(0, -1, 0), vector(1, 0, 0))
});
skLineSegment(profile, "l1", { "start" : vector(r - depth, 0) * meter, "end" : vector(r, width/2) * meter });
skLineSegment(profile, "l2", { "start" : vector(r, width/2) * meter, "end" : vector(r, -width/2) * meter });
skLineSegment(profile, "l3", { "start" : vector(r, -width/2) * meter, "end" : vector(r - depth, 0) * meter });
skSolve(profile);
// 3. Sweep along fitted spline
opSweep(context, id + "threadSweep", {
"profiles" : qSketchRegion(id + "threadProfile"),
"path" : qCreatedBy(id + "helixPath", EntityType.EDGE)
});
// 4. Subtract from host body
opBoolean(context, id + "threadCut", {
"tools" : qCreatedBy(id + "threadSweep", EntityType.BODY),
"targets" : qCreatedBy(id + "hostBody", EntityType.BODY),
"operationType" : BooleanOperationType.SUBTRACTION
});
Call write_featurescript_feature from the MCP client:
{
"documentId": "<doc_id>",
"workspaceId": "<workspace_id>",
"elementId": "<part_studio_id>",
"feature_type": "myParametricPart",
"feature_name": "PGK Casing Assembly",
"feature_script": "<full FeatureScript code>",
"parameters": [
{"id": "outerDiameter", "type": "quantity", "value": "80 mm"},
{"id": "totalLength", "type": "quantity", "value": "220 mm"},
{"id": "wallThickness", "type": "quantity", "value": "4 mm"},
{"id": "isHollow", "type": "boolean", "value": true}
]
}
The server automatically creates the Feature Studio, uploads the source code, binds the namespace, applies the feature to your Part Studio, and returns the regen status and geometric diff.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub muditatrey/onshape-mcp-archive --plugin onshape-mcp3 skills in this plugin
/onshapeProtocols for driving Onshape CAD via the onshape-mcp plugin. Render-first and entity-first workflows, unit + coordinate conventions, iteration discipline, when to reach for FeatureScript, and the gotchas (REMOVE-on-face auto-flip, Variable Studios as separate elements, deterministic ID remapping). Load before building anything in Onshape — the plugin's MCP tool surface makes more sense with this doc in context./vision-decomposeLook at an engineering reference image (drawing, iso render, photo) and produce a structured feature decomposition BEFORE building anything in Onshape. Output is a feature tree the user can review and the build phase can execute against. Use this whenever the user gives you a reference image and asks you to model it. Skip if the user has already described the part in plain text.