Semantic layers, compilation, and MCP
Enterprise analytics stacks rarely store business definitions in one place. Metric logic drifts across Markdown agent instructions, dbt schema.yml / manifest.json, Snowflake Semantic Views, Apache Ossie models, and LookML views. contextlift lints all five together at $0, compiles proven definitions back into your semantic layer, and serves the exact verified context over MCP.
Zero-LLM Cross-Layer Conflict Radar (lint)
Pass your Markdown spec/ alongside any combination of semantic layer sources:
contextlift lint \
--spec spec/ \
--dbt dbt_project/ \
--snowflake-semantic semantic_views/finance.yaml \
--ossie models/ossie.yaml \
--lookml looker_repo/ \
--db warehouse.duckdb
Without calling a single LLM, lint normalizes metric formulas, filter predicates, and accepted enum values across every supplied layer and refuses on contradictions:
- Cross-layer metric conflict: e.g.,
dbtdefinesactive_arrincluding trial accounts whilespec/rules/00-finance.mdfiltersstatus = 'active'. - Cross-layer enum conflict: e.g.,
dbtaccepted_valueslists['ACTIVE', 'CHURNED']whilespec/or the live warehouse (--db) uses lowercase'active'. - Multi-domain peer conflicts: in a multi-domain repo (
spec/domains/finance/,spec/domains/sales/),lint --spec spec/ --domain financevalidates the Finance domain plus org rules while warning whenever Sales defines the same term differently.
Supported semantic layer inputs
| Layer | Flag | Files read | Extra required |
|---|---|---|---|
| Markdown spec | --spec DIR | rules/*.md, schema/, authored/, vocabulary/, examples/, relationships.yaml | core (.json) or [yaml] |
| dbt | --dbt PATH | dbt_project.yml directory, schema.yml / MetricFlow YAML, or target/manifest.json | [yaml] (or core for manifest.json) |
| Snowflake Semantic View | --snowflake-semantic PATH | Semantic View YAML or JSON (tables, metrics, relationships, verified_queries) | [yaml] (or core for .json) |
| Apache Ossie | --ossie PATH | Ossie semantic model YAML or JSON | [yaml] (or core for .json) |
| LookML | --lookml PATH | LookML project directory (*.model.lkml, *.view.lkml, *.explore.lkml) | [lookml] |
Bidirectional compilation (compile)
Once a round proves your spec/ works on held-out SQL, compile it into your downstream semantic layer with verification metadata stamped into the header:
# Snowflake Semantic View YAML
contextlift compile \
--spec spec/ \
--target snowflake-yaml \
--attestation .contextlift/attestation.json \
--out semantic_views/finance.yaml
# dbt schema & MetricFlow YAML
contextlift compile --spec spec/ --target dbt-yaml --out models/metrics.yml
# Apache Ossie YAML (or .json when --out ends in .json)
contextlift compile --spec spec/ --target ossie --out semantic_model.yaml
Honest certification headers: compile checks BOTH the attestation's HMAC integrity AND whether the spec matches the attested arm hash, the verdict is REAL GAIN, and any merge policy passed.
- When all conditions pass: emits
Certified contextlift arm <arm_id>andintegrity=VERIFIED, certified=YES. - When the attestation is
UNDERPOWERED,NOT PROVEN,REAL LOSS, missing, tampered, or the spec changed by even one character: emitsUNVERIFIED contextlift arm <arm_id> (not certified: <reason>)andcertified=NO (<reason>).
Serving certified context over MCP (serve-mcp)
Run the zero-dependency JSON-RPC 2.0 stdio MCP server so production agents and coding assistants read the exact Arm that CI tested:
contextlift serve-mcp \
--spec spec/ \
--attestation .contextlift/attestation.json
serve-mcp speaks strictly over local stdin/stdout (supports both LSP Content-Length framing and newline-delimited JSON-RPC 2.0), binds no network port, and exposes six tools:
| Tool | Purpose |
|---|---|
search_schema | Search table and column descriptions by keyword. |
get_metric | Look up a business metric or glossary term definition. |
get_join_path | Find join relationships involving one or two tables. |
list_rules | List business reporting rules, optionally filtered by topic. |
lookup_verified_example | Match a natural-language question against verified SQL examples. |
get_attestation_status | Return arm_id, spec_sha256, attested_spec_sha256, attestation_verified, attestation_arm_matches, certified, certification_reason, verdict, and safety. |
Claude Code configuration (.mcp.json)
{
"mcpServers": {
"contextlift": {
"command": "contextlift",
"args": [
"serve-mcp",
"--spec", "spec/",
"--attestation", ".contextlift/attestation.json"
]
}
}
}
Cursor configuration (.cursor/mcp.json)
{
"mcpServers": {
"contextlift": {
"command": "contextlift",
"args": [
"serve-mcp",
"--spec", "spec/",
"--attestation", ".contextlift/attestation.json"
]
}
}
}