# ontology.run > Evaluate declarative compliance policy into an explainable plan (`because` provenance) over versioned JSON Schema entities. > Execute multi-party form signing, external connector checks, and cross-case credential reuse in one Effect 4 + Postgres 17 runtime. > Export an Ed25519 hash-chained audit bundle verifiable offline (`pnpm verify-audit`) — exposed identically over REST, Effect RPC, and MCP. ## Quick Discovery - Interactive Walkthrough: `/walkthrough` - Operator Console UI: `/console` - Model Context Protocol (MCP): `POST /mcp?profile=core` (curated compliance loop) or `POST /mcp` (full toolset / `--mcp-stdio`) - OpenAPI 3.1 spec: `GET /openapi.json` (interactive Swagger UI: `GET /docs`) - OpenRPC 1.3.2 spec: `GET /openrpc.json` (Effect RPC endpoint: `POST /rpc`) - Browser Policy Studio (no sign-in required): `/policy-studio` - Health probes: `GET /healthz`, `GET /readyz` ## 2-Minute Core Compliance Loop Run the core compliance loop end to end (in a sandbox or local `pnpm demo:serve`): 1. **Apply a Vertical Pack:** - REST: `POST /orchestrator/packs/apply` · RPC: `packs.apply` (or `POST /sandbox/seed` in a playground sandbox). - Loads entity types, form templates, policy sets, domain actions, and connector definitions in one step. 2. **Execute a Domain Action:** - `POST /domain/actions/` (or the matching `action_` tool on `POST /domain/mcp`). - Atomically upserts linked entities and starts the compliance case with zero manual fact wiring. 3. **Inspect the explainable `because` plan:** - `GET /orchestrator/cases/:id` (or dry-run `POST /domain/actions/?dry_run=true`). - Every required item carries structured `because` provenance explaining which rule and entity facts triggered it. 4. **Mint a party link & satisfy external connector checks:** - Mint a signing link for form requirements (`POST /documents/:id/roles/:role/links`) and complete multi-party form submission. - Invoke pluggable connectors (`POST /orchestrator/connections/:key/actions/:action`, e.g. Checkr `createReport`) and satisfy check items (`POST /orchestrator/cases/:id/items/:requirement/satisfy`). 5. **Export & offline-verify the Ed25519 audit bundle:** - `GET /orchestrator/cases/:id/bundle` (also `GET /documents/:id/audit`, `GET /orchestrator/entities/:id/audit`, `GET /orchestrator/entities/:id/history`). - Verify offline with zero network calls: `pnpm verify-audit `. 6. **Run a second case & observe cross-case reuse:** - Execute the action for a second target/jurisdiction on the same subject: valid shared credentials are automatically satisfied via cross-case reuse while only delta requirements are newly planned. ### Connecting an AI Agent via MCP (`?profile=core`) Start with `?profile=core` so the agent gets a focused compliance-loop toolset without context bloat: ```json { "mcpServers": { "ontology-run": { "url": "http://127.0.0.1:3100/mcp?profile=core", "headers": { "Authorization": "Bearer " } } } } ``` Optional MCP toolset profiles on `POST /mcp?profile=` (and `/service/mcp?profile=`): - `core` (recommended for agents): essential compliance-loop tools (entities, cases, audit trail, `plan_operations`, `apply_plan`, `list_skills`, `get_skill`). - `authoring`: Forma REPL, IR pack tools, template schemas, policy preview, `plan_operations`, `apply_plan`, `list_skills`, `get_skill`. - `all` (default): full toolset. Load deeper documentation on demand over MCP without bloating initial context: call `list_skills` and `get_skill` (or `resources/list` + `resources/read` for `ontology://skills/`) for `overview`, `compliance-loop`, `forma-dsl`, `policy-sets`, `packs-and-domain-mcp`, and `plan-and-safety`. ## Authentication, Tenancy & Transactional Plan/Apply All three transports (REST, RPC, MCP) share `CurrentActor` authentication and Postgres Row Level Security (`CurrentTenant`): - Header: `Authorization: Bearer ` - Mutation and create endpoints accept an optional `Idempotency-Key` header (1–255 visible ASCII characters, 24h TTL, scoped to the authenticated principal): retrying with the same key and payload replays the original response; reusing a key with a different payload returns `409 Conflict`. - Operator console routes also accept the `dw_operator` session cookie (with CSRF same-origin enforcement on mutations). - Common scopes: - `cases:read`, `cases:write` - `policies:read`, `policies:write` - `documents:read`, `documents:write`, `documents:void`, `read:sensitive` - `templates:read`, `templates:write` - `webhooks:manage` - `role:` (for system/agent roles submitting form values) - Every error returns RFC 7807 `application/problem+json` (`{ type, title, status, detail, errors? }`). ### Transactional Plan & Apply Preview and atomically commit multi-step compliance mutations (`entity.upsert`, `action.execute`, `case.create_for_entity`, `case.satisfy_item`, `policy_set.publish`): 1. **Plan (pure dry-run, rolled back via Postgres savepoint):** - REST: `POST /orchestrator/plan` · MCP: `plan_operations` - Returns `{ plan_hash, expires_at, operations_count, effects }` with zero committed writes. Operations may bind `ref` and reference earlier IDs via `"$ref:"`. 2. **Apply (single atomic Postgres transaction):** - REST: `POST /orchestrator/plan/:planHash/apply` · MCP: `apply_plan` - Executes all planned operations all-or-nothing, emits one audit event per operation, and rejects replays with `409`. ## Advanced Authoring (Packs, IR & Forma Lisp REPL) ### Pack Authoring Playbook (MCP / IR Loop) Author `format: 1` vertical packs (entity types, templates, concepts, bindings, policies, and scenarios) using the authoring MCP tools (`POST /mcp?profile=authoring`, requires `policies:read`): 1. **Read the schema:** Call `ir_schema` to fetch `schemas/pack.json` and a minimal valid `format: 1` example pack. 2. **Write the pack:** Author the complete pack JSON (`format: 1`, `kind: "library" | "binding"`, `requires`, `concepts`/`bindings`, `policies`, `scenarios`). 3. **Check until clean:** Call `ir_check` with your pack (and any `installed` dependencies). Fix every structured `Diagnostic` (`code`, `severity`, `path`, `message`, `suggest`) until `error_count === 0`. 4. **Test until green:** Call `ir_test` to run the pack's `scenarios` and iterate until all scenarios pass. 5. **Review impact:** Call `ir_impact` to dry-run the pack in a rolled-back transaction (zero persisted writes) and inspect section counts and live-case policy impact. 6. **Propose:** Submit the checked, tested pack via `ir_propose` (and poll `ir_release_status`) for human review. **No MCP tool can accept or publish a release** — a human (or authorized non-agent actor) must accept it. ### Incremental Forma Lisp REPL Workflow (MCP) Use the **Postgres-persisted Forma Lisp REPL** tools (persisted per tenant across stateless serverless requests via `forma_repl_sessions`; requires `policies:read`, zero writes to live domain/policy tables) when authoring or editing packs incrementally: 1. **`forma_load`:** Start or load a named session (`session_id`) from existing `VerticalPack` JSON or Forma Lisp `source`. 2. **`forma_eval`:** Append or replace top-level Forma forms (`pack`, `concept`, `binding`, `entity`, `template`, `policy-set`, `scenario`) one at a time. Compilation errors preserve the previous valid buffer and return structured `Diagnostic[]` so you can self-correct. Optionally pass `source` for a one-shot stateless call without a prior `forma_load`. 3. **`forma_print`:** Export the current canonical Forma Lisp source, compiled `pack` JSON, and `content_hash` (also accepts optional one-shot `source`). Call `forma_reset` to clear the session. 4. **Validate & propose:** Pass the printed `pack` to `ir_check`, `ir_test`, and `ir_impact`, then submit via `ir_propose` for human-gated release acceptance. ## REST & Effect RPC Reference 1. **Apply a Vertical Pack:** `POST /orchestrator/packs/apply` (`packs.apply`) — bundled packs include `packs/example-travel-nursing/pack.json`, `packs/healthcare-staffing.json`, and `packs/vendor-onboarding.json`. 2. **Register an Entity Type (versioned JSON Schema with optional `x-ref` links):** `POST /orchestrator/entity-types` (`entityTypes.register`). 3. **Upsert an Entity (auto-replans active cases when facts change):** `POST /orchestrator/entities` (`entities.upsert`). 4. **Publish & Roll Out a Policy Set:** `POST /orchestrator/policy-sets` (`policies.publish`), dry-run `POST /orchestrator/policy-sets/:key/versions/:version/evaluate` (`policies.evaluate`), fleet blast-radius preview `POST /orchestrator/policies/impact`, durable chunked rollouts `POST /orchestrator/rollouts` (`rollouts.create`, `rollouts.pause`, `rollouts.resume`, `rollouts.cancel`). 5. **Create & Update an Entity-Backed Case:** - REST: `POST /orchestrator/entities/:id/cases` (or `POST /orchestrator/cases` with `entity_id` in the body) - RPC: `cases.createForEntity` with payload `{ "entity_id": "ent_...", "policy_set": { "key": "...", "version"?: "..." }, "facts"?: {...}, "subject"?: {...}, "entity_refs"?: {...}, "materialization"?: "eager" | "lazy" }` (uses `entity_id`, not `id`; or `cases.create` with optional `entity_id`) - Update facts: `PUT /orchestrator/cases/:id/facts` (`cases.updateFacts` with `{ "id": "case_...", "facts": {...} }`) - Satisfy a check/attestation item: `POST /orchestrator/cases/:id/items/:requirement/satisfy` (`cases.satisfyItem`) 6. **Inspect & Invoke Pluggable Connectors:** - List registered connector schemas: `GET /orchestrator/connectors/catalog` (`connectors.catalog`) - Configure tenant connection (AEAD-encrypted credentials): `POST /orchestrator/connections` (`connections.upsert`) - Invoke a connector action (e.g. Checkr `createReport`): `POST /orchestrator/connections/:key/actions/:action` (`connectors.invoke`) ### Effect RPC Wire Format (`POST /rpc`) `POST /rpc` accepts Effect 4's JSON RPC envelope (`Content-Type: application/json`): ```json { "_tag": "Request", "id": "1", "tag": "cases.list", "payload": { "status": "active" }, "headers": [] } ``` For `Schema.Void` procedures (`policies.list`, `connections.list`, `permissions.list`, `views.list`, `connectors.catalog`), pass `"payload": null`. Inspect `GET /openrpc.json` for the exact parameter names and schemas of every procedure (for example, entity-scoped `cases.createForEntity` expects `entity_id`, not `id`). Payload schema errors return a typed `Fail` with an RFC 7807 `Problem` (`status: 400`, `errors[]` field paths). Use `@dw/sdk` (`createClient` for REST, `createRpcClient` for zero-Effect RPC) or `RpcClient.make(DwRpc)` for Effect callers. ## Local Quickstart & Benchmarks - `pnpm install && pnpm demo` — 5-second end-to-end Form I-9 + offline audit verification on embedded PGlite - `pnpm demo:serve` — Starts interactive service + console + MCP endpoint on `http://127.0.0.1:3100` - `pnpm bench` — Postgres 17 scale benchmark (GIN views, `entity_links`, chunked rollouts, lazy PDFs) - `pnpm sdk:generate` / `pnpm sdk:check` — Auto-generate zero-Effect SDK types from `@dw/api`