PaletteCraft MCP

v0.1.0
io.github.ahmedsaeed1-eng/palettecraft-mcp Checked 2 days ago Published 6 days ago

Deterministic light/dark color tokens and measured contrast checks.

An original, deterministic design-token engine for frontend and mobile development. Start with a brand color and a mood, produce coordinated light and dark semantic palettes, and receive measured contrast checks before using them in a UI. Once this version is published to npm by the repository maintainer, register the pinned local stdio server directly with Codex: Or install the exact release and use the installed command:

Summary extracted from the README.

PaletteCraft MCP

PaletteCraft editorial wordmark

Start with one color. Build a complete design system.

Palette tests GitHub stars MIT license Node.js 20+

Generated light and dark swatches, three real seed and mood combinations

Gallery: these six palettes come from actual runs of the project. The button labels show calculated foreground/background contrast, and each card reports the measured checks for its own theme.

An original, deterministic design-token engine for frontend and mobile development. Start with a brand color and a mood, produce coordinated light and dark semantic palettes, and receive measured contrast checks before using them in a UI.

  • 14 semantic colors per theme, including text, surfaces, buttons, status text, outlines, and focus.
  • 58 tested color pairs per generation: 29 in each theme.
  • Five moods: balanced, calm, vibrant, warm, and neutral.
  • Contrast checking and foreground adjustment with explicit pass/fail.
  • JSON, CSS custom properties, Tailwind CSS v4, and Flutter Material color roles.
  • Local computation only. No hosted service, API key, model, telemetry, arbitrary code execution, or network request from the tools.
  • Genuine MCP stdio via the official TypeScript SDK.

Package installation

Once this version is published to npm by the repository maintainer, register the pinned local stdio server directly with Codex:

codex mcp add palettecraft -- npx --yes palettecraft-mcp@0.1.0

Or install the exact release and use the installed command:

npm install -g palettecraft-mcp@0.1.0
codex mcp add palettecraft -- palettecraft-mcp

The package metadata declares the MCP Registry identity io.github.ahmedsaeed1-eng/palettecraft-mcp. The official registry entry is a separate publication step after npm release; local stdio use does not require it.

Quick start

Prerequisites: Node.js 20+ and an MCP client, such as Codex.

git clone https://github.com/ahmedsaeed1-eng/palettecraft-mcp.git
cd palettecraft-mcp
npm ci
npm run build

Connect the built server to Codex:

codex mcp add palettecraft -- node /absolute/path/to/palettecraft-mcp/dist/server.js

Alternatively configure the server in Codex's user config:

[mcp_servers.palettecraft]
command = "node"
args = ["/absolute/path/to/palettecraft-mcp/dist/server.js"]

Use your real absolute path. On Windows, forward slashes or escaped backslashes work in TOML. See the Codex MCP configuration reference.

Then ask your agent:

Generate a calm palette from #0F766E for my app, check light and dark contrast, and return the Tailwind v4 design token export.

MCP tools

generate_palette

Parameter Required Values/default
seed yes Opaque six-digit color, e.g. #0F766E
mood no balanced (default), calm, vibrant, warm, neutral
format no json (default), css, tailwind, dart, all

Example input:

{
  "seed": "#0F766E",
  "mood": "calm",
  "format": "all"
}

Output is structured JSON with light and dark objects. Each has tokens, contrastChecks, and a pass-count summary. The exports object contains the requested integration snippets. JSON mode returns the tokens and checks without additional snippet strings. Every check reports the semantic foreground/background, rounded ratio, unrounded exactRatio, threshold, pass flag, and usage.

check_contrast

Parameter Required Values/default
foreground yes #RRGGBB
background yes #RRGGBB
threshold no 4.5 (default), 3, or 7

Example input:

{"foreground":"#777777","background":"#FFFFFF","threshold":4.5}

