Skip to main content
Glama
aimsise

color-engine

by aimsise

solve_for_contrast

Read-onlyIdempotent

Find a foreground color meeting WCAG 2.1 contrast targets for a given background. Returns nearest-compliant hex and achieved contrast ratio, supporting single or multiple targets.

Instructions

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, ratio, nearMiss? }, ...] }. The output schema is an all-optional superset of both shapes (SDK 1.29 single-shape limitation). An unparseable background returns the PARSE_FAILED error; a translucent background (alpha < 1, e.g. rgba()/hsla()/#rgba/#rrggbbaa) returns ALPHA_UNSUPPORTED — composite it over its backdrop first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hueNoFixed 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 achromatic backgrounds (white/grey/black), so the result is an achromatic gray and the hue has no visible effect — pass chroma explicitly to keep saturation when fixing hue.
chromaNoFixed 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 explicitly to keep saturation when fixing hue. Giving chroma WITHOUT hue fixes the hue to the background's hue, or to 0 when the background is achromatic.
preferNoSearch direction relative to the background lightness. Default "either".
targetNoSingle WCAG 2.1 contrast target (e.g. 4.5, 7). Use this OR `targets` (targets wins if both given).
targetsNoMultiple WCAG 2.1 contrast targets (1-50 entries; an empty array is rejected). Takes precedence over `target`. Returns one result per target.
backgroundYesBackground CSS color string, e.g. "#FFFFFF", "oklch(0.6 0.1 240)" (max 256 chars).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
metNoSINGLE-target: whether the target contrast was achievable
colorNoSINGLE-target: nearest-compliant foreground hex, or null when unreachable
ratioNoSINGLE-target: achieved WCAG 2.1 ratio (display-rounded), or peak attainable when not met
resultsNoMULTI-target: one result per requested target (present only for the `targets` path)
nearMissNoSINGLE-target: present/true when met was granted via the near-ceiling tolerance
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond annotations (read-only, idempotent, non-destructive), the description discloses the search strategy ('Binary-searches OKLCH lightness holding hue/chroma fixed'), the return behavior (nearest-compliant hex plus achieved ratio), mode-dependent shapes, and error conditions (PARSE_FAILED, ALPHA_UNSUPPORTED). It also reveals subtle behavioral traps like hue without chroma having no visible effect on achromatic backgrounds. This is rich, non-obvious information that complements annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but densely informative—every sentence contributes (purpose, algorithm, modes, errors, caveats). It would benefit from structural formatting (e.g., separate paragraphs or bullets) to improve scannability, but it avoids fluff and redundancy relative to its complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With an output schema and exhaustive parameter documentation, the description still adds necessary context: it explains the response shape differences, the all-optional superset limitation, error conditions, and the key algorithmic behavior. For a tool with this many parameters and edge cases, the description is fully sufficient for an agent to select and invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although schema coverage is 100%, the description adds significant meaning beyond field names and types. It explains the interaction between `hue` and `chroma`: 'Giving hue WITHOUT chroma does not add saturation: chroma then defaults to the background's own chroma...' and the reverse case. It also clarifies precedence for `target` vs `targets` and the default for `prefer`. These are semantics not derivable from the schema alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a precise verb+resource: 'Find a foreground color that meets one or more WCAG 2.1 contrast targets against a background.' This clearly distinguishes the tool from siblings like `contrast` (which computes a ratio) and `generate_ramp` (which generates a ramp). The tool's purpose as a solver is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives clear context for parameter usage: 'Pass `target` for one target or `targets` for several; `prefer` selects lighter/darker/either' and explains precedence ('targets takes precedence'). It also warns against translucent backgrounds and instructs to composite first. However, it does not explicitly name alternative tools for scenarios where this tool is not the right choice, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aimsise/color-engine-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server