Skip to main content
Glama
PaletteCraft MCP

PaletteCraft MCP

README.md
# PaletteCraft MCP

![PaletteCraft editorial wordmark](assets/palettecraft.svg)

**Start with one color. Build a complete design system.**

![Generated light and dark swatches, three real seed and mood combinations](assets/palette-gallery.svg)

*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.

## Quick start

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

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

Connect the built server to Codex:

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

Alternatively configure the server in Codex's user config:

```toml
[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](https://developers.openai.com/codex/mcp/).

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:

```json
{
  "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, ratio, 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:

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

The input fails the 4.5:1 threshold. The tool returns a measured
suggestion, its 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:

```html
<body data-theme="dark">
  <button class="primary">Continue</button>
</body>
```

```css
.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:

```html
<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](https://tailwindcss.com/docs/theme),
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:

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

Core Material color roles are mapped using the
[ColorScheme API](https://api.flutter.dev/flutter/material/ColorScheme-class.html).
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:

```bash
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](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum)
and [non-text contrast](https://www.w3.org/WAI/WCAG22/Understanding/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

```bash
npm ci
npm test
```

Tests cover reference luminance values, unrounded threshold decisions,
hex/HSL conversion, feasible and impossible contrast adjustments,
45 seed/mood combinations across both themes, export consistency, and a
real MCP client/server exchange including schema validation.
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](THIRD_PARTY.md) for independent dependency licenses and
the referenced W3C specification.