Execute Python code
execute_codeRun sandboxed Python against the OpenSTAAD API to automate STAAD.Pro tasks, extract model data, or set properties, with optional CSV/Excel input and output.
Instructions
Execute Python code in a sandbox against the OpenSTAAD API (don't forget to call discover_api and read_skills for API guidance).
The sandbox provides pre-connected staad (the OpenSTAAD root object) and input_data (if input_data_path is provided) variables (plus json
and math modules). import statements, dir(), getattr(), ... are BLOCKED.
The last expression value or an explicit result = ... assignment is returned as the result.
If output_data_path is provided, the sandbox will write the result to the specified file.
Paths must be on the user LOCAL filesystem and inside MCP roots or configured allowed_dirs.
On Claude Desktop, users can configure allowed directories in the extension settings and Claude can use the filesystem copy_file_to_claude
tool to move files to Claude's filesystem.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source code to execute. Use the pre-injected ``staad`` variable to interact with the API. (don't forget to call discover_api and read_skills for API guidance) | |
| instance | No | Alias (from ``list_instances``, e.g. ``staadPro1``) of the STAAD instance to target. If omitted, last opened instance is selected. | |
| overwrite | No | Allow overwriting an existing output file. | |
| input_data_path | No | Path on user LOCAL filesystem to a ``.csv`` or ``.xlsx`` file. Its content is parsed and injected as ``input_data`` inside the sandbox. Use this to feed large datasets (e.g. node loads, section properties) into your code without hardcoding them. The shape is determined by the extension: - CSV -> list of row lists. When a header is detected, it is the first row: columns = input_data[0] for row in input_data[1:]: print(row) - XLSX -> dict mapping every sheet to ``columns`` and ``rows`` lists: sheet = input_data["Sheet1"] columns = sheet["columns"] for row in sheet["rows"]: print(row) The containers are mutable for normal Python compatibility, but are fresh for each execution; mutations do not change the source file or persist across executions. | |
| output_data_path | No | Path on user LOCAL filesystem to a ``.csv`` or ``.xlsx`` file where to write the ``result`` value. Use this to avoid flooding the context window with large amount of data. **Units rule:** every column holding a physical quantity MUST carry its unit inside the header cell as ``Name [unit]`` (e.g. ``"Fx [kN]"``, ``"UY [mm]"``). Never emit a separate units row — the first row is the header and any row below it is data, so a units row is read back as a record and turns the whole column into text. Take the unit string from ``Output.GetOutputUnitFor*`` and convert the value into it first (every result getter returns base units). Leave ID/count/dimensionless columns unbracketed. Keep file headers plain single-line text — no ``<br>`` or newlines (that variant is for chat tables only). Put model-level context (model name, base unit system, load cases, date) on a separate ``"Info"`` sheet, never as banner rows above the header. The ``result`` variable must be formatted as one of: - List-of-lists → written as CSV or single-sheet xlsx: result = [["Node ID", "X [m]", "Y [m]", "Z [m]"], [1, 0.0, 0.0, 0.0], ...] - Dict of sheet dicts → written as multi-sheet xlsx: result = { "Nodes": {"columns": ["Node ID", "X [m]", "Y [m]", "Z [m]"], "rows": [[1, 0.0, 0.0, 0.0], ...]}, "Reactions": {"columns": ["Node ID", "Load Case", "FX [kN]", "MZ [kN-m]"], "rows": [[1, 1, 12.5, 3.2], ...]} } |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||