dimctx
# dimctx
> **dimctx = dimensional modeling context provider**
> 一个本地 MCP server,让你的 AI 编码助手在写数仓代码时拥有维度建模的判断力。
[](LICENSE)
## 它解决什么
AI 写 SQL/DDL 时会瞎编建模决策:分不清事实和维度、猜不准粒度、不知道哪些维度该跨表一致。
`dimctx` 把这些判断交给确定性引擎 + 你自己的方法论语料。
五个工具:
| 工具 | 作用 |
|---|---|
| `analyze_table` | 判定表角色(fact/dimension)、粒度键、SCD 建议、总线矩阵格值 |
| `search_canon` | 检索**你自备**的建模语料(本地 markdown) |
| `bus_matrix` | 总线矩阵查询(单表格值 / 单维度实现 / 全库概览) |
| `measure_sql` | 度量下游取数复杂度(CASE WHEN / JOIN 深度 / 子查询 / 聚合嵌套) |
| `check_conformed_facts` | **一致性事实检查**:同名度量在多张事实表出现时,定义/单位/过滤/时间口径必须完全一致;不兼容则按原典须改名 |
## 三步接入
```bash
# 1) 配置(可选,缺省也能跑:只是语料检索为空)
export DIMCTX_ATLAS=/path/to/atlas.json # 工程表图谱(可选)
export DIMCTX_CANON_DIR=/path/to/markdown # 你自备的建模语料(可选)
# 2) 在 IDE 的 MCP 配置里加一条
# VS Code (mcp.json) / Cursor (.cursor/mcp.json) / Continue (config.yaml)
{"command": "uvx", "args": ["dimctx"]}
# 3) 让 AI 用它
# 「用 dimctx 看看 dt_batch 是什么表、粒度是什么」
```
## 数据边界(重要)
- **纯本地 stdio**:无网络出口、无遥测、无云服务、不做托管;
- **不打包任何第三方内容**:语料由你自备(详见 [`docs/DATA-POLICY.md`](docs/DATA-POLICY.md) 与 [`NOTICE`](NOTICE));
- 未配置语料时 `search_canon` 返回空并提示配置,**不会报错、不会联网索取**。
## 开发
```bash
uv run --with pytest --with pydantic python -m pytest tests/ -q # 19 passed
```
## 许可
代码 AGPL-3.0-or-later(见 [LICENSE](LICENSE))。本项目与 Kimball Group 无关联、未获其背书;
文档中提及 Kimball 方法论属指名性合理使用(nominative fair use)。
TDQS
Scored across 5 tools
Most tools have clearly distinct purposes: analyze_table for table role/grain/SCD analysis, search_canon for methodology lookup, bus_matrix for querying existing matrix data, check_conformed_facts for fact consistency, and measure_sql for SQL complexity. There is minor overlap between analyze_table (which suggests bus matrix cell values) and bus_matrix (which retrieves them), but the descriptions differentiate them adequately.
All names use snake_case and four of five follow a verb_noun pattern (analyze_table, search_canon, check_conformed_facts, measure_sql). The exception is bus_matrix, which is noun-only, but the overall convention remains predictable.
Five tools is well-scoped for a focused Kimball dimensional modeling assistant. Each tool covers a distinct analytical operation without redundancy or excessive surface area.
The surface covers core dimensional modeling workflows: table analysis, methodology retrieval, bus matrix queries, conformed fact checks, and SQL complexity measurement. Minor gaps remain, such as explicit conformed dimension checking or SCD implementation guidance beyond what analyze_table provides, but these are manageable workarounds.