Using Elinvar with AI coding agents
Elinvar is designed so coding agents (Claude Code, Codex, Cursor, Windsurf, or custom
agent loops) can verify a design before writing code. Agents can use Elinvar either
through the CLI or through MCP. Both return the same JSON; MCP offers every verb but
fuzz, which runs a database command, and ci, which reads files from disk.
Option A: Connect via MCP (elinvar serve --mcp)
Install the binary once:
cargo install elinvar
(Or from a local checkout: cargo install --path crates/elinvar. A tagged release
also has binary archives on the
releases page.)
Add Elinvar to your MCP client configuration (Claude Code, Claude Desktop, Cursor, etc.):
{
"mcpServers": {
"elinvar": {
"command": "elinvar",
"args": ["serve", "--mcp"]
}
}
}
When an MCP client connects to elinvar serve --mcp, it automatically receives:
-
Server instructions on
initializeexplaining the workflow, verdicts, and frame conditions. -
Embedded MCP resources (
resources/listandresources/read):skill://elinvar/SKILL.md: the full agent guide and supported Alloy 6 subset.elinvar://schema/<name>-v1.json: the thirteen versioned JSON Schemas ofelinvar explain schema:result,results,diff,import,render,eval,tests,accepts,fuzz,discover,ci,audit, andusage.
-
Eleven stateless tools (
tools/listandtools/call):check: check assertions (supportsexplain: truefor minimal unsat cores).run: find an example instance of a predicate.diff: compareold_modelandnew_model, or a function between them (of).import_sql: turn SQL DDL into a starter Alloy 6 model.render: render a result’s instance or trace asdot,mermaid, orsql.eval: evaluate an expression on a result at any state without re-solving.tests: generate step reachability and refusal tests.accepts: check whether a trace or SQL DML script is allowed.discover: find and prove invariants of a SQL schema.audit: check a SQL dump’s rows against a schema without the solver.explain: explain an error code,schema/schema:<name>, orskill.
check,run,eval, andacceptstake SQL DDL asmodelwithis_sql: true, and the command line’s--withsidecars aspromises(Alloy) andviews(SQL). An argument a tool does not list is refused with the list of those it takes.
Option B: Use the CLI directly (shell-capable agents)
If your agent already has shell access, it does not even need MCP configured. As long as
elinvar is on PATH:
- The agent can teach itself in one command from the embedded guide:
(Or copy skills/elinvar/SKILL.md into your project’s agent skills folder.)elinvar explain skill - The agent checks designs in one stateless command using stdin (
-) and--json:elinvar check - --json <<'EOF' sig User { roles: set Role } sig Role {} ... EOF - Every response is structured JSON with stable exit codes (
0holds/found,1counterexample/diff,2vacuous/unknown,3error withcode,place, andfix).
Good prompts to give an agent
You do not need to write Alloy yourself. Ask your coding agent things like:
- “Before implementing the permissions table and revocation endpoint, model the rules in Elinvar and check whether a revoked user can still edit a document.”
- “Import
migrations/001_init.sqlwithelinvar importand check whether an order can be marked shipped without a valid payment.” - “Compare our old and new state transition rules with
elinvar diffand show me any behavior change.”
What an agent should report back
- On
counterexample: the concrete steps or links that break the promise, and how to change the design to close the hole. - On
holds: always include the scope searched (for example, “holds up to 4 users, 4 documents, and 6 steps”), since bounded checking is strong evidence rather than an unbounded proof. - On
vacuous: stop and fix the contradictory rules (never treatvacuousas a pass). - On
unknown: raise--budgetor simplify the scope.