Listed from the MCP registry; nobody on Odel publishes it.
Twins for Postgres and REST: declared-subset Postgres, spec-defined REST, migration proof.
Runs on your machine from its package; the steps are below.
At most: moves money, runs code or commands, deletes data, or sends messages for you.
Odel charges nothing per call. The publisher may charge for its own service.
Runs locally over stdio
This server isn't hosted — your MCP client launches it from a package registry. Use one of the commands below, or drop the config into your client (e.g. Claude Desktop).
Run
npx -y @cmdrvl/twinning-mcp
MCP client config
{
"mcpServers": {
"postgres-and-rest-twins": {
"command": "npx",
"args": [
"-y",
"@cmdrvl/twinning-mcp"
]
}
}
}Twinning gives your code and your agents a stand-in for a database or an API that tells them why a request was refused. Point it at a Postgres schema or an OpenAPI spec and it serves a local twin. Your client connects with its normal driver, a write that breaks a constraint comes back with the real SQLSTATE and a reason, and a report records what happened. Use it to rehearse extraction code and pipelines before they touch a real database, to check a migration by replaying queries against old and new snapshots, and to test API clients against a spec-defined contract. Anything outside the declared contract is refused with a reason instead of guessed.
Paste this prompt into your coding agent (Claude Code, Cursor, Codex, or any agent that can run shell commands) to install the twinning MCP server on your machine. It downloads the prebuilt release, verifies its checksum, and configures your MCP client. It works on macOS and Linux. The Windows archive does not include the MCP server yet.
Set up the twinning MCP server on this machine. Work through the steps in order,
run each command yourself, and tell me what you did and what you saw. Do not use
sudo, and do not change any MCP server entry other than "twins".
1. Detect my OS and CPU. Supported targets are aarch64-apple-darwin,
x86_64-apple-darwin, x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu.
If this is Windows, stop and tell me the MCP server is not available there yet.
2. Find the latest release tag of https://github.com/cmdrvl/twinning (for example
by following the redirect from https://github.com/cmdrvl/twinning/releases/latest).
The archive is named twinning-<tag>-<target>.tar.gz and the checksums file is
named SHA256SUMS, both under https://github.com/cmdrvl/twinning/releases/download/<tag>/.
3. Create a new, empty directory ~/.local/share/twinning/<tag> and download the
archive and SHA256SUMS into it with curl -fL (not a browser). Verify the archive
against its line in SHA256SUMS (shasum -a 256 -c, or sha256sum -c on Linux).
If the checksum does not match, stop and tell me. Do not extract it.
4. Extract the archive into that directory. It must contain two executables,
twinning and twinning-mcp. Remember their absolute paths.
5. Run "<dir>/twinning-mcp doctor". It must print "health: ok (healthy (READY))".
If macOS refuses to run the binaries, run
"xattr -d com.apple.quarantine <dir>/twinning <dir>/twinning-mcp" and retry.
6. Ask me which project directory twins should work in (default: the current
directory) and which MCP client I use. Then configure it:
- Claude Desktop: "<dir>/twinning-mcp --workdir <project> setup --client claude-desktop"
- Cursor: "<dir>/twinning-mcp --workdir <project> setup --client cursor"
- Claude Code: "claude mcp add twins -- <dir>/twinning-mcp --workdir <project>"
- Anything else: run "<dir>/twinning-mcp --workdir <project> setup --client claude-desktop --print"
and add that "twins" entry to my client's MCP configuration by hand.
Tell me if I need to restart or reload the client.
7. Check it works without the client: write a file schema.sql in the project
directory containing
CREATE TABLE deals (deal_id TEXT PRIMARY KEY, deal_name TEXT NOT NULL);
then start the server with "<dir>/twinning-mcp --workdir <project>" and, over
MCP stdio, call twin_doctor, then twin_start with kind "postgres" and
schema_path "schema.sql", then twin_stop with the returned twin_id. Report the
result of each call. Stop the server when done.
If any step fails, stop and show me the exact command and its full output.
Twinning is built by CMD+RVL. If you work with filings or structured finance data and want a sourced answer, you can chat with Cairn, our research assistant, over text at textcairn.com.
Twinning is not a general database. The MCP manager ships postgres and rest
twin kinds only. It does not ship an MCP twin kind. MCP stdio is the manager's
control interface. Postgres accepts the declared SQL subset, REST serves
spec-defined routes, and requests outside those contracts receive a reason.
| Use case | Recorded demo |
|---|---|
| Extractor and pipeline development: rehearse writes against a schema contract and read which constraints were violated. | psycopg2 demo steps, run script, client compatibility results |
| Migration proof: replay a query set against legacy and candidate Postgres snapshots and inspect which results diverge. | recorded proof results, migration demo |
| API contract testing: exercise an OpenAPI REST twin with authentication and schema refusals. | REST compatibility results, REST demo |
Build both executables from source:
cargo build --locked --release -p twinning -p twinning-mcp
On a first run with empty caches, Cargo needs network access to download the
locked Rust dependencies. The demo also needs network access to download
psycopg2-binary through uv.
Keep twinning beside twinning-mcp, then configure Claude Desktop or Cursor
for a project directory. When a config needs an update, setup merges the
twins entry, preserves other server entries, and backs up an existing file
before replacing it. --print shows the snippet without writing a file.
./target/release/twinning-mcp --workdir "$PWD" setup --client claude-desktop
./target/release/twinning-mcp --workdir "$PWD" setup --client cursor
./target/release/twinning-mcp --workdir "$PWD" setup --client claude-desktop --print
The generated client entry has this shape. setup fills in the absolute
executable and workdir paths.
Claude Desktop:
{
"mcpServers": {
"twins": {
"command": "/absolute/path/to/twinning-mcp",
"args": ["--workdir", "/absolute/path/to/project"]
}
}
}
Cursor:
{
"mcpServers": {
"twins": {
"command": "/absolute/path/to/twinning-mcp",
"args": ["--workdir", "/absolute/path/to/project"]
}
}
}
Prebuilt binary install: download the archive for your platform from the
release page and verify it
against SHA256SUMS. Each macOS and Linux archive holds the matching twinning
and twinning-mcp pair; the Windows archive holds twinning only.
The MCP server is also on npm. npx @cmdrvl/twinning-mcp downloads the matching
release archive, checks it against its SHA-256, and runs it. Homebrew also
installs both binaries: brew install cmdrvl/tap/twinning.
The stdio MCP server exposes seven tools:
| Tool | Arguments |
|---|---|
twin_doctor | None. Check the executable and workdir. |
twin_list | None. List retained twins. |
twin_pair_proof | Required: left_snapshot_path, right_snapshot_path, queries_path. Optional: report_path. |
twin_report | twin_id; only available after stop. |
twin_seed_contract | kind: "postgres", schema_path. |
twin_start | Required: kind and the kind's input path. Postgres uses schema_path; optional fields are verify_path, seed_path, restore_path, snapshot_path, declaration_path, capture_refused_statements (default false), and ttl_minutes. REST uses spec_path; optional fields are auth_mode, server_variables, and ttl_minutes. |
twin_stop | twin_id. Stop a twin and return its summary. |
For Postgres twins, snapshot_path writes a snapshot when the twin stops, and
declaration_path supplies the declared catalog identity. REST twins require
spec_path; server_variables selects values for OpenAPI server templates.
twin_pair_proof reads Postgres snapshots and a replay query file.
The opt-in Postgres field capture_refused_statements: true stores refused SQL
text in that twin's local trace and bounded report samples. Refused SQL can
contain literal values. Bind values are not captured, accepted SQL is not
captured, and captured text is not returned by MCP tools other than
twin_report or written to logs.
Keep capture disabled unless you need to inspect refused statements.
Example tools/call request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "twin_start",
"arguments": {
"kind": "postgres",
"schema_path": "docs/demo/schema.sql"
}
}
}
Example prompts:
docs/demo/schema.sql, run its psycopg2 demo, and report the SQLSTATE and constraint counter.twin_pair_proof with the migration query set and explain each verdict.127.0.0.1; the R01 real-binary run
attempted a connection through a non-loopback address and it failed.E_PATH_OUTSIDE_WORKDIR.$ref entries are refused before a child starts or a
remote fetch occurs.postgres and rest kinds. twin_report is
available after twin_stop writes the report.Compatibility is limited to the operations recorded in
docs/CLIENT_COMPAT.md. In that record, psql 14.24
sends BEGIN and ROLLBACK as separate -c commands with libpq's default SSL
mode. psycopg2 2.9.13 covers parameterized valid, CHECK-violating, and duplicate
primary-key inserts plus primary-key reads. SQLAlchemy Core 2.1.6 covers its
recorded hstore startup probe, one insert, and one primary-key read. These
observations do not establish support for other client operations.
The compatibility record identifies these unsupported or untested cases:
SHOW ALL and a multi-statement simple query return SQLSTATE 0A000.information_schema reflection and the listed inner join return
SQLSTATE 0A000.The package license is MIT; see LICENSE.
From a clean clone with Cargo, Python, and uv available, run:
./docs/demo/run.sh
On a first run with empty Cargo and uv caches, the script needs network access
to download the locked Rust dependencies and psycopg2-binary. It builds the
real twinning and twinning-mcp binaries, uses the real psycopg2 driver,
starts a twin, inserts one valid row, records a CHECK violation, stops the
twin, and reads the final report. See
the demo steps.
Protocol-faithful interface twins for fast extractor iteration and later migration proof.
twinning is the spine and factory's runtime twin layer. It materializes
already-decided state behind a real protocol boundary so existing client code
can run against a fast disposable twin instead of a large production database.
It answers one narrow question:
Can this client or extractor run against a protocol-faithful twin for the declared subset, and what committed-state artifacts does that twin produce?
Current status:
run_once and --serve shells for the proven Postgres subset, plus REST, MCP, and Snowflake wire protocol twinscrates/twinning-kernel, crates/twinning-postgres, crates/twinning-rest, crates/twinning-snowflakeProtocol twins available:
| Subcommand | Feature flag | Protocol |
|---|---|---|
twinning postgres | (default) | pgwire — canary-defined SQL subset |
twinning rest | rest | OpenAPI-spec-driven HTTP REST |
twinning mcp | mcp | Model Context Protocol (JSON-RPC 2.0 over HTTP + stdio) |
twinning snowflake | snowflake | Snowflake HTTP wire protocol (Arrow IPC results) |
twinning port | rest | Dual REST twins for client migration proof |
Build with all twins: cargo build --features all
# Build with all protocol twins enabled
cargo build --features all
# Validate a schema and inspect the bootstrap state
cargo run -- postgres --schema schema.sql --json
# Write the bootstrap report and deterministic bootstrap snapshot
cargo run -- postgres --schema schema.sql --verify schema.verify.json \
--report out/bootstrap.json \
--snapshot out/bootstrap.twin \
--json
# Capture declared rows from a disposable/source Postgres database into a snapshot
cargo run -- postgres --schema schema.sql \
--materialize-source-url "$SOURCE_DATABASE_URL" \
--report out/materialized.json \
--snapshot out/materialized.twin \
--json
# Export a seed contract for an external agent to fill, then import seed rows
cargo run -- postgres --schema schema.sql \
--export-seed-contract out/seed-contract.jsonl \
--json
cargo run -- postgres --schema schema.sql \
--seed out/seed-data.jsonl \
--snapshot out/seeded.twin \
--json
# Restore a prior snapshot and re-emit bootstrap status
cargo run -- postgres --restore out/bootstrap.twin --json
# Compare two committed-state snapshots over one proof query fixture
cargo run -- --json proof twin-pair \
--left snapshots/legacy.twin \
--right snapshots/candidate.twin \
--queries tests/fixtures/differential/twin_pair_migration_proof/cases.json \
--report out/twin-pair-proof.json
# Run manifest-first twin-pair proof orchestration over restore-backed or schema-load endpoints
cargo run -- --json proof twin-pair orchestrate \
--manifest proof-run.json \
--report out/twin-pair-proof.json \
--bundle-dir out/twin-pair-proof/
# Run one child command against the live run_once shell
# The child must connect to the configured --host/--port.
cargo run -- postgres --schema schema.sql --run 'your-client-command' --json
# REST twin — serve OpenAPI-spec-driven HTTP endpoints
cargo run --features rest -- rest --spec openapi.yaml --serve --report out/rest.json
# REST response stubs — deterministic contract responses declared in x-twinning
cargo run --features rest -- rest \
--spec tests/fixtures/rest/openfigi_v2_v3/response-stub-schema.yaml \
--server-variable basePath=v3 \
--auth-mode shape \
--serve
# MCP twin — serve Model Context Protocol over HTTP (or stdio)
cargo run --features mcp -- mcp --server 'npx @scope/mcp-server' --report out/mcp.json
cargo run --features mcp -- mcp --manifest manifest.json --serve
# Snowflake wire twin — serve Snowflake HTTP protocol with Arrow IPC results
cargo run --features snowflake -- snowflake --schema schema.sql --serve --report out/sf.json
# Run a standalone interactive twin until SIGINT/SIGTERM
cargo run -- postgres --schema schema.sql \
--serve \
--report out/interactive.json \
--snapshot out/interactive.twin \
--json
# Opt in to a redacted-by-default query trace artifact for a live run_once session
cargo run -- postgres --schema schema.sql \
--run 'your-client-command' \
--query-trace out/query-trace.json \
--json
# Also capture SQL text for refused statements only; the local trace can contain SQL literals.
cargo run -- postgres --schema schema.sql \
--serve \
--query-trace out/query-trace.json \
--capture-refused-statements \
--json
# Print the operator manifest
cargo run -- --describe
# Inspect the read-only doctor surface
cargo run -- doctor health --json
cargo run -- doctor capabilities --json
cargo run -- doctor --robot-triage
The first materialization example shells out to psql and captures only the
tables declared by the schema. Use it against a source account/database that is
safe for deterministic reads; TWINNING_PSQL_BIN can point at a specific
psql binary in test harnesses. The --run and --serve examples use the
current live pgwire shell and final artifact path.
Seed JSONL is a contract/data pair, not a generator. --export-seed-contract
writes a deterministic schema-shaped template for another agent to fill.
--seed imports filled rows through the Postgres kernel and constraint executor
before bootstrap finalization or live startup, so seeded rows become committed
state in reports, snapshots, and the first run_once client session. V1 is
schema-backed only: seed import/export cannot be combined with --restore, and
--seed cannot be combined with --materialize-source-url.
Human mode (default):
twinning postgres bootstrap ready
endpoint: 127.0.0.1:5432
schema: schema.sql (4 tables, 28 columns, 3 indexes, hash sha256:a1b2c3...)
storage: tournament=bounded-memory hot working set with per-twin overlay | replay=disk-backed, snapshot-backed, or delegated real-database backend
verify: constraints.verify.json (12 loaded, hash sha256:d4e5f6...)
snapshot: out/bootstrap.twin (sha256:7a8b9c...)
next: Bootstrap mode validated the schema assets and deterministic artifact path. Use --run or --serve to exercise the declared live Postgres subset, or stay in bootstrap mode while broader protocol and SQL coverage lands.
JSON mode (--json):
{
"version": "twinning.v0",
"outcome": "READY",
"mode": "bootstrap",
"engine": "postgres",
"host": "127.0.0.1",
"port": 5432,
"wire_protocol": "pgwire",
"schema": {
"source": "schema.sql",
"hash": "sha256:a1b2c3...",
"table_count": 4,
"column_count": 28,
"index_count": 3,
"constraint_count": 9
},
"verify_artifact": {
"source": "constraints.verify.json",
"hash": "sha256:d4e5f6...",
"loaded": 12
},
"catalog": {
"dialect": "postgres",
"table_count": 4,
"column_count": 28,
"index_count": 3,
"constraint_count": 9
},
"storage": {
"tournament_mode": "bounded-memory hot working set with per-twin overlay",
"replay_mode": "disk-backed, snapshot-backed, or delegated real-database backend",
"hot_working_set": "memory",
"cold_state": "shared snapshot or pluggable backing store"
},
"tables": {
"public.deals": { "rows": 0, "columns": 10, "indexes": 2, "constraints": 4 },
"public.tenants": { "rows": 0, "columns": 6, "indexes": 1, "constraints": 3 }
},
"constraints": {
"not_null_violations": 0,
"fk_violations": 0,
"check_violations": 0,
"unique_violations": 0
},
"snapshot": {
"written_to": "out/bootstrap.twin",
"snapshot_hash": "sha256:7a8b9c..."
},
"next_step": "Bootstrap mode validated the schema assets and deterministic artifact path. Use --run or --serve to exercise the declared live Postgres subset, or stay in bootstrap mode while broader protocol and SQL coverage lands."
}
Bootstrap reports show the validation-oriented next_step string above. When
--run is present, the report switches to mode: "run_once" and points
operators at the final run metadata instead.
Run-once mode (--run <COMMAND>):
{
"version": "twinning.v0",
"outcome": "FAIL",
"mode": "run_once",
"engine": "postgres",
"host": "127.0.0.1",
"port": 5432,
"run": {
"command": "exit 7",
"exit_code": 7,
"timed_out": false
},
"next_step": "Inspect the run metadata, fix the child failure or drift, and rerun the candidate against the twin."
}
Interactive mode (--serve):
{
"version": "twinning.v0",
"outcome": "READY",
"mode": "interactive",
"engine": "postgres",
"host": "127.0.0.1",
"port": 5432,
"next_step": "Interactive mode finalized committed-state artifacts after shutdown. Inspect the snapshot and embedded verify payload before reusing this twin state."
}
Refusal mode (bootstrap/configuration failure):
{
"version": "twinning.v0",
"outcome": "REFUSAL",
"refusal": {
"code": "E_AMBIGUOUS_BOOTSTRAP_SOURCE",
"message": "Use exactly one bootstrap source: --schema or --restore, not both.",
"detail": { "engine": "postgres" },
"next_command": "twinning postgres --schema schema.sql --json"
}
}
Two loops need the same primitive:
You provide:
verify.constraint.v1 artifacttwinning returns:
twinning.v0 report over the declared committed statetwinning.snapshot.v0 snapshot with canonical
committed-state bytes; envelope metadata such as creation time and restore
lineage remains explicit but is not the equality surfaceImplemented now:
Postgres twin (default):
sqlparser-rs, deterministic normalized catalog construction--run and --serve modes with SIGINT/SIGTERM finalizationREST twin (--features rest):
x-twinning.response-stubs for fixture-backed contract responsesport dual-twin migration proofMCP twin (--features mcp):
initialize, tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/getunsupported_shape for stateful/schema-less toolsSnowflake wire twin (--features snowflake):
rowsetBase64 result encoding with full Snowflake type fidelitySHOW and DESCRIBE responses for JDBC/DBeaver/dbt compatibilitySqlRoute classificationNot implemented yet:
This means the repo can validate bootstrap assets, run one child command, or serve interactive clients for the proven subset, but it still refuses broader live traffic instead of pretending to be a complete database.
Command surface:
twinning postgres [OPTIONS] # pgwire twin (default)
twinning rest [OPTIONS] # REST twin (--features rest)
twinning mcp [OPTIONS] # MCP twin (--features mcp)
twinning snowflake [OPTIONS] # Snowflake wire twin (--features snowflake)
twinning port [OPTIONS] # dual REST twins (--features rest)
twinning proof twin-pair [OPTIONS] # twin-pair migration proof
twinning doctor [SUBCOMMAND] # read-only health/capabilities
Current options:
--schema <FILE>: SQL DDL file defining tables, constraints, and indexes--verify <FILE>: compiled verify.constraint.v1 artifact--declaration <FILE>: optional twinning.catalog-declaration.v0 parent catalog subset identity--host <HOST>: bind host (default 127.0.0.1)--port <PORT>: bind port (default 5432)--run <COMMAND>: run one child command against the live pgwire shell, then freeze final artifacts--serve: run a standalone interactive pgwire shell until SIGINT/SIGTERM, then freeze final artifacts--report <FILE>: write twinning.v0--snapshot <FILE>: write twinning.snapshot.v0--query-trace <FILE>: write a live query trace artifact, redacted by default, in --run or --serve--capture-refused-statements: with --query-trace, capture refused Postgres SQL text only; the local trace may contain SQL literals, never bind values--restore <FILE>: restore a prior twinning.snapshot.v0--export-seed-contract <FILE>: write twinning.seed-contract.v0 JSONL for the schema-loaded Postgres catalog--seed <FILE>: import filled twinning.seed-data.v0 JSONL as committed Postgres state--materialize-source-url <URL>: capture declared source rows into the final report/snapshot--json: emit machine-readable status--describe: print operator.jsonREST response stubs are declared inside the OpenAPI document under
x-twinning.response-stubs and are consumed through the existing
twinning rest --spec <FILE> path. They are deterministic contract fixtures:
the runtime matches method, mounted path, and optional canonical JSON request
body equality, then returns the declared status, headers, and JSON, text, or
file-backed body after auth, chaos, and matched request-body validation checks.
File-backed bodies use body-file and are validated at startup. They are not
generated dummy data, not a live provider simulator, and not a separate REST
--seed mode.
For matched JSON routes, the REST twin validates the declared OpenAPI
requestBody.content.application/json.schema before response stubs,
materialization, or unsupported_shape route refusal. Schema failures return
deterministic request paths such as $.edges[0].downstream_key; malformed JSON
and unsupported content types keep their existing refusal mappings. If a valid
request reaches a non-materialized route, request_valid: true only means the
request matched the declared request schema. It does not mean side effects were
modeled or persisted.
Use separate specs or thin spec overlays to model separate API scenarios for the
same upstream service, such as happy path, no-match, malformed/error, and
ambiguity twins. The OpenFIGI fixture at
tests/fixtures/rest/openfigi_v2_v3/response-stub-schema.yaml demonstrates a
local /v3/mapping response that returns the OpenFIGI top-level batch array
instead of the generic {"data":null,"warning":null} fallback.
Managed paths:
~/.cmdrvl/config/twinning/config.toml~/.cmdrvl/state/twinning/~/.cmdrvl/cache/twinning/~/.cmdrvl/migrations/applied.jsonl
and ~/.cmdrvl/notices/deprecated-paths.jsonlRead-only doctor surface:
doctor health --json: emit twinning.v0 health diagnostics without reading
schema, snapshot, or verify filesdoctor capabilities --json: list machine-readable commands, output
contracts, detector fixtures, and safety boundariesdoctor robot-docs: print concise agent-facing command notesdoctor --robot-triage: emit structured follow-up findingsdoctor --fix is intentionally not available. The read-only doctor detector
catalog is fixture-backed, and any future fix mode needs verbatim backups,
explicit inverses, and undo tests before it is exposed.
Exit codes:
| Exit | Meaning |
|---|---|
0 | clean bootstrap, run_once, or --serve completion without embedded verify failure |
1 | live finalization completed but embedded verify reported FAIL |
2 | refusal / bootstrap failure / CLI error |
Live-shape discipline:
twinning rest --spec openapi.yaml --serve --report out/rest.json
Where it serves. twinning rest binds --host (default 127.0.0.1) and
--port (default 8080), so the base URL is http://127.0.0.1:8080 unless you
override them. The standalone REST server does not print its address at startup;
it logs the route topology and then waits for SIGINT/SIGTERM. Pass --port
explicitly if you need to be certain. The startup route table's PATH column is
the path to request; a literal path in servers[].url was not added as a prefix
in a local check (a spec with url: http://localhost/api/demo/v1.0 and path
/loans served /loans), so always read the table, not the spec. Each request
is logged as GET <path> -> <status>. The session report is written to
--report only after the server stops.
Reading the startup log. Each route is listed as ok (materialized) or
REFUSED. A line such as [rest] 7 routes ok | 3 refused means 3 routes will
not return spec data. Lines such as "Schema has type string and is not
materialized as REST resource fields in v0", "oneOf is treated as text" and
"array path/query filters remain unsupported" are documented v0 limits, not
errors. No spec examples found - backend starts empty means the spec has no
example values to seed from, so list routes return []. The REST twin has no
--seed flag; it seeds committed rows at startup from OpenAPI examples (see
below).
Getting sample objects back from ok routes. Add example values to the
spec and the twin seeds them as rows when it starts. The startup log then says
Seeded N rows across M resource types from spec examples. Examples are read
from a schema's example (components.schemas.<Name>.example), from named or
inline component and request-body examples, and from GET response examples on
routes that are not refused. A refused route is skipped, and an example whose
values do not match the schema types is skipped with a warning. Without a
primary key, all examples are seeded and a warning is logged once; with one,
a duplicate key keeps the first example. Example rows that go in the spec are
fixtures: use realistic but non-sensitive values.
Worked example, checked against the real binary. A list route returning an
array of objects, with one schema-level example on the item schema:
openapi: 3.0.3
info: { title: Seed demo, version: "1.0" }
paths:
/loans:
get:
responses:
"200":
description: ok
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Loan"
components:
schemas:
Loan:
type: object
required: [loanId]
properties:
loanId: { type: string }
balance: { type: number }
example:
loanId: "L-001"
balance: 1250000
twinning rest --spec seed.yaml --port 18080 --serve logs
Seeded 1 rows across 1 resource types from spec examples, and
curl http://127.0.0.1:18080/loans returns
[{"balance":"1250000","loanId":"L-001"}]. Note that the number field comes
back as a JSON string. To seed several rows, use one example per schema or
named examples where the spec allows them; only a single schema-level
example was run here. Re-run curl against every route you expect to return
data and confirm the object shape before relying on it.
Why a route is refused, and what to do. Refusals are deliberate. Fix the spec or add a stub; do not loosen the twin to make a refusal go away.
| Startup message | Cause | Fix |
|---|---|---|
REST route declares a non-CRUD static discovery-style object response ... Path: <p> | The route returns a fixed object (a discovery or "last changed" style endpoint), not a resource collection. | Declare a deterministic response under x-twinning.response-stubs for that route. |
REST route requires path lookup on resource '<r>', but the resource has no primary key and no path parameter can materialize a declared column | A route such as GET /deal/{dealIdentifier} needs to look a row up, but the path parameter does not match any property on the response schema. | Give the response schema a property that matches the path parameter, or use a response stub. |
Path parameter to column matching (see resource_column_for_path_param in
crates/twinning-rest/src/normalize.rs): the parameter name is compared with
the resource's declared properties as written, lower-cased, and converted from
camelCase to snake_case, and a resource-name prefix may be stripped. Matching
ignores case. So dealIdentifier matches a property named dealIdentifier,
dealidentifier or deal_identifier. A parameter named pk or key falls
back to the schema's single required scalar property. Do not rely on any other
name matching; name the property after the path parameter.
Response stubs for routes the twin cannot materialize. Add to the OpenAPI document:
x-twinning:
response-stubs:
- id: last_changed
method: GET
path: /api/cmbs-data/v1.0/changes/last-changed # the PATH shown in the startup route table
status: 200
headers:
Content-Type: application/json
body:
lastChanged: "2026-01-01T00:00:00Z"
Rules, from crates/twinning-rest/src/xext.rs: each stub needs id, method,
path (starting with /, matching the mounted path in the startup route table) and status (100 to 599), plus exactly one of body,
body-text or body-file. The only matcher is
when.body-json-equals. Unknown keys are rejected. A stub whose path matches no
mounted route is refused at startup with E_REST_INVALID_X_TWINNING. Stub paths
are concrete, so a parameterized route needs one stub per concrete path you want
served. Working examples: docs/demo/rest/response-stub-schema.yaml and
tests/fixtures/rest/openfigi_v2_v3/response-stub-schema.yaml. Stubs are
fixtures, not generated data and not a stateful simulator.
twinning owns:
twinning does not own:
decoding, canon)verify)benchmark)assess)pack)Critical boundary:
verifyverify.report.v1 payloadsverifyverify/benchmark/assess
artifact identities, but must not score or reinterpret themFactory role:
decoding / materialize -> twinning -> embedded verify -> assess / pack
Current development sequencing:
real Postgres proof loop first -> twinning tournament wedge -> later replay/proof modes
Related tools:
| If you need... | Use |
|---|---|
| Claim resolution and canonical mutation selection | decoding |
| Constraint semantics and reports | verify |
| Gold-set scoring | benchmark |
| Policy decisions | assess |
| Evidence sealing | pack |
twinning only answers:
Can we materialize and exercise candidate state behind a protocol-faithful twin boundary for the declared subset?
Current artifact contracts:
twinning.v0 — bootstrap or later runtime reporttwinning.snapshot.v0 — content-addressed snapshottwinning.query-trace.v0: opt-in live query lineage artifact with SQL text redactedtwinning.query-trace.v1: opt-in refused-statement capture; refused SQL text may contain SQL literals and bind values remain redactedtwinning.twin-pair-proof.v0 — interface-equivalence receipt for two Postgres twinstwinning.twin-pair-replay-result.v0 — per-case replay diff inputs nested in twin-pair proof reportstwinning.twin-pair-replay-manifest.v0 — declared Postgres-subset replay manifest for twin-pair proof queriestwinning.twin-pair-orchestration-manifest.v0 — manifest-first twin-pair proof orchestration contracttwinning.canary-manifest.v0 — normative compatibility manifest for the supported subsetChecked-in manifest:
Schemas:
Snapshot contract highlights:
run_once snapshots freeze committed relation contents for the executed subsetRefusals are structured errors with exit code 2. Each includes a code, message, detail, and (when applicable) a next_command suggesting what to run instead.
| Code | When | Next step |
|---|---|---|
E_BOOTSTRAP_SOURCE_REQUIRED | Neither --schema nor --restore provided | Add --schema schema.sql |
E_AMBIGUOUS_BOOTSTRAP_SOURCE | Both --schema and --restore provided | Use exactly one |
E_ENGINE_UNIMPLEMENTED | Non-Postgres engine requested | Use twinning postgres ... |
E_IO_READ | Input file not readable | Check path and permissions |
E_IO_WRITE | Output file not writable | Check path and permissions |
E_SCHEMA_PARSE | DDL parsing failed | Fix SQL syntax in schema file |
E_DECLARATION_PARSE | Catalog declaration malformed or mismatched | Regenerate the declaration for the selected schema |
E_VERIFY_ARTIFACT_PARSE | Verify artifact malformed | Regenerate with verify |
E_SNAPSHOT_VERIFY | Snapshot hash mismatch or version error | Re-emit from schema source |
E_SEED_BOOTSTRAP_SOURCE | Seed import/export requested with --restore | Use --schema |
E_SEED_SOURCE_COMPOSITION | --seed combined with --materialize-source-url | Pick one source for v1 |
E_SEED_JSONL | Seed JSONL is malformed or violates catalog/constraint rules | Regenerate or fix seed rows |
E_REST_INVALID_X_TWINNING | REST x-twinning response stubs are malformed or target no mounted route | Fix the OpenAPI x-twinning extension |
E_TWIN_PAIR_PROOF | Twin-pair proof inputs or query fixture are incompatible | Use snapshots with the same schema/catalog/declaration and a supported query fixture |
E_SERIALIZATION | Internal JSON rendering failure | Report bug |
Refusals are never silent. If twinning cannot do what you asked, it tells you why and what to try instead.
| If you need... | Use | Not twinning |
|---|---|---|
| Claim resolution, canonical mutation selection | decoding | twinning does not decide truth |
| Constraint semantics and validation rules | verify | twinning executes verify, it does not define constraints |
| Gold-set scoring | benchmark | twinning materializes state, it does not score it |
| Policy proceed/block decisions | assess | twinning reports, it does not adjudicate |
| Evidence sealing | pack | twinning is runtime, not archive |
| A real Postgres instance | docker run postgres | twinning speaks the protocol for a narrow subset, it is not a database |
| A general SQL engine | DuckDB, SQLite | twinning only supports canary-defined shapes |
twinning only answers: Can this client run against a protocol-faithful twin for the declared subset, and what committed-state artifacts does that twin produce?
Tagged releases publish twinning to cmdrvl/tap:
brew install cmdrvl/tap/twinning
Until the first tagged release is cut, use the source build below.
git clone https://github.com/cmdrvl/twinning.git
cd twinning
cargo build --release
# Binary at target/release/twinning
Cargo fetches the pinned cmdrvl/verify Git revision for verify-core and
verify-engine; a sibling checkout is not required.
twinning is designed for agent-driven pipelines. Parse JSON output programmatically:
# Check bootstrap readiness
result=$(cargo run -- postgres --schema schema.sql --json 2>/dev/null)
outcome=$(echo "$result" | jq -r '.outcome')
case $outcome in
READY) echo "Twin ready for bootstrap or live mode" ;;
REFUSAL) echo "Refused: $(echo "$result" | jq -r '.refusal.code')" ;;
esac
# Exit code routing
cargo run -- postgres --schema schema.sql --json
case $? in
0) echo "clean bootstrap" ;;
1) echo "verify violations (future)" ;;
2) echo "refusal or error" ;;
esac
FAIL outcome in run_once mode
The child command completed with a non-success exit, timeout, signal, or an
embedded verify failure. Inspect the run metadata and any attached verify
payload in twinning.v0, fix the candidate or supported-shape drift, and rerun.
E_SCHEMA_PARSE on valid-looking SQL
twinning uses sqlparser-rs for DDL parsing. Ensure your schema uses standard Postgres CREATE TABLE syntax. Extensions, custom types, and procedural SQL are not supported in v0.
E_SNAPSHOT_VERIFY hash mismatch
The snapshot was modified after creation, or was produced by a different twinning version. Re-emit from the original schema source with --schema and --snapshot.
E_ENGINE_UNIMPLEMENTED for mysql or oracle
Only the Postgres engine is implemented. MySQL and Oracle are declared in the CLI for forward compatibility but currently refused. See docs/PLAN_TWINNING_FUTURES.md for the roadmap.
--run and --serve bind pgwire for the manifest-backed subset; unsupported SQL and protocol shapes remain explicit live errors.cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test
./scripts/ubs_gate.sh
Built by CMD+RVL. Support: cairn@cmdrvl.com or GitHub issues. Questions about filings or structured finance data? Chat with Cairn over text at textcairn.com.