<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Orvain UI]]></title><description><![CDATA[Orvain UI]]></description><link>https://orvain.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 22:11:24 GMT</lastBuildDate><atom:link href="https://orvain.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Stop your AI hard-coding hex colours. Give it your design tokens over MCP]]></title><description><![CDATA[AI coding tools write #3b82f6 and 10px where your design system has tokens. A small MCP server gives them the real tokens and checks their CSS.]]></description><link>https://orvain.hashnode.dev/stop-your-ai-hard-coding-hex-colours-give-it-your-design-tokens-over-mcp</link><guid isPermaLink="true">https://orvain.hashnode.dev/stop-your-ai-hard-coding-hex-colours-give-it-your-design-tokens-over-mcp</guid><category><![CDATA[CSS]]></category><category><![CDATA[AI]]></category><category><![CDATA[mcp]]></category><category><![CDATA[Design Systems]]></category><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Tue, 01 Dec 2026 18:37:55 GMT</pubDate><content:encoded><![CDATA[<p>Ask an AI coding tool for a button in your app and you will often get this:</p>
<pre><code class="language-css">.save {
  background: #3b82f6;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
}
</code></pre>
<p>It renders, and it looks close. But your brand blue is <code>#2f6fed</code>, your spacing scale has no 10px step, your buttons use a 6px radius, and none of it points at a token. The next time someone changes the accent colour or adds a dark theme, this button stays behind.</p>
<p>The model didn't pick <code>#3b82f6</code> for any reason specific to you. It's one of the most common blues in public code, so it is the model's most likely guess. It has never seen your token file.</p>
<p>In <a href="https://dev.to/ozzy_design/your-ai-keeps-inventing-component-props-give-it-your-design-system-over-mcp-1mli">an earlier post</a> I put a component library's props behind a small MCP server so the assistant stops inventing them. This post does the same for design tokens: one JSON file, three tools, about 85 lines.</p>
<h2>Why "use our tokens" in a rules file doesn't stick</h2>
<p>Most teams try a line in <code>.cursorrules</code> or <code>AGENTS.md</code>: "Always use design tokens, never raw hex values." The model agrees and then writes <code>#3b82f6</code> anyway, because the rule tells it <em>what not to do</em> without telling it <em>what the token is called</em>. To follow the rule it needs the actual names and values, at the moment it is writing the style.</p>
<p>Pasting the whole token file into the prompt works for a small system and falls over for a real one: hundreds of entries, most of them irrelevant to the current task, taking context from the work.</p>
<p>A tool fits better. The assistant asks for the tokens it needs, and it can check its own CSS before handing it to you.</p>
<h2>Step 1: the tokens</h2>
<p>Use the <a href="https://www.designtokens.org/">Design Tokens Community Group format</a> (<code>$value</code>, <code>$type</code>), which Figma variable exporters, Style Dictionary and Tokens Studio can all produce:</p>
<pre><code class="language-json">{
  "color": {
    "accent": { "$type": "color", "$value": "#2f6fed", "$description": "Primary actions, links, focus rings" },
    "accent-hover": { "$type": "color", "$value": "#2459c9" },
    "surface": { "$type": "color", "$value": "#ffffff" },
    "text": { "$type": "color", "$value": "#16181d" },
    "text-muted": { "$type": "color", "$value": "#5b6270" },
    "danger": { "$type": "color", "$value": "#d93f3f" }
  },
  "space": {
    "1": { "$type": "dimension", "$value": "4px" },
    "2": { "$type": "dimension", "$value": "8px" },
    "3": { "$type": "dimension", "$value": "12px" },
    "4": { "$type": "dimension", "$value": "16px" },
    "6": { "$type": "dimension", "$value": "24px" }
  },
  "radius": {
    "sm": { "$type": "dimension", "$value": "6px" },
    "md": { "$type": "dimension", "$value": "10px" },
    "full": { "$type": "dimension", "$value": "9999px" }
  }
}
</code></pre>
<p>Save it as <code>tokens.json</code>. The <code>$description</code> on <code>accent</code> is worth copying across your file: it tells the model when to use a token, not just what it is.</p>
<h2>Step 2: the server</h2>
<pre><code class="language-bash">npm i @modelcontextprotocol/sdk zod
</code></pre>
<p><code>server.mjs</code> exposes three tools:</p>
<ul>
<li><code>get_tokens</code> lists tokens with their CSS variable names.</li>
<li><code>find_token</code> turns one raw value into the token to use.</li>
<li><code>check_styles</code> reads a block of CSS and reports every raw colour and pixel value, with a replacement.</li>
</ul>
<pre><code class="language-js">import { readFileSync } from "node:fs";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const tree = JSON.parse(readFileSync(new URL("./tokens.json", import.meta.url), "utf8"));

