Skip to content
AI-Ready Docs
/llms.txt/llms-mcp.txt

cad-mcp and cad-cli ​

The studio's tools also run outside the browser:

  • cad-mcp serves them to any MCP client, such as Claude Code or Claude Desktop, on a .bcad file of its own.
  • cad-cli runs scripts and checks from a shell.

Both use the same tool layer as the studio's chat, with the same gates and the same proposals, and the same tool contract (see Tools). Both work on local files only.

Register the local CAD MCP server (132 modeling, drawing, DFM & robot actions) in one command:

claude mcp add barocss-cad -- node apps/cad-studio/scripts/cad-mcp.mjs --doc ./part.bcad

cad-mcp: the tools over MCP ​

bash
node apps/cad-studio/scripts/cad-mcp.mjs --doc part.bcad [--autonomy 1|2|3|4] [--libraries dir]
  • --doc is the part the tools work on, a .bcad (or .json) file. A file that doesn't exist yet starts as an empty part and is written on the first change.
  • --autonomy works as in the studio: the default is 2. See Proposals and autonomy.
  • --libraries is a folder of team library files (.json) the library tools can insert from.

In an MCP client's configuration:

json
{ "command": "node", "args": ["<repo>/apps/cad-studio/scripts/cad-mcp.mjs", "--doc", "/absolute/path/part.bcad"] }
  • Talking to it. It speaks MCP over stdio, and stdout carries only the protocol. It builds itself from the TypeScript sources when it starts.
  • Saving. Each change is saved at once, and atomically: a temporary file is renamed over the part.
  • Proposals. They are kept in the file. Open it in the studio to preview and accept them.

A session from samples/agent-mcp.test.mjs:

mjs
// query.measure: a face by its name.
assert.deepEqual(await s.call('query', { action: 'measure', a: 'n1.top' }),
  { isError: false, label: 'Planar face', area: 2400 });

// A new feature at autonomy L2 (the default): refused, the part unchanged.
const hole = await s.call('features', { action: 'command', command: 'hole', faces: ['n1.top'], values: { d: 8, x: 30, y: 20 } });
assert.equal(hole.isError, true);
assert.equal(hole.code, 'needs_proposal');
assert.equal(hole.kept, 'the part is unchanged');

// A call the part can't answer: refused with the reason.
assert.deepEqual(await s.call('features', { action: 'delete', index: 9 }),
  { isError: true, ok: false, error: 'There is no feature 9 (features 0–1).' });

Read requirement evidence for a saved revision ​

Call the requirements tool with {"action":"evidence"} to read the base part. Pass part for an exact top-level occurrence ID. The checks use the selected part's local coordinates and apply its occurrence material overrides.

The response contains requirement-evidence.json with its byte count and SHA-256. The file keeps authored source and confirmation data separate from the check result and its freshness. Use the returned revision as expectedRevision in a later call to require the same authored inputs. A mismatch refuses the report. The evidence revision includes the full authored inputs except the document's proposal and design history logs. The report also gives the standard documentRevision. The file's SHA-256 verifies the report bytes. A current pass requires a matching evidence revision, an ok result with a pass verdict, and current freshness.

The local MCP server reads its document when the session starts. Start a fresh session on the saved file after Studio makes a change. Open proposals stay separate from the measurements in this report.

cad-cli: scripts and checks ​

bash
node apps/cad-studio/scripts/cad-cli.mjs <command> …

Or pnpm cli <command> … from apps/cad-studio. Commands print JSON results; help, usage errors and some failures are plain text. Read stdout, stderr and the exit code together. The exit codes:

CodeMeaning
0Done
1Refused or failed: the output says why
2A usage error
3A hard requirement fails (run --check, check)

Running a script ​

bash
cad-cli run <script | -> [-o part.bcad] [--doc base.bcad] [--step part.step] [--stl part.stl] [--check] [--dry-run]
  • What it runs. A model.run script, on base.bcad or an empty part. - reads the script from stdin.
  • What it writes. It writes what you ask for. --stl writes one file per body when there are several, and a .source.json record beside them.
  • Checks. --check runs the part's requirements.
  • Dry runs. --dry-run writes nothing.
  • Refusals. A line the tools refuse is reported as file:line:col, with the refusal.

--doc supplies the starting document; -o selects the document to write. Use a different output path to keep the input file. Outputs are written before --check reports a failed requirement, so exit 3 does not mean that nothing was written. A later export or write failure can also leave earlier output files in place.

