Canonic

io.github.mischuh由 GitHub 帳號 mischuh 發布v0.46.2更新於 Nov 7, 2026

The Open Context Layer for Data Agents

概覽

AI 產生的概覽

Canonic 是本地情境層,讓 AI 助理透過受治理的指標定義、編譯後的 SQL 與護欄來查詢資料倉儲。

可以做什麼
  • 將指標與維度解析為標準定義,並針對資料倉儲編譯唯讀 SQL
  • 執行查詢與原始 SQL,回傳結果並附上解析出的定義、觸發的護欄、資料新鮮度與信任等級
  • 依整體與成員拆解指標在兩個期間之間的變化
  • 搜尋並閱讀業務知識頁面,其中的定義會即時呈現並附上注意事項
  • 審閱擬議的情境變更,並查看服務契約版本
適用情境
當助理需要針對資料倉儲回答資料問題,而你希望強制套用已議定的定義、強制篩選條件與信任中繼資料,而不是靠猜測時使用。適合已在 dbt、Looker、Metabase 或 Notion 維護指標,並希望代理重用這些語意的團隊。
執行需求
透過 uvx 或 pip 以本機程序執行,需要 Python 3.13 或更新版本。需要一個已連接資料來源的 canonic 專案目錄,可透過設定精靈配置。以伺服器為基礎的資料庫與選用的 LLM 草擬功能需要憑證,透過環境變數或用戶端設定的 env 欄位提供;本機 SQLite、DuckDB、CSV 與 Parquet 來源不需網路。
安裝前請注意
它會讀取你的資料倉儲,因此你提供的憑證即授予該存取權限;請放在環境變數或設定的 env 欄位中,不要直接寫入 canonic.yaml。情境變更會以可審閱的差異形式提出,套用前應先審閱。設定期間可能會用選用的 LLM 草擬情境,這會把結構描述資訊傳送給所選供應商。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Canonic,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

canonic

[CI] [PyPI] [License]

The context layer that lets AI agents query your data correctly.

Point canonic at your database and it builds the context an agent needs to answer data questions accurately: definitions, relationships, business meaning, and the guardrails that stop confidently-wrong answers. It keeps that context up to date as your data changes, and it never touches your warehouse beyond reading it.

📖 Full documentation: https://docs.getcanonic.app

The problem

An AI agent connected straight to your warehouse sees tables and columns, not meaning. It doesn't know that revenue lives in orders.amount but excludes refunds, or that "active customer" has a specific definition your finance team agreed on. So it guesses. Schema access makes an agent fluent. It doesn't make it correct.

Real output, captured from a live run against the ecommerce example:

bash
$ canonic sql "SELECT SUM(amount) FROM fct_orders"┏━━━━━━━━━┓┃ sum     ┃┡━━━━━━━━━┩│ 4050.50 │└─────────┘

This total includes two refunded orders ($260), a confident, well-formatted number that's off by 6.4%.

bash
$ canonic --json query --metrics revenue{  "result": { "rows": [["3790.50"]] },  "compiled": {    "sql": "SELECT SUM(\"orders\".\"amount\") AS \"revenue\" FROM \"fct_orders\" AS \"orders\" WHERE \"orders\".\"status\" <> 'refunded'"  },  "metadata": {    "guardrails_fired": [{ "id": "revenue-excludes-refunds", "kind": "mandatory_filter" }]  }}

canonic resolves "revenue" to its canonical definition, compiles the guardrail into the SQL whether or not anyone asked for it, and returns the right number with the reasoning attached.

canonic is not a BI tool and not a chat interface: it's the layer that feeds the tools you already have (a BI dashboard, an agent, a notebook) correct, governed answers.

