Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 initialize explaining the workflow, verdicts, and frame conditions.

  • Embedded MCP resources (resources/list and resources/read):

    • skill://elinvar/SKILL.md: the full agent guide and supported Alloy 6 subset.
    • elinvar://schema/<name>-v1.json: the thirteen versioned JSON Schemas of elinvar explain schema: result, results, diff, import, render, eval, tests, accepts, fuzz, discover, ci, audit, and usage.
  • Eleven stateless tools (tools/list and tools/call):

    • check: check assertions (supports explain: true for minimal unsat cores).
    • run: find an example instance of a predicate.
    • diff: compare old_model and new_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 as dot, mermaid, or sql.
    • 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>, or skill.

    check, run, eval, and accepts take SQL DDL as model with is_sql: true, and the command line’s --with sidecars as promises (Alloy) and views (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:

  1. The agent can teach itself in one command from the embedded guide:
    elinvar explain skill
    
    (Or copy skills/elinvar/SKILL.md into your project’s agent skills folder.)
  2. The agent checks designs in one stateless command using stdin (-) and --json:
    elinvar check - --json <<'EOF'
    sig User { roles: set Role }
    sig Role {}
    ...
    EOF
    
  3. Every response is structured JSON with stable exit codes (0 holds/found, 1 counterexample/diff, 2 vacuous/unknown, 3 error with code, place, and fix).

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.sql with elinvar import and check whether an order can be marked shipped without a valid payment.”
  • “Compare our old and new state transition rules with elinvar diff and 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 treat vacuous as a pass).
  • On unknown: raise --budget or simplify the scope.