Before retrying, read the refusal and inspect the output paths. Correct the input or options, then use a fresh output path if you need to preserve the first result. --dry-run checks the script without writing its outputs; it does not prove that a later file export will succeed.

From samples/cli.test.mjs:

mjs
  // plate.cad.js: a plate, and a hard requirement that it is 80 mm long.
  const script = `box({w: 80, d: 40, h: 8})
requirements([{id: "R1", source: "80 long", hard: true,
  check: {op: "==", query: {fn: "bbox", axis: "x"}, value: 80, tol: 0.1}}])`;
mjs
// cad-cli run plate.cad.js -o plate.bcad --step plate.step --check
const run = await cli(['run', join(dir, 'plate.cad.js'), '-o', join(dir, 'plate.bcad'), '--step', join(dir, 'plate.step'), '--check']);
assert.equal(run.code, 0);
assert.equal(run.json.checks.summary.hard_failing, 0);

// cad-cli check plate.bcad: the saved part's requirements again.
assert.equal((await cli(['check', join(dir, 'plate.bcad')])).code, 0);

// The same requirement on a 90 mm plate fails: exit 3.
const wide = await cli(['run', '-', '-o', join(dir, 'wide.bcad'), '--check'], script.replace('w: 80', 'w: 90'));
assert.equal(wide.code, 3);

// A line the tools refuse: exit 1, where it is, and nothing written.
const bad = await cli(['run', '-', '-o', join(dir, 'bad.bcad')], 'box({w: 5, d: 5, h: 5, q: 2})');
assert.equal(bad.code, 1);
assert.match(bad.err, /<stdin>:1:\d+: \[REFUSED\] Box has no value "q"/);

Create a rectangle with two driving lengths ​

The existing feature() call accepts a straight rectangle with two driving lengths on the default XY plane. The same node works with features.add over MCP. The native file keeps both lengths when you open the sketch in Studio.

js
const plate = feature({
  kind: "sketch",
  profile: "rectangle",
  min: [0, 0],
  max: [20, 10],
  outline: {
    points: [[0, 0], [20, 0], [20, 10], [0, 10]],
    lengths: { "0": 20, "1": 10 },
    hv: { h: [0, 2], v: [1, 3] }
  }
});
feature({ kind: "extrude", sketch: plate, height: 6 });

Give the four corners counter-clockwise from min. Edges 0 and 1 carry the width and depth in millimetres. The lengths must agree with the numeric bounds at the existing solver tolerance. Optional sideTags.outer contains four distinct side IDs of 1 to 32 letters, digits, underscores or hyphens. Names reserved for locked references, such as ref0, are refused. This input form covers one rectangle. Add a separate Hole feature for a cut.

The other commands ​