What canonic does

  • Canonical definitions, enforced. An agent asks for a metric by name. canonic resolves it to the one agreed definition and compiles the SQL. Guardrails such as mandatory_filter, required_dimension, restrict_source and min_trust are part of the contract, so a documented caveat can't be silently skipped. Contracts and guardrails
  • The right aggregation, not just valid SQL. Semi-additive measures (MRR snapshots), ratios recomputed at the requested grain, distinct counts, percentiles and running totals each get their own compilation strategy, and joins that would fan out a fact table are caught. Several valid join paths? You pick one with via, canonic doesn't guess. Compiler
  • Answers carry their trust. Every result ships a metadata band: the resolved definition, guardrails fired, freshness, final vs. provisional rows, and a trust tier (trusted, provisional, caution) with the reasons behind it. Assertions gate CI, and confirmed-wrong outcomes lower a metric's trust. Trust and assertions
  • Why did it change? canonic decompose and the MCP tool decompose_change attribute the change of a metric between two periods, overall and by member. The method follows the metric's kind, so a ratio is split into mix and rate effects that add up, instead of per-member differences that do not. Tools reference
  • Refuse and ask. Ambiguous or unsafe questions come back as a structured reason (ambiguous_join_path, guardrail_block, ...) the agent can act on, never as a guess. Error codes
  • The context builds itself. Ingest drafts semantics from your live schema, a dbt manifest or an Apache Ossie model, and learns from Looker and Metabase usage, Notion pages and web docs. Every change is a reviewable diff (canonic review, canonic apply), drift is flagged, and references to things that disappeared are proposed for removal. Ingestion
  • Business knowledge for agents. Definitions, policies and caveats live as Markdown pages. Agents search them, read them with live-rendered definitions, and get the relevant caveats attached to an answer. Knowledge layer
  • Governance built in. Tenant scoping, role-based access, column masking, and OAuth 2.1 / OIDC for the MCP server, including identity assertion for agents acting on behalf of a user. Tenancy and access control
  • Your warehouse, read-only. Postgres, Redshift, MySQL, Snowflake, Databricks, ClickHouse, SQLite and DuckDB (including CSV and Parquet files). Connectors
  • Measurable. A local event log feeds canonic audit and canonic status, and an accuracy harness (canonic assert, canonic eval baseline) turns "trustworthy" into something you can check. Instrumentation

How it works

 your sources                 canonic                          consumers ────────────                 ───────                          ───────── warehouse schema ┐   ingest  ┌──────────────────────────┐     CLI (query, sql, review) dbt / Ossie      ├─────────▶ │ semantics/  knowledge/   │ ──▶ MCP server Looker, Metabase │  propose  │ contracts/  (files in git)│     Claude Code, Cursor, Codex, Notion, web docs ┘  → review └──────────────────────────┘     any MCP client

A question takes one deterministic path: resolve the metric, compile SQL against the canonical definition, apply guardrails, run it read-only, attach the metadata band. No LLM is involved at answer time.

What an agent gets back

Real output (abridged) from canonic --json query --metrics gross_revenue in the saas-analytics example:

json
{  "result": { "columns": [{ "name": "gross_revenue", "type": "decimal" }], "rows": [["77071.00"]] },  "compiled": {    "sql": "SELECT SUM(\"fct_invoices\".\"amount\") AS \"gross_revenue\" FROM \"fct_invoices\" AS \"fct_invoices\" WHERE \"fct_invoices\".\"status\" <> 'refunded' AND \"fct_invoices\".\"is_trial\" = FALSE",    "dialect": "duckdb"  },  "metadata": {    "resolved": { "metrics": { "gross_revenue": "fct_invoices.total_amount" } },    "guardrails_fired": [      { "id": "revenue-excludes-refunds", "kind": "mandatory_filter", "severity": "error" },      { "id": "revenue-excludes-trials", "kind": "mandatory_filter", "severity": "error" }    ],    "freshness": [{ "source": "fct_invoices", "stale": false }],    "trust_score": {      "tier": "provisional",      "reasons": ["gross_revenue: assertion unverified (pass/fail not yet persisted)"]    }  }}

The agent sees which definition answered, which rules shaped the SQL, and why the number is only provisional, so it can caveat the answer instead of presenting it as settled.

The three layers

canonic's context lives in three committed surfaces: plain files in your git repo, reviewed like code.

LayerFileAnswersOwned by
Semanticssemantics/**/*.yaml"How do I query this safely?"auto-maintained
Knowledgeknowledge/**/*.md"What does this mean to the business?"auto-maintained
Contractscontracts/**/*.yaml"Which definition is canonical, and what must the answer obey?"human-owned

Changes how the SQL runs → semantics. A human needs it to trust the answer → knowledge. Governs which definition is authoritative → contracts. See Concepts: the three layers.

Quickstart

canonic needs Python 3.13 or newer (uv fetches it for you).

bash
uvx canonic --version        # try it without installinguv tool install canonic      # persistent, global commandpip install canonic          # without uvdocker pull ghcr.io/mischuh/canonic:latest   # CI, headless, air-gapped

The fastest path uses local connectors, no server, no network. Point at a SQLite .db or DuckDB .duckdb/CSV/Parquet file:

bash
canonic setup

[canonic setup end-to-end on the vehicle rental example]

The wizard names your project, connects a source, optionally configures an LLM, drafts your semantics from the live schema, then runs a real query and shows the answer with its freshness and definition. A server-based database or an LLM provider needs a credential in an environment variable (or a file: reference) before you run canonic setup, because canonic never stores secrets in canonic.yaml directly.

You now have a working context layer committed to your repo:

bash
canonic overview                                           # what's askablecanonic query --metrics revenue --dimensions order_date    # ask itcanonic review && canonic status                           # review what it drafted

Air-gapped install and offline wheels: Installation.

Connect your agent (MCP)