// Flatten { color: { accent: { $value } } } into [{ name: "color-accent", ... }]
const tokens = [];
(function walk(node, path) {
  if (node &amp;&amp; typeof node === "object" &amp;&amp; "$value" in node) {
    tokens.push({ name: path.join("-"), type: node.$type, value: String(node.$value), description: node.$description });
    return;
  }
  for (const [key, child] of Object.entries(node)) if (!key.startsWith("$")) walk(child, [...path, key]);
})(tree, []);

const cssVar = (t) =&gt; `var(--${t.name})`;
const text = (v) =&gt; ({ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v, null, 2) }] });

const hex = (h) =&gt; {
  const s = h.replace("#", "");
  const f = s.length === 3 ? [...s].map((c) =&gt; c + c).join("") : s;
  return [0, 2, 4].map((i) =&gt; parseInt(f.slice(i, i + 2), 16));
};
const distance = (a, b) =&gt; Math.hypot(...hex(a).map((v, i) =&gt; v - hex(b)[i]));
const px = (v) =&gt; parseFloat(v);

// group: "color", "space" or "radius", picked from the CSS property
function nearest(raw, group) {
  if (/^#(?:[0-9a-f]{3}){1,2}$/i.test(raw)) {
    const best = tokens.filter((t) =&gt; t.type === "color").map((t) =&gt; ({ t, d: distance(raw, t.value) })).sort((a, b) =&gt; a.d - b.d)[0];
    return best &amp;&amp; { token: best.t, exact: best.d === 0 };
  }
  if (/^\d+(\.\d+)?px$/.test(raw)) {
    const pool = tokens.filter((t) =&gt; t.type === "dimension" &amp;&amp; (!group || t.name.startsWith(group)));
    const best = pool.map((t) =&gt; ({ t, d: Math.abs(px(raw) - px(t.value)) })).sort((a, b) =&gt; a.d - b.d)[0];
    return best &amp;&amp; { token: best.t, exact: best.d === 0 };
  }
}

const server = new McpServer({ name: "acme-tokens", version: "1.0.0" });

server.registerTool(
  "get_tokens",
  {
    description: "List the design tokens (colour, space, radius) with their CSS variable names. Call this before writing any styles.",
    inputSchema: { type: z.enum(["color", "dimension"]).optional() },
  },
  async ({ type }) =&gt; text(tokens.filter((t) =&gt; !type || t.type === type).map((t) =&gt; ({ ...t, css: cssVar(t) })))
);

server.registerTool(
  "find_token",
  {
    description: "Given a raw value such as #3b82f6 or 14px, return the design token to use instead.",
    inputSchema: { value: z.string() },
  },
  async ({ value }) =&gt; {
    const hit = nearest(value.trim());
    if (!hit) return text(`No token type matches ${value}.`);
    return text(hit.exact ? `Use ${cssVar(hit.token)} (exact match).` : `No exact token. Closest is ${cssVar(hit.token)} (${hit.token.value}).`);
  }
);

server.registerTool(
  "check_styles",
  {
    description: "Check CSS declarations for raw colours and pixel values. Returns each one with the token to use, or OK.",
    inputSchema: { code: z.string() },
  },
  async ({ code }) =&gt; {
    const problems = [];
    for (const [, prop, value] of code.matchAll(/([a-z-]+)\s*:\s*([^;}]+)/g)) {
      const group = /radius/.test(prop) ? "radius" : /padding|margin|gap/.test(prop) ? "space" : undefined;
      for (const raw of value.match(/#(?:[0-9a-fA-F]{3}){1,2}\b|\b\d+px\b/g) ?? []) {
        const hit = nearest(raw, group);
        problems.push(hit ? `${prop}: ${raw} -&gt; ${cssVar(hit.token)}${hit.exact ? "" : ` (closest, ${hit.token.value})`}` : `${prop}: ${raw} has no token`);
      }
    }
    return text(problems.length ? problems.join("\n") : "OK");
  }
);

