color-engine-mcp
v1.0.1Six pure, in-memory CSS color tools: parse, convert, WCAG/APCA contrast, gamut map, ramps, solver
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
parse_color
Parse a CSS color string and return hex, rgb, oklch, and gamut info.
| Parameter | Type | Description |
|---|---|---|
input * | string | CSS color string, e.g. "tomato", "#ff6347", "oklch(0.6 0.18 27)" (max 256 chars) |
convert_color
Convert a CSS color string into a canonical hex, rgb, hsl, or oklch format string.
| Parameter | Type | Description |
|---|---|---|
input * | string | CSS color string to convert, e.g. "#ff0000", "tomato" (max 256 chars) |
to * | string | Target color format to convert the input into |
contrast
Compute the WCAG 2.1 contrast ratio between two fully opaque CSS color strings and return WCAG tier flags (AA/AAA normal/large text). Set apca:true to also get the signed APCA-W3 Lc for text `a` over background `b`.
| Parameter | Type | Description |
|---|---|---|
a * | string | First CSS color string, e.g. "#000000", "black", "oklch(0 0 0)" (max 256 chars) |
b * | string | Second CSS color string, e.g. "#ffffff", "white", "oklch(1 0 0)" (max 256 chars) |
apca | boolean | When true, additionally compute the APCA-W3 (SAPC-4g) lightness contrast Lc for text `a` over background `b` (returned as `apcaLc`) |
gamut_map
Map any CSS color string into the sRGB gamut via perceptual OKLCH chroma reduction. Returns the nearest in-gamut hex, raw OKLCH components, and a `clamped` flag indicating whether the input was out-of-gamut.
| Parameter | Type | Description |
|---|---|---|
input * | string | Any CSS color string, e.g. "#ff0000", "oklch(0.6 0.4 30)" (max 256 chars) |
generate_ramp
Generate a tint-to-shade color ramp from a base CSS color. Returns an ordered list of swatches (light → dark) each with its in-gamut hex, display-rounded OKLCH components (l/c 5dp, h 2dp), WCAG contrast ratios (2dp) + tiers vs white and black, and an in-gamut flag. Optionally emits the ramp as design tokens via tokenFormat ("tailwind" JSON or a "css-variables" :root block).
| Parameter | Type | Description |
|---|---|---|
base * | string | Any CSS color string, e.g. "#3b82f6", "oklch(0.6 0.35 30)" (max 256 chars) |
deltaL | number | Total lightness span (> 0) centered on the base L — endpoints at base L ± deltaL/2 (overrides the fixed range). |
lightnessMax | number | Upper lightness endpoint (OKLCH L, 0..1). Default 0.97. |
lightnessMin | number | Lower lightness endpoint (OKLCH L, 0..1). Default 0.05. |
steps | integer | Number of swatches (integer 2..512). Default 5. |
tokenFormat | string | Optional design-token format for the ramp ("tailwind" JSON object or a "css-variables" :root block); when present the output includes a `tokens` string. |
tokenName | string | Base name for emitted tokens (letters/digits/hyphens, must start with a letter, 1-64 chars). Default "color". |
solve_for_contrast
Find a foreground color that meets one or more WCAG 2.1 contrast targets against a background. Binary-searches OKLCH lightness (holding hue/chroma fixed) and returns the nearest-compliant hex plus the achieved ratio. Pass `target` for one target or `targets` for several; `prefer` selects lighter/darker/either; `hue`/`chroma` pin the foreground chromaticity. If BOTH `target` and `targets` are provided, `targets` takes precedence. The response shape differs by mode: a single `target` returns `{ met, color, ratio }` (with an optional `nearMiss` flag); `targets` returns `{ results: [{ met, color,…
| Parameter | Type | Description |
|---|---|---|
background * | string | Background CSS color string, e.g. "#FFFFFF", "oklch(0.6 0.1 240)" (max 256 chars). |
chroma | number | Fixed OKLCH chroma (>= 0) held constant during the lightness search (reduced along the fixed hue when the sRGB gamut requires it). Defaults to the background's own chroma when omitted; pass chroma exp… |
hue | number | Fixed OKLCH hue (degrees, cyclic) held constant during the lightness search. Giving hue WITHOUT chroma does not add saturation: chroma then defaults to the background's own chroma, which is 0 for achr… |
prefer | string | Search direction relative to the background lightness. Default "either". |
target | number | Single WCAG 2.1 contrast target (e.g. 4.5, 7). Use this OR `targets` (targets wins if both given). |
targets | array | Multiple WCAG 2.1 contrast targets (1-50 entries; an empty array is rejected). Takes precedence over `target`. Returns one result per target. |