Overview of the Wren Core Module
mainibis-server API v3. For Python users, the functionality is exposed via the wren-core-py module, which is also utilized by the ibis-server.repository·main·Indexed 20 days ago
https://github.com/canner/wren-engineAn open-source semantic and execution foundation that provides AI agents with business context by transforming raw data into a governed layer of models, metrics, and relationships using Modeling Definition Language (MDL). The project includes the wren-engine-server (v0.25.0), a CLI tool, and an Ibis Server module for executing SQL queries via FastAPI, ibis, and sqlglot.
ibis-server API v3. For Python users, the functionality is exposed via the wren-core-py module, which is also utilized by the ibis-server.The Ibis Server Module is the API server for Wren Engine, built on top of FastAPI. It provides APIs for executing SQL queries. The query lifecycle involves:
wren-core.sqlglot.ibis against the target database.Note: This module is deprecated. Wren Engine is migrating to a CLI tool with similar capabilities. For the new tool, refer to the wren package.
This repository is archived (read-only) and has been merged into Canner/WrenAI under the core/ directory.
The wren-http-api allows you to interact with the Wren MCP server using plain HTTP JSON-RPC 2.0 requests. This is useful when your client cannot use the standard MCP SDK (e.g., custom HTTP clients, shell scripts, or environments like OpenClaw).
Key Details:
http://localhost:9000/mcp (default Docker setup).Content-Type: application/jsonAccept: application/json, text/event-streamstreamable-http transport, meaning responses arrive as Server-Sent Events (SSE).A Wren MDL project is a directory of YAML files used to manage Wren Model Definition Language (MDL) manifests in a human-readable and version-control friendly format, similar to how dbt projects operate.
Instead of managing a single large JSON file, you split the manifest into several files: one for project metadata, one per model, one for all relationships, and one for all views. This structure allows for easier code reviews and granular version control.
Key distinction: The YAML files use snake_case for field names to improve readability, while the compiled output (target/mdl.json) uses camelCase to match the wire format expected by the engine.
A View is a named SQL query stored in the MDL (Model Definition Language). It acts as a virtual table that clients can query by name.
Key characteristics:
statement SQL before execution.statement at query time.Use a View for pre-built queries such as dashboards, saved filters, or cross-model aggregations that you want to expose as a named table.
Modeling Definition Language (MDL) is the structured, machine-readable language used by Wren Engine to describe business data. Instead of exposing raw database tables and columns, MDL provides a logical layer that defines how data should be interpreted and used.
MDL allows you to define:
By using MDL, you provide Wren Engine with a consistent business context, which is essential for reliable query generation and AI agent reasoning.
SELECT * FROM customers) instead of complex physical paths. Models define the exposed columns, their data types, and how they relate to other models.Wren Engine is an open context engine designed to provide AI agents with a semantic, governed layer for business data. Instead of agents interacting with raw database tables, Wren Engine allows them to reason over business concepts.
Wren Engine uses a rewrite pipeline to transform your SQL. It injects Common Table Expressions (CTEs) that expand each MDL (Model Definition Language) model into its underlying database query.
The Rewrite Pipeline:
sqlglot to parse your SQL and qualify column references.wren-core expands the model definition into a CTE.Example Transformation:
If you have a model orders backed by table public.orders with columns o_orderkey, o_custkey, and o_totalprice:
Your Input:
SELECT o_custkey, SUM(o_totalprice) FROM orders GROUP BY 1Engine Output (via dry-plan):
WITH "orders" AS (
SELECT "public"."orders"."o_orderkey",
"public"."orders"."o_custkey",
"public"."orders"."o_totalprice"
FROM "public"."orders"
)
SELECT o_custkey, SUM(o_totalprice) FROM orders GROUP BY 1The CTE named "orders" shadows the model name, allowing the rest of your SQL to run against the CTE as if it were a standard table.
-- You write:
SELECT o_custkey, SUM(o_totalprice) FROM orders GROUP BY 1
-- Engine produces (via dry-plan):
WITH "orders" AS (
SELECT "public"."orders"."o_orderkey",
"public"."orders"."o_custkey",
"public"."orders"."o_totalprice"
FROM "public"."orders"
)
SELECT o_custkey, SUM(o_totalprice) FROM orders GROUP BY 1The Memory layer is a LanceDB-backed semantic index. While models define what the data looks like, memory helps agents find the right parts of it.
Use Memory when you need to:
The Wren MDL is a JSON manifest that defines the catalog, schema, data source, models (tables), columns, and relationships.
catalog: Use "wren" unless specified otherwise.schema: Use the target schema name (e.g., "public").dataSource: Use the enum value of the data source (e.g., "POSTGRES").tableReference.catalog: Set this to the actual database name, not "wren".models: Each table in the database corresponds to one Model entry.columns: Each column in the table corresponds to one Column entry. Mark primary keys with "isPrimaryKey": true and update the model's primaryKey field.relationships: Define links between models using joinType and a condition string.{
"catalog": "wren",
"schema": "public",
"dataSource": "POSTGRES",
"models": [
{
"name": "orders",
"tableReference": {
"catalog": "my_db_name",
"schema": "public",
"table": "orders"
},
"columns": [
{
"name": "order_id",
"type": "INTEGER",
"isPrimaryKey": true,
"isCalculated": false,
"notNull": true
}
],
"primaryKey": "order_id"
}
],
"relationships": [
{
"name": "orders_customer",
"models": ["orders", "customers"],
"joinType": "MANY_TO_ONE",
"condition": "orders.customer_id = customers.customer_id"
}
]
}