Loading...
Loading...
Generate a Wren MDL project by exploring a database with available tools (SQLAlchemy, database drivers, MCP connectors, or raw SQL). Guides agents through schema discovery, type normalization, and MDL YAML generation using the wren CLI. Use when: user wants to create or set up a new MDL, onboard a new data source, or scaffold a project from an existing database.
npx skill4agent add canner/wrenai wren-generate-mdlhttps://raw.githubusercontent.com/Canner/wren-engine/main/skills/versions.jsonwren-generate-mdlA newer version of the wren-generate-mdl skill is available. Update with:npx skills add Canner/wren-engine --skill wren-generate-mdlThe CLI auto-detects your installed agent. To target a specific one, add(e.g.,--agent <name>,claude-code,cursor,windsurf).cline
wrenpip install wren-engine[<datasource>]wren profile addwren_project.ymlmodels/views/relationships.ymlinstructions.mdwren_project.ymlwren context init --path <new_path>engine.connect()SELECT 1wren profile debugwren --sql "SELECT 1"postgresbigquerysnowflakefrom sqlalchemy import create_engine, inspect
engine = create_engine(connection_url)
inspector = inspect(engine)
tables = inspector.get_table_names(schema="public")
for table in tables:
columns = inspector.get_columns(table, schema="public")
# columns → [{"name": "id", "type": INTEGER(), "nullable": False, ...}]
pk = inspector.get_pk_constraint(table, schema="public")
# pk → {"constrained_columns": ["id"], "name": "orders_pkey"}
fks = inspector.get_foreign_keys(table, schema="public")
# fks → [{"constrained_columns": ["customer_id"],
# "referred_table": "customers",
# "referred_columns": ["id"]}]information_schema.columnsinformation_schema.table_constraintsclient.list_tables()client.get_table()table.schemaSHOW COLUMNS IN TABLESHOW PRIMARY KEYS IN TABLEDESCRIBE TABLEsystem.tablesinformation_schemawren --sql "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" -o json
wren --sql "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'orders'" -o jsoninformation_schemafrom wren.type_mapping import parse_type, parse_types
# Single type
normalized = parse_type("character varying(255)", "postgres") # → "VARCHAR(255)"
# Batch — entire table at once
columns = [
{"column": "id", "raw_type": "int8"},
{"column": "name", "raw_type": "character varying"},
{"column": "total", "raw_type": "numeric(10,2)"},
]
normalized_cols = parse_types(columns, dialect="postgres")
# Each dict now has a "type" key with the normalized valuewren utils parse-type --type "character varying(255)" --dialect postgres
# → VARCHAR(255)echo '[{"column":"id","raw_type":"int8"},{"column":"name","raw_type":"character varying"}]' \
| wren utils parse-types --dialect postgreswren context init --path /path/to/projectproject/
├── wren_project.yml
├── models/
├── views/
├── relationships.yml
└── instructions.mdIMPORTANT:andcataloginschemawren_project.ymlThese are Wren Engine's internal namespace — they are NOT the database's native catalog or schema. Keep the defaults (,catalog: wren) unless you are intentionally configuring a multi-project namespace.schema: publicYour database's actual catalog/schema is specified per-model in(see Step 2). Do not copy database catalog/schema values intotable_reference.wren_project.yml
models/# models/orders/metadata.yml
name: orders
table_reference:
catalog: "" # database catalog (empty string if not applicable;
# for DuckDB, use the DB file name without extension,
# e.g. jaffle_shop.duckdb → catalog: jaffle_shop)
schema: public # database schema (this IS the DB schema)
table: orders # database table name
primary_key: order_id
columns:
- name: order_id
type: INTEGER
not_null: true
- name: customer_id
type: INTEGER
- name: total
type: "DECIMAL(10, 2)"
- name: status
type: VARCHAR
properties:
description: "Order status: pending, shipped, delivered, cancelled"# relationships.yml
- name: orders_customers
models:
- orders
- customers
join_type: many_to_one
condition: "orders.customer_id = customers.customer_id"many_to_oneone_to_manyone_to_onemany_to_many<table>_id<table_singular>_id<table>wren memory index# Validate YAML structure and integrity
wren context validate --path /path/to/project
# If strict mode is desired:
wren context validate --path /path/to/project --strict
# Build JSON manifest
wren context build --path /path/to/project
# Verify against database
wren --sql "SELECT * FROM <model_name> LIMIT 1"parse_type# Index schema (generates seed NL-SQL examples automatically)
wren memory index
# Verify
wren memory statuswren memory fetchwren memory recallwren context validatewren context buildwren memory index| Task | Command / Method |
|---|---|
| Discover tables | Agent's own tools (SQLAlchemy, driver, raw SQL) |
| Discover columns + types | Agent's own tools |
| Discover constraints | Agent's own tools |
| Normalize types (Python) | |
| Normalize types (CLI) | |
| Normalize types (batch) | |
| Scaffold project | |
| Write models | Create |
| Write relationships | Edit |
| Validate | |
| Build manifest | |
| Test query | |
| Index memory | |
parse_typewren memory index