await server.connect(new StdioServerTransport());
</code></pre>
<p>Add <code>"type": "module"</code> to <code>package.json</code>.</p>
<p>Two details do most of the work:</p>
<ul>
<li><strong>Matching by property.</strong> <code>padding: 10px</code> and <code>border-radius: 10px</code> need different tokens, so <code>check_styles</code> looks at the property name and only searches the space scale for padding, margin and gap, and only the radius scale for radius.</li>
<li><strong>Closest, not just exact.</strong> A model rarely guesses your exact value. Returning the nearest token, and saying it isn't exact, gives it something to use instead of a dead end.</li>
</ul>
<h2>Step 3: connect it</h2>
<p><strong>Claude Code:</strong></p>
<pre><code class="language-bash">claude mcp add acme-tokens -- node ./mcp/server.mjs
</code></pre>
<p><strong>Cursor</strong>, <code>.cursor/mcp.json</code>:</p>
<pre><code class="language-json">{
  "mcpServers": {
    "acme-tokens": { "command": "node", "args": ["./mcp/server.mjs"] }
  }
}
</code></pre>
<h2>What it returns</h2>
<p>Running <code>check_styles</code> on the button at the top of the post:</p>
<pre><code class="language-text">background: #3b82f6 -&gt; var(--color-accent) (closest, #2f6fed)
color: #fff -&gt; var(--color-surface)
padding: 10px -&gt; var(--space-2) (closest, 8px)
padding: 16px -&gt; var(--space-4)
border-radius: 8px -&gt; var(--radius-sm) (closest, 6px)
</code></pre>
<p>The agent rewrites the block in the same turn:</p>
<pre><code class="language-css">.save {
  background: var(--color-accent);
  color: var(--color-surface);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
}
</code></pre>
<p>Notice <code>color: #fff -&gt; var(--color-surface)</code>. The value matches, but white text on a blue button is not really a "surface". That is a hint your token set wants an <code>on-accent</code> colour. Running the checker over generated code is a quick way to find gaps like that in your own system.</p>
<h2>Limits worth knowing</h2>
<ul>
<li>It reads CSS declarations. For Tailwind arbitrary values (<code>bg-[#3b82f6]</code>) or inline style objects, add a second pattern for those.</li>
<li>Nearest colour here is plain RGB distance. It's fine for catching an off-brand blue. If you need perceptual accuracy, convert to OKLCH first.</li>
<li>It doesn't know intent. It can tell the model a token exists, but naming tokens by role (<code>accent</code>, <code>danger</code>, <code>text-muted</code>) is what lets the model pick the right one.</li>
</ul>
<h2>Where to take it</h2>
<ul>
<li>Generate <code>tokens.json</code> from your Figma variables in CI so the server never drifts from the design file.</li>
<li>Add modes: return light and dark values, so the model knows a token changes per theme and stops writing one-off dark overrides.</li>
<li>Put it next to the component tools from the earlier post. Props plus tokens covers most of what an assistant gets wrong in UI code.</li>
</ul>
<p>I build <a href="https://orvain.dev">Orvain UI</a>, a React and Vue design system whose hosted MCP server serves components, tokens and full block examples together, kept in step with each release (<a href="https://orvain.dev/docs/mcp">how it works</a>). But the 85 lines above are enough to stop the hex codes in your own project this week.</p>
]]></content:encoded></item><item><title><![CDATA[Your AI keeps inventing component props. Give it your design system over MCP]]></title><description><![CDATA[Cursor and Claude Code guess your component API. A 60-line MCP server lets them read it instead, and check their JSX before writing it.]]></description><link>https://orvain.hashnode.dev/your-ai-keeps-inventing-component-props-give-it-your-design-system-over-mcp</link><guid isPermaLink="true">https://orvain.hashnode.dev/your-ai-keeps-inventing-component-props-give-it-your-design-system-over-mcp</guid><category><![CDATA[React]]></category><category><![CDATA[mcp]]></category><category><![CDATA[design system]]></category><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Tue, 01 Dec 2026 18:05:57 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published on <a href="https://dev.to/ozzy_design/your-ai-keeps-inventing-component-props-give-it-your-design-system-over-mcp-1mli">DEV</a>.</em></p>
<p>Ask Cursor or Claude Code for a settings screen built with your own component library and you get something that looks right:</p>
<pre><code class="language-jsx">&lt;Button variant="outline" isLoading={saving}&gt;Save&lt;/Button&gt;
&lt;DatePicker selected={date} onSelect={setDate} /&gt;
</code></pre>
<p>Then the type checker lights up. Your <code>Button</code> has no <code>outline</code> variant, the prop is <code>loading</code>, not <code>isLoading</code>, and your <code>DatePicker</code> takes <code>value</code> and <code>onChange</code> and requires a <code>label</code>. None of those names came from your library. The model predicted them from the hundreds of similar libraries it read during training, because it has never seen yours.</p>
<p>This post shows the fix that has worked best for me: put the component API behind a small <a href="https://modelcontextprotocol.io">Model Context Protocol</a> server, so the assistant asks your library instead of guessing. The full server is about 60 lines and works for any React or Vue design system.</p>
<h2>Why rules files and pasted docs don't hold</h2>
<p>The usual first fix is more text: a <code>.cursorrules</code> file, an <code>AGENTS.md</code>, or a docs page pasted into the chat. It helps for a day. Then three things go wrong:</p>
<ul>
<li><strong>It goes stale.</strong> Someone renames a variant, and the rules file still lists the old one.</li>
<li><strong>It competes for room.</strong> A long API dump shares the context window with the actual task.</li>
<li><strong>It loses arguments.</strong> When your pasted page disagrees with what the model already "knows", nothing says which one wins, so you get a mix of both.</li>
</ul>
<p>What the assistant needs is not a better copy of your API. It needs to ask the API, at the version you have installed, when it is about to use a component.</p>
<h2>What MCP gives you</h2>
<p>MCP is an open protocol for connecting an assistant to tools. A server declares a list of tools, each with a typed input schema. The client (Cursor, Claude Code, Windsurf, VS Code and others) discovers them when it connects, and the model calls them mid-task.</p>
<p>A design system fits this unusually well, because the hard part is already done. Props are typed. Variants are a closed set. Required props are known. You only have to publish that structure.</p>
<h2>Step 1: describe the components</h2>
<p>Start with a manifest. You can write it by hand for a first test, and later generate it from your TypeScript types (<code>react-docgen-typescript</code> or <code>vue-component-meta</code> both work).</p>
<pre><code class="language-json">{
  "Button": {
    "import": "import { Button } from \"@acme/ui\"",
    "props": {
      "variant": { "type": "enum", "values": ["primary", "secondary", "ghost", "danger"], "default": "primary" },
      "size": { "type": "enum", "values": ["sm", "md", "lg"], "default": "md" },
      "loading": { "type": "boolean" },
      "disabled": { "type": "boolean" },
      "onClick": { "type": "function" }
    },
    "required": [],
    "a11y": "Icon-only buttons need aria-label."
  },
  "DatePicker": {
    "import": "import { DatePicker } from \"@acme/ui\"",
    "props": {
      "value": { "type": "Date | null" },
      "onChange": { "type": "function" },
      "min": { "type": "Date" },
      "max": { "type": "Date" },
      "label": { "type": "string" }
    },
    "required": ["value", "onChange", "label"],
    "a11y": "label is required; it names the input for screen readers."
  }
}
</code></pre>
<p>Save it as <code>components.json</code>. Note the <code>a11y</code> line: generated UI most often forgets labels, so it is worth handing the rule over with the props.</p>
<h2>Step 2: the server</h2>
<p>Install the official SDK:</p>
<pre><code class="language-bash">npm i @modelcontextprotocol/sdk zod
</code></pre>
<p>Then <code>server.mjs</code>, with three tools: list the components, describe one, and check a usage before it is written.</p>
<pre><code class="language-js">import { readFileSync } from "node:fs";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const components = JSON.parse(readFileSync(new URL("./components.json", import.meta.url), "utf8"));
const server = new McpServer({ name: "acme-ui", version: "1.0.0" });
const text = (value) =&gt; ({
  content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 2) }],
});

