execute_code_headless
Run FreeCAD Python scripts in an isolated headless process for crash-prone OCCT operations, so GUI documents survive while output and crash diagnostics are returned.
Instructions
Run a FreeCAD Python script in a separate headless freecadcmd process.
Use this for OCCT work that can crash or block FreeCAD: helical threads (makeHelix + makePipeShell), lofts and sweeps, booleans with many or B-spline tools, long parametric rebuilds. A native OpenCascade crash here only kills the helper process; the GUI and its open documents survive, and the tool reports the crash signal and the script's output.
The script runs on the MCP server machine, independently of --host, in a fresh process without GUI: import FreeCAD/Part yourself, open documents from disk (FreeCAD.openDocument(path)), save results with doc.save()/saveAs() or Shape.exportBrep(). Nothing from the execute_code namespace is available. Print progress to stdout; it is returned when the process ends. After the script saved a .FCStd that is open in the GUI, call reload_document(doc_name) to show the result.
Args: code: Complete Python script for freecadcmd. timeout: Positive finite seconds to wait before killing the process (default 600). Partial output is preserved on timeout.
Returns: Exit status, crash/timeout diagnosis and the script's printed output.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute_code_headless"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| timeout | No |