The input fails the 4.5:1 threshold. The tool returns a measured suggestion, its rounded and unrounded ratio, and its own passes flag. A suggestion can fail when the requested threshold is mathematically impossible for the chosen background; the tool does not label it as a pass.

Semantic token reference

Token Intended use
background / surface / surfaceVariant Canvas, panel, elevated/tinted panel
text / textMuted Body and secondary text on the three surfaces
primary / onPrimary Link or button fill, with label on button
secondary / onSecondary Secondary action and its label
success / warning / error Status text paired with an icon or label
outline / focus Control boundary or focus visual against surfaces

Exports

CSS custom properties

Use the generated CSS in your app stylesheet, and set the theme attribute on the document root or theme container:

<body data-theme="dark">
  <button class="primary">Continue</button>
</body>
.primary {
  background: var(--pc-primary);
  color: var(--pc-on-primary);
}

Tailwind CSS v4

The export combines the generated custom properties with top-level @theme inline declarations. Tailwind utility classes reference the current theme at runtime:

<div class="bg-pc-background text-pc-text">
  <button class="bg-pc-primary text-pc-on-primary">Continue</button>
</div>

It is designed for Tailwind CSS v4, not v3.

Flutter

The Dart export provides paletteCraftLight and paletteCraftDark ThemeData values and explicit Material 3 color roles. Paste the snippet in a Dart file in your app, then integrate both:

MaterialApp(
  theme: paletteCraftLight,
  darkTheme: paletteCraftDark,
  themeMode: ThemeMode.system,
)

Core Material color roles are mapped using the ColorScheme API. Other Flutter theme roles rely on framework defaults and require their own review. Always validate real app screens, states, and text sizes.

Explore the output: calm teal

Seed #0F766E, mood calm. Palette swatches and check totals below are generated by the actual algorithm, not a hand-picked design mock.

Token Light Dark
background #F9FAFA #101414
surface #FFFFFF #1B2221
text #1B2222 #EEF2F1
textMuted #5A7270 #9EB3B1
primary #267973 #87D9D3
onPrimary #F9FAFA #131616
secondary #3D7396 #87B3CF
success #257C4E #7DD8A8
warning #95630F #F1C374
error #AB2521 #E98E8B

Measured pairs passed: light 29/29, dark 29/29.

Run the included example for the entire structured JSON report and snippets:

npm run example

Contrast methodology

The engine converts each opaque sRGB input to relative luminance and calculates the ratio of the brighter and darker color. Normal text pairs use the WCAG AA minimum of 4.5:1. Outline/focus pairs use 3:1. The standalone checker also supports 7:1. See WCAG 2.2 contrast and non-text contrast.

To improve a failing foreground, it searches the same hue and saturation at 0.1% HSL lightness increments. The selected passing candidate minimizes lightness displacement among those candidates; for multiple surfaces it must pass against all of them. If none meets the threshold, the candidate with the highest observed minimum contrast is returned with passes=false. Pass/fail always uses the unrounded ratio.

PaletteCraft does not certify a UI as WCAG conformant. It checks listed opaque static color pairs, not alpha blending, gradients, rendered font size, focus geometry, dynamic states, color perception, or assistive technology. Never communicate status using color alone.

Development

npm ci
npm run typecheck
npm run format:check
npm test

Tests cover reference luminance values, unrounded threshold decisions, hex/HSL conversion, feasible and impossible contrast adjustments, 45 reference seed/mood combinations and 250 additional deterministic sample combinations across both themes, export consistency (including Flutter error-label contrast), and a real MCP client/server exchange including schema validation. CI gates TypeScript and source whitespace on Node 20 and 22. Flutter and Tailwind snippets are inspected for token consistency; this test suite does not compile a Flutter app or build a Tailwind project.

No accounts or secrets are necessary.

License

MIT. Original design-token and contrast code by Ahmed Saeed. See THIRD_PARTY.md for independent dependency licenses and the referenced W3C specification.