CommandWhat it doesExits 1 when
check part.bcadRuns a saved part's requirements (exit 3 when a hard one fails)It can't be read
replay part.bcadReads a saved part as the studio opens it, evaluates it afresh, prints its facts and requirement verdictsIt doesn't read
urdf part.bcad -o folder [--name robot]Writes the assembly as URDF (robot.urdf, meshes/*.stl), checked against the URDF specRefused
mjcf part.bcad -o folder [--name robot]Writes it as MuJoCo MJCF (robot.xml, meshes/*.stl), checkedRefused
robot-check part.bcad duty.jsonEvery margin of the robot against its duty: the actuators, the joints' ranges and ratings, the sweep, the model's consistencyA margin is 0 or less, or anything is unknown
robot-size part.bcad duty.json -o sized.bcadSizes the robot one change a round (an actuator, a rating or a slower profile) until every margin is above 0. Writes sized.bcad and sized.duty.json, and prints the traceIt stops: BRIEF_INFEASIBLE or NOT_CONVERGED
stock part.bcad -o folder [--list stock.json] [--allowance mm]The smallest block or bar on your stock list that a part is machined from (stock.json, stock.step)None is loaded, or none fits
nest part.bcad -o folder [--list lengths.json] [--kerf mm]Nests a frame's cut list into your stock lengths (nesting.json, nesting.csv)Refused, or a piece is left over
mould part.bcad -o folder [--margin mm]A moulded part's two halves, cut at a flat parting plane (mould.step, mould.json)It can't be built, with the code
pattern part.bcad -o folderA sand-cast part's pattern: the machining allowance and the shrinkage from your casting rules (pattern.step, pattern.json)It can't be made, with the code
mould-quote part.bcad -o package.zip [--quantity n]The injection-moulding quote package: STEP, the manufacturability report and the requestAnything is still open
cam-preview part.bcad -o folder [--tool mm]NOT FOR PRODUCTION: a 2.5D preview of the pockets' contours and the holes' drill points, as JSON and SVG. No G-code, feeds, speeds or collision checkRefused
bundle write part.bcad -o folder [--baseline id]The export bundle: the document, its approved BOM baseline, materials with sources, the analysis results with their freshness, and a manifest of digestsIt isn't complete
bundle verify folderReads a bundle back from its files alone and checks every digest and pinIt is incomplete, changed or stale

team and board run the scripted team and candidate-board scenarios. cad-cli help prints the full usage.

Review a pending worker candidate ​

For a local run named run with a pending task named base, export the review receipt. Pass that exact file to the renderer. Choose paths outside the run directory for the output files.

sh
node apps/cad-studio/scripts/cad-cli.mjs task-run review run base base.bcad-candidate
node apps/cad-studio/scripts/cad-cli.mjs task-run render-candidate run base --review base.bcad-candidate > views.json

On success, views.json contains four views of the proposed occurrence in its local coordinates, the face legend, and its verified dimensions and checks. Decode image.data as base64 and compare the SHA-256 of the PNG bytes with imageSha256. Match runId, taskId, attemptId and candidateDigest to the current review before displaying the result. Two attempts can produce identical geometry and PNG bytes.

A retired receipt produces a nonzero exit status. Read the current run status before requesting another review. The command leaves the accepted document and the approval decision intact. In Studio, open a pending candidate from the local run to request the same four views.

Using another agent ​

Any agent that speaks MCP can drive a part through cad-mcp:

  • What it reads. It gets the same 13 tools and the same refusals. describe gives the detail on request.
  • What waits for you. Changes that need your approval, or that go past its autonomy, wait in the file as proposals.
  • Rows. Rows an agent wrote itself are refused, as in the chat.

The tool list it reads is the one the studio's chat reads. There is no separate, older list.

Use the describe tool to discover an action's arguments, a modeling command's values or a feature kind's document fields before sending a change. This is tool discovery, not a separate cad-cli describe command. After an MCP failure, read its returned error and inspect the current document before retrying: earlier successful calls have already been saved.

barocss-cad: Headless CLI and Structured MCP ​

The @barocss/cad-cli workspace package also provides the barocss-cad standalone binary (pnpm barocss-cad or pnpm exec barocss-cad) for external coding agents and CI pipelines:

bash
barocss-cad check <file.bcad>
barocss-cad export <file.bcad> --format step|stl|glb|svg|dxf|pdf --out <path>
barocss-cad export-snapshot <file.bcad>
barocss-cad commands --schemas
barocss-cad mcp --structured [--doc <file.bcad>]
  • check <file.bcad> runs strict B-rep validity checks (checkOutput), drawing diagnostics, assembly solve and interference checks, and specification requirements (exit 0 ok, 1 refused/invalid, 2 usage, 3 hard requirement failure).
  • export <file.bcad> --format <fmt> --out <path> deterministically exports step, stl, glb, svg, dxf, or pdf.
  • export-snapshot <file.bcad> outputs a deterministic typed JSON snapshot per body (volumeMm3, surfaceAreaMm2, exact enclosing B-rep bboxMm, topology.counts, eulerGenus, sha256, refusals, and snapshotSha256).
  • commands --schemas emits machine-readable JSON Schemas across modeling, assembly, inspection, and MCP commands.
  • mcp --structured runs a stdio JSON-RPC 2.0 MCP server (initialize, tools/list, tools/call) exposing document lifecycle (doc_create, doc_open, doc_save with Safe Save round-trip validation), parametric modeling (feature_add, feature_modify, parameter_set), validation/inspection (check, export_snapshot, commands_schemas, render_preview, compare_picture silhouette diff with provenance/overrides and tight-alpha preservation), replayable timeline script export, and CAD I/O (export_step, import_step, export_stl, export_asset) with typed inputSchema/outputSchema, expectedRevision enforcement across all feature_add forms, session preservation on failed doc_create/doc_open, and deterministic refusals.