
Canonic
io.github.mischuh由 GitHub 账号 mischuh 发布v0.46.2更新于 Nov 7, 2026
The Open Context Layer for Data Agents
概览
Canonic 是一个本地上下文层,让 AI 助手通过受治理的指标定义、编译后的 SQL 和护栏来查询数据仓库。
- 可以做什么
- 把指标和维度解析为规范定义,并针对数据仓库编译只读 SQL
- 执行查询和原始 SQL,返回结果并附带解析出的定义、触发的护栏、数据新鲜度和信任等级
- 按整体和成员拆解指标在两个周期之间的变化
- 搜索并阅读业务知识页面,其中定义会实时渲染并附带注意事项
- 审阅拟议的上下文变更,并查看服务契约版本
- 适用场景
- 当助手需要基于数据仓库回答数据问题,而你希望强制执行已商定的定义、强制过滤器和信任元数据而不是靠猜测时使用。它适合已在 dbt、Looker、Metabase 或 Notion 中维护指标、并希望智能体复用这些语义的团队。
- 运行要求
- 通过 uvx 或 pip 作为本地进程运行,需要 Python 3.13 或更高版本。需要一个已连接数据源的 canonic 项目目录,可通过设置向导配置。基于服务器的数据库和可选的 LLM 起草功能需要凭据,通过环境变量或客户端配置的 env 字段提供;本地 SQLite、DuckDB、CSV 和 Parquet 数据源无需网络。
安装
在 SourceWeft 中
- 打开 控制台中的 Canonic,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
canonic
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:
This total includes two refunded orders ($260), a confident, well-formatted number that's off by 6.4%.
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_sourceandmin_trustare 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 decomposeand the MCP tooldecompose_changeattribute 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 auditandcanonic status, and an accuracy harness (canonic assert,canonic eval baseline) turns "trustworthy" into something you can check. Instrumentation
How it works
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:
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.
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).
The fastest path uses local connectors, no server, no network. Point at a SQLite .db or DuckDB .duckdb/CSV/Parquet file:
[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:
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:
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:
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
- 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
ConnectorFactoryby capability (introspect_schema,run_read_only_sql,extract_definitions,extract_evidence), and short-lived credentials plug in through theCredentialProviderRegistry. - Stable contract. The serving contract is versioned (the
contract_infoMCP tool,CONTRACT_CHANGELOG.md), andtests/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.yamlconfig 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版本历史
24- v0.46.2最新Nov 7, 2026
- v0.46.1Oct 29, 2026
- v0.46.0Oct 23, 2026
- v0.45.5Oct 21, 2026
- v0.45.4Oct 21, 2026
- v0.45.1Oct 20, 2026
- v0.45.0Oct 20, 2026
- v0.44.1Oct 20, 2026
- v0.43.2Oct 19, 2026
- v0.42.0Oct 19, 2026
- v0.41.0Oct 18, 2026
- v0.40.1Oct 17, 2026
- v0.40.0Oct 14, 2026
- v0.39.0Oct 11, 2026
- v0.38.0Oct 10, 2026
- v0.36.2Oct 10, 2026
- v0.36.1Oct 7, 2026
- v0.35.1Oct 6, 2026
- v0.34.0Oct 4, 2026
- v0.32.0Oct 3, 2026
- v0.31.0Oct 3, 2026
- v0.30.0Oct 2, 2026
- v0.29.0Oct 1, 2026
- v0.28.0Sep 28, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。