canonic exposes its tools over a local, on-demand MCP server, verified with Claude Code, Cursor, and Codex:

bash
canonic mcp start
json
{  "mcpServers": {    "canonic": {      "command": "uvx",      "args": ["canonic", "mcp", "start", "--project", "/path/to/canonic/examples/rental", "--suggestions"]    }  }}

GUI-launched clients (Claude Desktop, Cursor) don't source your shell profile, so pass connection credentials via the config's env field, not export.

See Connecting your agent for remote and enterprise deployment (--transport http, per-client bearer tokens) and the tools reference. To see masking, run_sql gating and tenancy scoping applied to a real identity, scripts/local_idp runs the marketplace example behind a local Keycloak: walkthrough.

Example projects

examples/ ships seven ready-to-run projects, each with a guide:

ExampleBackendShows
jaffle-shopDuckDBdbt manifest with MetricFlow models as evidence
ecommercePostgresthe full loop: guardrails, finality, Notion and dbt evidence, observability
rentalSQLitecross-fact fanout and a NULL-handling guardrail, no setup needed
saas-analyticsDuckDBevery metric binding kind, all guardrail kinds, finality, assertions
dutch-railwayDuckDBa geography dimension chain and ratio metrics
marketplaceSQLitetenant scoping, role-based access and column masking
ossie-retailSQLitecontext bootstrapped from an Apache Ossie model
coffeehouseDuckDBthe same questions answered by dbt MetricFlow and canonic: count distinct, averages, guardrails

What you can rely on

  • Read-only. canonic never mutates your warehouse.
  • Propose-only, refuse-and-ask. Every change is a reviewable diff; ambiguous or unsafe answers get a structured reason, not a guess.
  • No LLM in the answer path. Queries compile deterministically. An LLM is optional and only drafts context during setup, four providers supported (Anthropic, OpenAI, any OpenAI-compatible endpoint, GitHub Copilot), see Configuring an LLM.
  • Local-first & air-gapped-capable. Run entirely on your machine; nothing has to leave your network.

For developers

bash
uv sync                          # install with dev dependenciesuv run pytest tests/ -x          # tests, including the golden suiteuv run ruff check . && uv run ruff format --check .uv run mypy canonic/
  • Layout. canonic/ is the package (compiler, connectors, contracts, ingestion, knowledge, MCP server, trust, instrumentation), tests/ mirrors it, examples/ holds the sample projects.
  • Extension points. Connectors register with the ConnectorFactory by capability (introspect_schema, run_read_only_sql, extract_definitions, extract_evidence), and short-lived credentials plug in through the CredentialProviderRegistry.
  • Stable contract. The serving contract is versioned (the contract_info MCP tool, CONTRACT_CHANGELOG.md), and tests/golden/ locks compiled SQL and executed numbers for the examples.
  • Contributing. Conventional Commits, the golden-suite workflow and the contract-change process are in CONTRIBUTING.md.

Documentation

  • Quickstart: first answer in minutes.
  • Concepts: the three layers, the compiler, contracts, tenancy.
  • CLI reference: every command, flag by flag.
  • MCP / agent integration: wiring canonic into Claude Code, Cursor, Codex, or any MCP client.
  • Guides: the seven example projects and the warehouse walkthroughs.
  • Reference: error codes and the full canonic.yaml config schema.

License

Business Source License 1.1. Free for non-commercial, personal, evaluation, educational and developmental use. Commercial use needs a separate license. The licensed version converts to Apache 2.0 on July 17, 2030.

來源:README.md,提交 f8e9c4d

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

24
  1. v0.46.2最新Nov 7, 2026
  2. v0.46.1Oct 29, 2026
  3. v0.46.0Oct 23, 2026
  4. v0.45.5Oct 21, 2026
  5. v0.45.4Oct 21, 2026
  6. v0.45.1Oct 20, 2026
  7. v0.45.0Oct 20, 2026
  8. v0.44.1Oct 20, 2026
  9. v0.43.2Oct 19, 2026
  10. v0.42.0Oct 19, 2026
  11. v0.41.0Oct 18, 2026
  12. v0.40.1Oct 17, 2026
  13. v0.40.0Oct 14, 2026
  14. v0.39.0Oct 11, 2026
  15. v0.38.0Oct 10, 2026
  16. v0.36.2Oct 10, 2026
  17. v0.36.1Oct 7, 2026
  18. v0.35.1Oct 6, 2026
  19. v0.34.0Oct 4, 2026
  20. v0.32.0Oct 3, 2026
  21. v0.31.0Oct 3, 2026
  22. v0.30.0Oct 2, 2026
  23. v0.29.0Oct 1, 2026
  24. v0.28.0Sep 28, 2026

評分

已滿足適用檢查項的 40%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。