Design Constraint Validator

io.github.CseperkePapp由 GitHub 帳號 CseperkePapp 發布v2.3.0更新於 Oct 24, 2026

Validate design tokens for accessibility, scales, and design-system constraint consistency.

已驗證STDIO僅桌面開發者工具媒體與設計

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓助理依無障礙、比例與門檻限制驗證設計權杖,並解釋驗證結果。

可以做什麼
驗證設計權杖(內嵌或來自檔案),檢查 WCAG 對比度、門檻、順序與跨軸限制,可輸出彙總表,違規時以非零狀態結束。解釋單一權杖的來源、別名、相依項目與被相依項目及別名鏈。匯出權杖相依圖的節點與邊。列出給定輸入下生效的限制。把違規轉成白話說明及機器可讀事實。為違規計算一個經驗證的滿足值,但不寫入任何內容。
適用情境
適合在設計系統或權杖集上工作時使用,讓助理檢查對比度、字體與間距層級以及政策門檻,並解釋某個權杖為何不通過。它關注值之間的關係,而不是 JSON 結構本身。
執行需求
以本機程序透過 stdio 執行,從 npm 套件 design-constraint-validator 安裝;需要 Node.js 18 或更新版本並支援 ESM。未宣告驗證、環境變數或標頭。它會從工作目錄讀取權杖 JSON 與選用的設定檔(例如 dcv.config.json)。
安裝前請注意
六個工具都描述為唯讀並回傳 JSON,建議不會自動套用,權杖的修改需由你自行完成。內建的 WCAG 與門檻預設值針對隨附範例的權杖 id,驗證自己的權杖名稱時應將其停用。npm 上單獨的 dcv 指令名稱屬於無關的套件,一次性執行請使用完整套件名稱。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

Design Constraint Validator (DCV)

Mathematical constraint validator for design systems — ensuring consistency, accessibility, and logical coherence.

[npm version] [npm downloads] [CI] [SBOM] [Supply Chain Security] [License: MIT] [Node]

Design Constraint Validator (DCV) validates design constraints across token sets and styles:

  • ✅ Accessibility: WCAG text contrast, perceptual lightness floor/ceilings
  • ✅ Order & Monotonicity: increasing typography scales, spacing hierarchies
  • ✅ Thresholds & Policies: min/max ranges, cross-axis guards (size × weight × contrast)
  • ✅ Graph Intelligence: Hasse/poset graph export; "why" explanations with implicated edges

This is not a schema linter; it's a reasoning validator for values and relationships.

[DCV at a glance — one engine with three entry points (CLI, Library API, MCP server) over a shared validation core that flattens tokens, builds the engine, loads constraints, runs plugins, and reports errors/warnings.]

[DCV validation pipeline — token files → flatten & resolve → build engine → load constraints → run plugins → report results; CLI, API, and MCP all use the same flow.]


Installation

bash
# Local (recommended)npm i -D design-constraint-validator
# One-off run, no install (the bin name `dcv` belongs to an unrelated package)npx design-constraint-validator --help

After a local install, the shorter dcv bin is available (e.g. npx dcv --help).

Requirements: Node.js ≥ 18.x (ESM)


Quick Start

DCV validates your tokens against your constraints. From an empty directory:

bash
# 1. Your design tokens (DTCG-style "$value")cat > tokens.json <<'JSON'{  "color": {    "text": { "$value": "#888888" },    "bg":   { "$value": "#999999" }  }}JSON
# 2. Your constraints — auto-discovered as dcv.config.json in the cwdcat > dcv.config.json <<'JSON'{  "constraints": {    "enableBuiltInWcagDefaults": false,    "enableBuiltInThreshold": false,    "wcag": [      { "foreground": "color.text", "background": "color.bg", "ratio": 4.5, "description": "Body text on background" }    ]  }}JSON
# 3. Validate (positional path or --tokens; exits non-zero on violations)npx design-constraint-validator validate tokens.json --summary table
# Explain one token (the tokenId is required)npx design-constraint-validator why color.text --tokens tokens.json --format table
# Export the dependency graphnpx design-constraint-validator graph --tokens tokens.json --format mermaid > graph.mmd

These one-offs use the full package name because the bare dcv bin name on npm belongs to an unrelated package. After npm i -D design-constraint-validator, use the shorter npx dcv ….

Example output (validate):

text
validate: 1 error(s), 0 warning(s)ERROR wcag-contrast  color.text|color.bg @ Body text on background — Contrast 1.24:1 < 4.5:1scope   rules  warnings  errors------  -----  --------  ------global  1      0         1

Exit code is 1 when violations are found, 0 when clean (use --fail-on off to always exit 0). The built-in WCAG/threshold defaults target the bundled example token ids, so disable them (as above) when validating your own token names.


Programmatic API

ts
import { validate } from 'design-constraint-validator';
// Synchronous. Point at files, or pass `tokens` / `constraints` inline.const result = validate({  tokensPath: './tokens.json',  configPath: './dcv.config.json', // omit to auto-discover dcv.config.json in the cwd});
if (!result.ok) {  for (const v of result.violations) {    console.log(`[${v.ruleId}] ${v.message}`);  }  process.exitCode = 1;}

See API Reference for complete programmatic usage.


Use from AI agents (MCP)

DCV ships a second binary, dcv-mcp, that exposes the validator over MCP stdio for agent clients. Add it to a Claude Desktop or generic MCP client config like this:

