Primitiv
Primitiv
The design contract layer for your agents.
Retrieval gives you data. Reconciliation gives you truth.
Primitiv sits above your design sources — Figma, codebase, Storybook, token files — scans them, reconciles conflicts between them, and exposes a single machine-readable contract via MCP. Any agent that connects gets one authoritative answer before it builds. Your code never leaves your machine.
Quick start
npx @ai-by-design/primitiv init # detect your stack, write config + MCP registration
npx @ai-by-design/primitiv build # scan sources, resolve conflicts, write the contract
npx @ai-by-design/primitiv serve # start the MCP serverinit writes a .mcp.json to your project root, so Cursor, Claude Code, Codex, Windsurf, and any other MCP-compatible tool pick up the server without manual config.
If your project is on GitHub, init also installs .github/workflows/primitiv-verify.yml — a workflow that runs primitiv verify on every PR and push. Pair it with branch protection on your default branch and the merge is blocked when an agent ships UI that breaks the contract.
From here, every agent that builds UI calls get_design_context first and gets your resolved design contract back.
Related MCP server: uxship
The problem
Design-relevant information is spread across Figma, tokens, Storybook, and the codebase itself — sources that were never meant to stay in sync. Humans reconcile the drift by inference; agents can't, so they fall back on training-data patterns and build UI that works but doesn't fit.
Primitiv resolves it: one contract, built from every source, served live to every agent.
How it works
Any source Primitiv Your agent
Figma ──┐
Codebase ──┤──► scan ──► reconcile ──► contract ──► MCP ──► Cursor / Claude Code / Codex / Windsurf / any MCP-compatible tool
Storybook ──┤
Tokens file ──┤
Any adapter ──┘Scan — Primitiv ingests from any configured source via adapters
Reconcile — Conflicts between sources are surfaced and resolved according to your governance configuration
Infer — Design rules are extracted from actual codebase patterns and written into the contract
Contract — A single
primitiv.contract.jsonis written as the canonical referenceMCP — Agents call
get_design_contextbefore building and receive the resolved contract
Install
npm install @ai-by-design/primitiv
# or
bun add @ai-by-design/primitivCLI
Command | Description |
| Detect your project and generate |
| Scan sources, resolve conflicts, write the contract |
| Start the MCP server |
MCP tools
Tool | Description |
| Get all tokens, components, conflicts, and inferred rules. Pass |
| Look up a specific token by name |
| Look up a specific component and its props |
| Get unresolved conflicts between sources |
| Get the design rules Primitiv has extracted from your codebase patterns |
Primitiv works with any tool that speaks MCP — it is not tied to a specific editor or agent ecosystem.
Using Primitiv across multiple projects
Primitiv runs one MCP server process per project, each pointed at that project's contract. This is intentional — each project has its own resolved contract, and there is no global shared state.
primitiv init writes a project-scoped MCP config automatically. Do not add Primitiv to your editor's global MCP config — if you do, the global server will keep serving one project's contract regardless of which project your agent is working in.
Per-editor setup
Editor | Project-level config | Global config (avoid for Primitiv) |
Claude Code |
|
|
Cursor |
|
|
Windsurf |
|
|
Zed |
|
|
primitiv init detects which editor config exists and writes to the right project-level file. If none exists, it creates .mcp.json (works with Claude Code and most modern editors).
Switching between projects
Each project needs its own primitiv init + primitiv build. When you switch projects in your editor, the project-scoped MCP config is loaded automatically — no manual switching needed, as long as you haven't added Primitiv to the global config.
If you already added Primitiv to your global editor config, remove it:
# Cursor — edit ~/.cursor/mcp.json and remove the "primitiv" entry
# Windsurf — edit ~/.codeium/windsurf/mcp_config.json and remove "primitiv"Stale or mismatched contract warnings
If get_design_context returns a warnings array, stop and resolve before proceeding:
STALE CONTRACT— the contract is outdated. The warning includes the exact command to rebuild, e.g.:npx @ai-by-design/primitiv build /path/to/your/primitiv.config.jsCONTRACT MISMATCH— the server is serving a contract from a different project. This usually means Primitiv is in your global editor MCP config. Remove it from there and re-runprimitiv initin the correct project.
CI / GitHub Actions
primitiv init auto-installs .github/workflows/primitiv-verify.yml when the project's remote is on GitHub. The workflow runs on every pull request and push to your default branch and fails the check when the contract is stale or has unresolved conflicts.
To turn the failed check into a hard merge gate, enable branch protection on the default branch — init prints the exact settings URL after install (https://github.com/<owner>/<repo>/settings/branches).
The workflow uses npx --yes @ai-by-design/primitiv verify, so it works regardless of your project's package manager. Two notes:
Monorepos — the workflow runs at repo root. If
primitiv.config.jslives in a subdirectory, add aworking-directory:to the verify step in the generated YAML.Pinning —
npx --yes @ai-by-design/primitivfetches the latest version. To pin, edit the workflow'srun:line tonpx --yes @ai-by-design/primitiv@1.4.0 verify(or your chosen version).
The workflow is idempotent — re-running primitiv init refreshes the block between # <!-- primitiv --> markers, preserving any content you've added outside them.
Configuration
// primitiv.config.js
module.exports = {
sources: {
codebase: {
root: "./src",
patterns: ["**/*.css", "**/*.ts", "**/*.tsx"],
ignore: ["node_modules", "dist", ".next"]
},
// figma: {
// token: process.env.FIGMA_ACCESS_TOKEN,
// fileId: "your-figma-file-id"
// },
// storybook: {
// url: "http://localhost:6006"
// }
},
governance: {
sourceOfTruth: "codebase", // "codebase" | "figma" | "storybook" | "manual"
onConflict: "warn" // "error" | "warn" | "auto-resolve"
},
output: {
path: "./primitiv.contract.json"
}
}Contributing
Local setup
git clone https://github.com/AI-by-design/primitiv.git
cd primitiv
bun install
bun run buildRunning in development
To run the MCP server against local source without a build step, point your MCP config directly at the source file. Bun runs TypeScript directly so changes are picked up on the next server restart:
{
"mcpServers": {
"primitiv": {
"command": "bun",
"args": ["/path/to/primitiv/src/cli.ts", "serve", "./primitiv.config.js"]
}
}
}The MCP server also hot-reloads primitiv.contract.json automatically whenever primitiv build runs.
Build commands
bun run build # Compile TypeScript → dist/
bun run dev # Run src/index.ts directly via ts-node
bun run lint # ESLint on src/**/*.tsArchitecture
src/
├── cli.ts Entry point — routes init / build / serve
├── index.ts Exports build() and serve()
├── types.ts All shared interfaces — define types here, not inline
├── scanner/ CodebaseScanner — extracts tokens and components from the filesystem
├── sources/ Source adapters — Figma (Variables API), Storybook (manifest)
├── contract/ ContractBuilder — merges sources, detects conflicts, applies governance
├── inferrer/ inferRules() — derives design rules from token and component patterns
├── mcp/ PrimitivMCPServer — loads the contract and registers MCP tools
└── init/ init() — detects framework and writes primitiv.config.jsSee CLAUDE.md for conventions on adding new sources, MCP tools, and types.
Releases
Releases are managed by Release Please. Commit messages must follow the Conventional Commits format:
Prefix | Effect |
| Patch release (0.1.0 → 0.1.1) |
| Minor release (0.1.0 → 0.2.0) |
| Major release |
| No release |
On merge to main, Release Please opens a release PR. Merging that PR tags the release and publishes to the package registry automatically.
Design principles
Source-agnostic — Primitiv does not assume any particular toolchain. Sources are configured via adapters, and new adapters can be added for any system that holds design-relevant information. Works with Figma, Storybook, token files, raw codebase — or any combination.
Contract over documentation — The output is a machine-readable contract, not human-readable documentation. It is designed to be consumed by agents, not read by people.
Active reconciliation, not retrieval — Primitiv does not answer questions about what exists in your codebase. It resolves conflicts between sources and produces something authoritative. The distinction matters: retrieval gives you data, reconciliation gives you truth.
Inferred before prescribed — Primitiv surfaces the rules your codebase is already following before asking you to write any. The inferred rules are a starting point, not a final answer.
Governance is explicit — When sources conflict, the resolution is not silent. Conflicts are surfaced, logged, and resolved according to rules you define. Nothing is resolved by guessing.
Local-first and private — Primitiv runs entirely on your machine. Your codebase is never sent to an external service. The contract is a local file; the MCP server is a local process.
Incrementally adoptable — Start with a single source. Add more as needed. The contract remains valid at any level of completeness.
Roadmap
Codebase scanner (CSS variables, TypeScript tokens, React components)
Contract builder with conflict detection
MCP server with 5 tools
primitiv init— project detection and config generationInferred rules — extract design rules from actual codebase patterns
AGENTS.md / CLAUDE.md integration —
primitiv initwrites agent instructions to the project's agent config file, ensuringget_design_contextis called before any UI build without manual promptingProject-scoped MCP config —
primitiv initwrites a project-level MCP config so the server is scoped to the current project, not a global user-level serverbuild-componentskill —primitiv initinstalls a Claude Code slash command that queries the contract before building any UI componentRemediation steps on conflicts — conflicts include a
suggestedFixandactionableflag so agents know exactly what to do, not just what's wrongPublished to npm — available as
@ai-by-design/primitivFigma source adapter — scan Figma Variables and components via the Figma REST API
Storybook source adapter — scan components and variants via the Storybook manifest
Source provenance — every token and component in the contract traces back to its origin (file, line number, Figma variable ID, Storybook story ID)
CI enforcement —
primitiv initauto-installs a GitHub Actions workflow that runsprimitiv verifyon every PR; pair with branch protection to block merges on contract driftToken relationships — document how tokens relate and what constraints exist between them
Part of a larger system
Primitiv is the contract layer. It works alongside Design-workflow — a build system for going from idea to working product with agents. Design-workflow gives agents the process. Primitiv gives them the source of truth.
License
MIT
Available Tools
9 toolsfind_componentsBRead-only
Find a bounded component shortlist sorted by exact ID. Filters combine with AND; intents match any by default. Inspect coverage and broaden filters or search unclassified records before concluding no reusable component exists. Continue using nextCursor with the same filters. Read-only.
Inputs: kind, level, limit, scope, +4 more.
get_componentARead-only
Look up a component by name or id. Read-only, no side effects. Pass context (your current working file or directory) so same-name components resolve by path scope. Returns the component JSON (with its id) when the lookup resolves to exactly one component, or an error listing available names if not found. Detail is opt-in: pass 'api' for the component's declared prop contract, 'usage' for static JSX-site counts and observed prop values, 'relationships' for sorted outgoing uses and derived incoming usedBy counts, 'conflicts' for bounded source-conflict evidence, or 'all' for every projection. These are static source-site facts, never runtime frequency. When several components share the name and neither governance nor scope decides, returns { ambiguous, matches, instruction } — follow the instruction: match each candidate's rationale.when against the user's intent, and if that doesn't decide, ask the user; never pick arbitrarily. Use this when you need implementation details for a known component to reuse it rather than recreate it. For a list of all components, use get_design_context with category 'components' instead.
Inputs: name (required), limit, detail, offset, +1 more.
get_component_catalogARead-only
Inspect component counts, classification coverage, supported discovery filters, source/guidance health, and the loaded snapshot. Read-only. No full name inventory.
Inputs: no named parameters.
get_component_contextARead-only
Inspect an exact component ID in the selected snapshot, with API, guidance, relationships and source sections. Follow nextCursor until complete. JSON-fragment continuations must be concatenated in order then JSON-parsed. Observed usage is static evidence; pairings are advisory. Restart discovery after snapshot-changed. Read-only.
Inputs: id (required), snapshotId (required), cursor, sections.
get_conflictsARead-only
Get a bounded, repeatable page of design-system conflicts. Read-only, no side effects. Filter by type, status, scope, exact component name or durable component ID, and a structured fieldPath prefix. Use offset and limit for pagination (default 25, maximum 100). For resolved design values, use get_token or get_component instead.
Inputs: type, limit, scope, offset, +3 more.
get_design_contextARead-only
Get the resolved design system context before building UI. Read-only, no side effects. Default (no category) returns a JSON summary of token counts, component names, conflict counts, comparison diagnostic counts, and contract metadata. Pass category: 'all' | 'tokens' | 'components' | 'conflicts' | 'diagnostics' to get detail. Pass tokenCategory to filter tokens: colors, spacing, sizes, typography, borderRadius, shadows, zIndex, breakpoints, motion (unknown/aliased categories return an actionable error, not a silent empty result). Use this as the first call to understand what exists. For lookups by name, use get_token or get_component instead.
Inputs: limit, offset, category, tokenCategory.
get_inferred_rulesARead-only
Get the design rules inferred from your codebase patterns. Read-only, no side effects. Returns JSON with a list of rules including category, pattern, and confidence, or an error if no rules have been generated yet. Pass category to filter: spacing, colors, typography, borderRadius, naming, components. Omit category to get all. Use this to understand implicit conventions the codebase follows. For explicit design token values, use get_token. For source conflicts, use get_conflicts.
Inputs: category.
get_tokenARead-only
Look up a specific design token by name. Read-only, no side effects. Returns the token's name, value, and category, or an error if not found. Pass category to narrow search: colors, spacing, sizes, typography, borderRadius, shadows, zIndex, breakpoints, motion (aliases like 'color'/'radius'/'z-index' are normalized). Omit category to search all. Use this when you know the token name. For a broad overview of all tokens, use get_design_context with category 'tokens' instead.
Inputs: name (required), category.
get_violationsARead-only
Get hardcoded token values: literals in source code typed inline instead of referencing a design token, bypassing the contract. Read-only, no side effects. Returns JSON with a count, suggestion-coverage stats, and a list with file:line:column, the captured literal, the surrounding utility (e.g. 'bg-[#ff0000]'), and an optional smart-match suggestion when a contract token has the same value. Pass category to filter: 'all' | 'colors' | 'spacing' (hardcoded values are only detected for these). Call this BEFORE generating UI with literal values — prefer the suggested token over a hardcoded literal. For available tokens to use instead, use get_design_context or get_token.
Inputs: category.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Most tools have distinct purposes, but there are real overlaps: get_component vs get_component_context (both inspect a single component), and get_design_context vs get_component_catalog (both give a system overview). The descriptions mitigate this heavily with explicit cross-references ('for X, use Y instead'), keeping misselection risk low but nonzero.
Eight of nine tools use a clean get_<noun> pattern (get_component, get_token, get_conflicts, get_violations, get_inferred_rules, get_design_context, get_component_catalog, get_component_context). find_components is the lone deviation, but the search-vs-fetch distinction is meaningful and readable.
Nine tools is well-scoped for a read-only design-system inspection server. Each tool covers a distinct facet (catalog, discovery, component detail, tokens, rules, conflicts, violations, context) without redundancy in count.
The surface covers discovery, component lookup, token lookup, inferred rules, conflicts, and violations, giving broad lifecycle coverage for a read-only inspection role. Minor gaps exist (no explicit snapshot-compare or diagnostics tool outside get_design_context), but agents can work around these.
Maintenance
Related MCP Connectors
Serves your design system and coding standards to coding agents, so they stop guessing.
Live React design-system APIs, patterns, and code validation so AI agents build real UI, not slop.
Access and maintain design system docs, tokens, components, skills, and contexts across any project.
Give your agent a real design system: tokens, measured WCAG contrast, and rules to follow.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI coding agents to read the live state of an open Figma file — variables, modes, components, prototype edges and assets — and to export design tokens and code packages for web, iOS, Android, React, Django and Tauri through a user-run loopback bridge with separate read and write gates.2MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to write AI-generated designs into design-tool canvases (MasterGo, Penpot) as native editable layers, and to read canvas selections back out as HTML + Tailwind, design tokens, and SVG assets. Runs locally with progressive tool disclosure and structurally truncated results so large design files stay within an agent's context budget.Apache 2.0
- AlicenseNot gradedqualityCmaintenanceGives AI agents token-efficient, provenance-aware context from scattered design-system knowledge — component specs, guidelines, decision records, research, and team-local overrides — through structured lookup, semantic search, and progressive document disclosure. It also surfaces conflicts and hides superseded content by default, so agents can answer design questions without confidently citing outdated guidance.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to draw on a shared local design canvas — creating frames, shapes, text, vector paths, components, and diagrams alongside a human collaborator — while taking screenshots and running checks for contrast, overflowing text, and missing design tokens, then exporting results as HTML, React components, or SVG.1MIT