color-engine-mcp

v1.0.1
io.github.aimsise/color-engine-mcp Checked 3 days ago Published 5 months ago

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

ParameterTypeDescription
input *stringCSS 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.

ParameterTypeDescription
input *stringCSS color string to convert, e.g. "#ff0000", "tomato" (max 256 chars)
to *stringTarget 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`.

ParameterTypeDescription
a *stringFirst CSS color string, e.g. "#000000", "black", "oklch(0 0 0)" (max 256 chars)
b *stringSecond CSS color string, e.g. "#ffffff", "white", "oklch(1 0 0)" (max 256 chars)
apcabooleanWhen 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.

ParameterTypeDescription
input *stringAny 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).

ParameterTypeDescription
base *stringAny CSS color string, e.g. "#3b82f6", "oklch(0.6 0.35 30)" (max 256 chars)
deltaLnumberTotal lightness span (> 0) centered on the base L — endpoints at base L ± deltaL/2 (overrides the fixed range).
lightnessMaxnumberUpper lightness endpoint (OKLCH L, 0..1). Default 0.97.
lightnessMinnumberLower lightness endpoint (OKLCH L, 0..1). Default 0.05.
stepsintegerNumber of swatches (integer 2..512). Default 5.
tokenFormatstringOptional design-token format for the ramp ("tailwind" JSON object or a "css-variables" :root block); when present the output includes a `tokens` string.
tokenNamestringBase 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,…

ParameterTypeDescription
background *stringBackground CSS color string, e.g. "#FFFFFF", "oklch(0.6 0.1 240)" (max 256 chars).
chromanumberFixed 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…
huenumberFixed 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…
preferstringSearch direction relative to the background lightness. Default "either".
targetnumberSingle WCAG 2.1 contrast target (e.g. 4.5, 7). Use this OR `targets` (targets wins if both given).
targetsarrayMultiple WCAG 2.1 contrast targets (1-50 entries; an empty array is rejected). Takes precedence over `target`. Returns one result per target.