json
{  "mcpServers": {    "dcv": {      "command": "npx",      "args": ["-y", "--package", "design-constraint-validator", "dcv-mcp"]    }  }}

The server exposes six read-only, JSON-returning tools:

  • validate - validate inline tokens or a tokensPath against inline constraints or a config file.
  • why - explain provenance, aliases, dependencies, dependents, and alias chain for one token id.
  • graph - return token dependency nodes and edges.
  • list-constraints - enumerate the active constraints (WCAG pairs, thresholds, order/lightness scales, cross-axis) for the given input.
  • explain - turn a violation into plain-English text plus machine-readable facts.
  • suggest-fix - compute a verified satisfying value for a violation (WCAG color, threshold/monotonic boundary) without writing anything.

The three derivation tools (list-constraints, explain, suggest-fix) stay read-only — they return suggestions; applying them is up to you (dcv set / dcv patch). See AI Guide for the full agent loop.

Tool failures are returned as structured JSON: { "ok": false, "error": { "code": "...", "message": "..." } }.


Documentation

For Everyone

For Users

For Developers

Additional Resources


Why Constraints, Not Conventions?

Conventional linters catch schema issues ("has a value, has a type"). DCV enforces relationships that matter to users and brand integrity:

  • Legible contrast under all themes and states
  • Proper hierarchical spacing/typography (monotonic scales)
  • Coherent cross-axis behavior (e.g., weight increases with size where needed)
  • Policy conformance (AA/AAA, internal thresholds)

This transforms tokens from "bags of numbers" into a formal design system.

[What DCV checks — five plugin families: WCAG contrast, monotonic order, lightness ordering, thresholds, and cross-axis rules; every plugin returns a structured issue (rule, level, message, involved tokens, metadata).]


Comparison: Schema Linters vs DCV

FeatureSchema LintersDCV
ValidatesJSON structure, typesMathematical relationships, accessibility
CatchesMissing fields, wrong typesContrast violations, hierarchy breaks
PurposeFormat complianceDesign system integrity
ExamplesDTCG schema validatorWCAG checks, monotonic scales

[Mathematical Integrity for Design Systems — the DCV engine: the three core constraint types (accessibility & contrast, monotonic & lightness ordering, thresholds & cross-axis rules), one engine with three interfaces (CLI, library API, MCP server), and the difference between schema linters (format compliance) and DCV (mathematical relationships / design-system integrity).]

DCV is not affiliated with Anima's design-tokens-validator (schema-focused).


Input Formats

DCV accepts token JSON (flat or nested) and optional policy JSON. Adapters normalize common ecosystems:

  • Style Dictionary - See examples/style-dictionary/
  • Tokens Studio JSON - See examples/tokens-studio/
  • DTCG (Design Tokens Community Group) — reads the 2025.10 stable spec (structured sRGB colors, structured dimensions, {alias} references, $extensions passthrough; non-sRGB spaces warn rather than mis-calculate; composite types out of scope). See examples/dtcg/

Full adapter documentation: Adapters


DCV & DecisionThemes

DCV is the standalone validation engine — use it for any token system.

DecisionThemes (coming 2026) is a complete design system framework built on DCV:

  • 5-axis decision model (Tone, Emphasis, Size, Density, Shape)
  • VT/DT pipeline (Value Themes + Decision Themes → deterministic CSS configs)
  • Studio UI + Hub marketplace for sharing Decision Systems

DCV powers DecisionThemes' validation layer — but works perfectly standalone. Preview: www.decisionthemes.com


Method & Prior Art

The Design Constraint Validator engine is based on a theming and validation method published as defensive prior art.

To understand the underlying architecture (Decision Themes / Value Themes, deterministic compute, post-compute validation and receipts):

These documents keep the method openly implementable and prevent patent lock-up.


Security & Supply Chain

SBOM (Software Bill of Materials)

DCV generates CycloneDX-compliant SBOMs for supply chain transparency:

  • CI Builds: SBOM artifacts on every CI run (90-day retention)
  • Version tags: SBOM artifacts for release tags
  • GitHub Releases: SBOM files (JSON + XML) attached when a GitHub Release is created
  • Manual: Run npx @cyclonedx/cyclonedx-npm in project root

Download:


Roadmap

  • Plugin API for custom constraints
  • VS Code diagnostics (inline explain)
  • Cross-axis packs (typography × weight × contrast)
  • Signed / attestable receipts — dcv validate --receipt already emits environment + input content hashes today; cryptographic signing is the roadmap part
  • UI graph explorer (node inspector, violations focus)

Philosophy

Constraints, not conventions.

Design systems need mathematical guarantees. This validator:

  1. Enforces relationships - Typography hierarchies, color progressions
  2. Validates accessibility - WCAG contrast with alpha compositing
  3. Explains violations - Provenance tracing shows why rules fail
  4. Scales with complexity - Incremental validation of 1000s of tokens

Related Projects

This is the core validation engine. For a complete decision-driven design system with a 5-axis framework (Tone, Emphasis, Size, Density, Shape) and theme configurator UI, see DecisionThemes (coming soon).


Contributing

Contributions welcome! See CONTRIBUTING.md


License

MIT © Cseperke Papp

來源:README.md,提交 be0a35f

工具

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

版本歷史

1
  1. v2.3.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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