server.registerTool(
  "list_components",
  { description: "List every component in the Acme UI design system.", inputSchema: {} },
  async () =&gt; text(Object.keys(components))
);

server.registerTool(
  "get_component",
  {
    description: "Get the exact import, props, allowed values and accessibility rules for one component. Call this before writing JSX that uses it.",
    inputSchema: { name: z.string() },
  },
  async ({ name }) =&gt; {
    const c = components[name];
    return c ? text(c) : text(`No component named ${name}. Available: ${Object.keys(components).join(", ")}`);
  }
);

server.registerTool(
  "check_usage",
  {
    description: "Check a component's props before writing them. Returns every problem, or OK.",
    inputSchema: { name: z.string(), props: z.record(z.any()) },
  },
  async ({ name, props }) =&gt; {
    const c = components[name];
    if (!c) return text(`Unknown component ${name}.`);
    const problems = [];
    for (const [key, value] of Object.entries(props)) {
      const spec = c.props[key];
      if (!spec) problems.push(`${key} is not a prop of ${name}. Props: ${Object.keys(c.props).join(", ")}`);
      else if (spec.type === "enum" &amp;&amp; !spec.values.includes(value))
        problems.push(`${key}="${value}" is not allowed. Use one of: ${spec.values.join(", ")}`);
    }
    for (const key of c.required) if (!(key in props)) problems.push(`${key} is required.`);
    return text(problems.length ? problems.join("\n") : "OK");
  }
);

