The strukts CLI: more verbs, serve and mcp¶
Audience: build engineers · about 5 minutes · Prerequisites: The strukts CLI
explain¶
Answers "why is this value what it is?" for a language that evaluates synchronously (KernelF today): strukts explain --project-dir <dir> --name z.
It runs each root with a trace and prints the declaration, its value, and the steps it was computed from, in the language's own syntax:
val z = double(y) => 84
double(y) => 84
double => <function>
y => 42
n * 2 => 84
n => 42
2 => 2
--name <declaration> explains that one declaration in full depth; without it every top-level declaration is listed with its value only.
--depth <n> limits how many levels of steps are kept (a cut is shown as … n more), and --format text prints these lines instead of JSON
(the JSON has the same information as a tree, plus the node ids of the run). A failed step shows !! and its message instead of a value.
A language that cannot run synchronously (Python-grammar Core, for example) is reported as unsupported, exit 0; an unknown --name exits 2.
It needs exactly one project and writes nothing. A conditional says which way it went and a decision table which row decided, as
[via else] or [via row 2] after the value:
val tariff = fee(30, true) => 9
fee(30, true) => 9
…
Table rows => 9 [via row 2]
A language reports this by naming the branch it took (ctx.branch("row 2") in its evaluation rule); a concept that does not simply shows no via.
migrate¶
Brings model files up to their language's current version, using the language's recorded migration history (structural
steps and scripted transform steps; see Migrating a language).
strukts migrate --project-dir <dir> only reports: for each root file the version it was saved at (from), the language's
version (to) and a status: current, pending, refused (saved by a newer version of the language than the one
installed), failed (a step threw) or skipped (a syntax error). --check makes any pending root exit 6, for a CI gate.
--write rewrites the pending files and stamps the new # langversion:. --from <n> assumes version n for a file that
records none (no # langversion: header; a headerless grammar without a langVersion in model.json), which is otherwise
taken to be version 1; a recorded version always wins.
strukts migrate --project-dir ./my-project --trust-project-code --write
A model is rewritten only when all of its roots migrated, a file with a syntax error is left alone, and each file is
written whole or not at all. --write needs --project-dir (a shipped sample is never rewritten) and cannot be combined
with --check. A project's own language is arbitrary JavaScript, so --trust-project-code applies as for every verb. Exit
6 when anything is refused or failed, or with --check when something is pending.
script¶
Runs a project script with the workbench API against a project, headless:
strukts script scripts/tidy.script.js --project-dir ./my-project --trust-project-code. Put the file name first; it is relative to the
project folder. The script is the body of an async function with workbench, args (from --args '<json>'), log and cancelled().
The result is JSON: the script's returned value, its logs, the files it wrote, the models it changed but did not save
(unsaved), and the audit log of what it did. A script that throws exits 7 with the error in the JSON.
A script is arbitrary JavaScript, so --trust-project-code is required, exactly as for a project's own language file. A script is not sandboxed: it runs inside the CLI's own process with your privileges, so --trust-project-code is the real boundary. A trusted script can import Node's own modules and write any file or start any program, whatever --write and --shell say. Those two flags gate only the workbench API's fs, project.save() and shell; they keep a script that uses the API honest and tell you what to expect, they do not contain it.
Through the workbench API a script can, by default, read and query the project and edit models in memory, and nothing reaches disk. You open up the API's own paths, one flag each:
| Flag | Lets the script | Limit |
|---|---|---|
--write |
call workbench.project.save() and workbench.fs.write/mkdir/remove |
the API refuses a path that leaves --project-dir (also through a symlink) and never writes a shipped project; a script that bypasses the API is not held to that |
--shell |
call workbench.shell.run(command, args) |
argument list only (no shell expansion), working directory inside the project, 60 s default timeout |
--answer 'label=value' |
get an answer for workbench.prompts.ask/confirm/choose("label") |
repeat per prompt; a prompt with no answer fails the script instead of waiting for input |
--model <name> |
choose which model is workbench.model.active() |
default: the first model |
A language can offer a script as a task step with { verb: "script", args: ["scripts/tidy.script.js", "--write"] }.
tasks and task¶
A language can declare named tasks (a chain of verbs and external commands; see Tasks and the project terminal).
strukts tasks --project-dir <dir> lists the ones the project's languages declare, as JSON. strukts task <name> --project-dir <dir>
runs one: each step in order, stopping at the first failure and exiting with that step's code (127 if an external command
cannot be started). An unknown name exits 2 and lists the declared ones.
tree¶
Prints a project's structure as JSON, for a tool that browses it: strukts tree --project-dir <dir>. It lists each model (its label,
folder and language) and each root file in it with the display name the IDE shows, plus a top-level outline per root. Every outline entry
carries its head (the kind of statement), a label and a location (line and column, counted from 1, like a check finding), so a tool can
jump to it. It needs exactly one project (--project or --project-dir); --all exits 2.
dap¶
strukts dap [--trust-project-code] starts a Debug Adapter Protocol server on standard input and output, so VS Code's own debugger
can step a model's program over the evaluator. Standard output is the protocol channel, so nothing else is printed there. An editor integration normally launches it.
Preview
mcp (the AI tools) and serve are preview features in this first release.
serve¶
strukts serve --project-dir <dir> [--port <n>] [--token-env <NAME>] keeps a project in memory and offers the commands its languages
contribute (Concept#contributes().commands) as JSON over HTTP, so a web application can keep its own user interface and let struktJS do
the modelling, the checks and the storing. A request is POST /v1/command with {"command": "octo.saveCheckin", "args": {...}}; the
command answers {status, body} (the status and JSON to relay) and a command that saves writes the project's files. GET /v1/commands lists the
commands, GET /v1/health answers when it is up and POST /v1/reload rereads the folder after you edited it elsewhere.
It is for a developer's machine or a private network, and strict about it: it listens on 127.0.0.1 only (the Host header must match), every request needs Authorization: Bearer <token> from the environment variable (default STRUKTS_SERVE_TOKEN, at least 16 characters; it refuses to start without one), a request is JSON of at most 2 MB, one request runs at a time, and only commands a language registered can be called, never the application's own commands or script text from a request. It needs --project-dir (a shipped sample is not served: it saves). The worked example is the Octo web app, whose API route relays to the octo.* commands of the Octo language.
mcp¶
Starts a Model Context Protocol server on standard input and output, so an AI agent in an MCP client can read a project the way the IDE's own AI chat does; it is the headless counterpart of the chat agent's read tools, computed by the same code as the verbs above. The target is optional and only sets the default for calls that name no
project: strukts mcp --project-dir ./my-project.
| Tool | Returns |
|---|---|
strukts_list_projects |
the shipped projects (use an id as project) |
strukts_get_model |
each model's language and roots, every root's source text and a located outline (includeSource: false for the outline only) |
strukts_get_concepts |
the concepts the project's language supports, as text or format: "json" |
strukts_get_checks |
the checker's findings, each with severity, message, rule code, file and line/column |
strukts_run_generator |
the generated text per root, in the response (nothing is written) |
strukts_run_program |
runs each root like the IDE's Run: what it printed, its final value, any error |
strukts_run_tests |
pass/fail per test |
strukts_verify |
check, tests and generator dry run in one report |
Every tool takes project (a shipped id) or projectDir (a folder on disk). The project is reloaded on every call, so an agent can edit the model files itself and call strukts_get_checks again. Findings are identified by file and location, never by node id.
By default the server is read-only: there is no tool that edits a model, and the headless host rejects every write. Start it with
--write and it gains one more tool, strukts_run_script: it runs a script (JavaScript text from the agent) against the project with the
workbench API. Edits stay in memory and are reported as unsaved unless the call also passes write: true (a real projectDir only)
and the script saves. workbench.shell is not offered over MCP, but that is the API's rule only: a script is JavaScript running in the server's own process, so strukts mcp --write gives the agent code execution with your privileges (it can import Node's modules and write files or start programs directly). Start it only for an agent and a project you trust, with --trust-project-code understood the same way. Anything else is still the client's own file tools. The IDE chat agent's
apply_code and node operations act on a live editor and are not offered. strukts_run_program executes the model as Run does, with no sandbox beyond the evaluator's own: input() always answers an empty string (nobody to ask), output is capped at 1000 lines, and a run is cancelled after timeoutMs (default 30 seconds; cooperative, like test --timeout) and stops with a RecursionError past maxCallDepth nested calls (default 1000). A failing call comes back as a tool result flagged isError; a project with its own *.lang.js is refused unless the server was started with --trust-project-code. Progress goes to standard error; standard output carries only the protocol, so don't wrap the command in anything that prints to it.
To register it, give the MCP client the command node dist/strukts-cli/strukts.mjs mcp --project-dir ./my-project (or,
from a checkout, npm run --silent strukts -- mcp: without --silent npm prints a banner to standard output, which breaks the protocol).