await server.connect(new StdioServerTransport());
</code></pre>
<p>Add <code>"type": "module"</code> to your <code>package.json</code> so Node runs it as ESM.</p>
<p>The tool descriptions matter more than they look. "Call this before writing JSX that uses it" is an instruction the model reads every time it sees the tool list, and it is what makes it reach for <code>get_component</code> without being asked.</p>
<h2>Step 3: connect your editor</h2>
<p><strong>Claude Code</strong>, from the project root:</p>
<pre><code class="language-bash">claude mcp add acme-ui -- node ./mcp/server.mjs
</code></pre>
<p><strong>Cursor</strong>, in <code>.cursor/mcp.json</code>:</p>
<pre><code class="language-json">{
  "mcpServers": {
    "acme-ui": { "command": "node", "args": ["./mcp/server.mjs"] }
  }
}
</code></pre>
<p>Restart the editor and the three tools show up in its MCP list.</p>
<h2>What changes</h2>
<p>Here is what <code>check_usage</code> returns for the code at the top of this post:</p>
<pre><code class="language-text">variant="outline" is not allowed. Use one of: primary, secondary, ghost, danger
isLoading is not a prop of Button. Props: variant, size, loading, disabled, onClick
</code></pre>
<pre><code class="language-text">label is required.
</code></pre>
<p>The difference from a linter is when the error lands. A type error in review costs a person a round trip. A <code>check_usage</code> answer costs the agent one retry in the same turn, with the fix spelled out, so the code reaches you already correct.</p>
<p>And once the agent has called <code>get_component</code>, the real prop list is in its context for the rest of the task, so there is far less left to guess.</p>
<h2>Where to take it next</h2>
<ul>
<li><strong>Generate the manifest in CI</strong> from your component types, so it can never drift from the code.</li>
<li><strong>Add tokens.</strong> A <code>get_tokens</code> tool that returns your colour, spacing and radius names stops the model hard-coding <code>#3b82f6</code> where you have <code>--color-accent</code>.</li>
<li><strong>Serve it over HTTP</strong> instead of stdio when a whole team, or several repos, should share one version. The SDK ships a Streamable HTTP transport for that.</li>
<li><strong>Return examples.</strong> A short, correct usage snippet per component teaches composition better than the prop list alone.</li>
</ul>
<h2>A ready-made version</h2>
<p>I build <a href="https://orvain.dev">Orvain UI</a>, a React and Vue design system, and this is the problem that started it. Its hosted MCP server does the above for the whole library: props, variants, tokens, accessibility rules and full block examples, kept in step with each release. The 45 free components are on npm as <code>@orvain/react</code> and <code>@orvain/vue</code>; more on how the server works is in <a href="https://orvain.dev/docs/mcp">the MCP docs</a>.</p>
<p>But the 60 lines above are yours to keep. If your team has a design system, give your assistant a way to ask it.</p>
]]></content:encoded></item></channel></rss>