Skip to main content
Glama

a11y-toolkit: Nearest passing color

a11y_suggest_color
Read-onlyIdempotent

Find the nearest opaque foreground color that meets a target contrast ratio against a background, returning the color, ratio, and lighten/darken action. Fixes WCAG contrast failures.

Instructions

Nearest opaque color (RGB distance) to fg that reaches the target ratio against bg (4.5 default). Returns the color, its ratio and whether it lightens or darkens. — The fixer companion to a11y_contrast_pair failures. Returns JSON: {color, ratio, action} — the nearest opaque color reaching the target.

Input Schema

NameRequiredDescriptionDefault
bgYesThe background it must pass against
fgYesThe failing foreground color to fix
targetNoRatio to reach: 4.5 normal text, 3.0 large text/UI, 7.0 AAA (default 4.5)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv4.0.0
    • addedInput schema / properties / bg / description
      Added value: +"The background it must pass against"
    • addedInput schema / properties / fg / description
      Added value: +"The failing foreground color to fix"
    • addedInput schema / properties / target / description
      Added value: +"Ratio to reach: 4.5 normal text, 3.0 large text/UI, 7.0 AAA (default 4.5)"
  2. First observedv2.3.0

TDQS

A4/5.0
Behavior4/5

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

Annotations already declare readOnly, idempotent and non-destructive, so the safety profile is covered. The description adds genuinely new behavioral detail: the matching is by RGB distance, results are constrained to opaque colors, and the returned action indicates whether the color lightens or darkens. It does not mention edge cases (e.g. when no passing color exists) or tie-breaking.

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

Conciseness3/5

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

The front-loaded first sentence is excellent, but the return-value information is stated twice — once as prose ('Returns the color, its ratio and whether it lightens or darkens') and again as 'Returns JSON: {color, ratio, action}' — and the trailing clause 'the nearest opaque color reaching the target' repeats the opening. Roughly a third of the text is redundant.

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

Completeness4/5

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

With no output schema, the description correctly steps in to document the return payload {color, ratio, action}, and all three parameters are documented in the schema. The only real gap is the undefined failure case when no opaque color reaches the target ratio, which matters for an agent deciding how to handle the result.

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

Parameters3/5

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

Schema coverage is 100% and each parameter already carries a description, including the target's ratio semantics and default. The description reinforces 'opaque' and the 4.5 default but adds no syntax or format detail beyond the schema, so the baseline of 3 applies.

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 states a specific operation (find the nearest opaque color to fg that reaches a target contrast ratio against bg) and even names the algorithm (RGB distance). It explicitly positions itself as 'the fixer companion to a11y_contrast_pair failures,' which separates it from the diagnostic sibling a11y_contrast_pair without opening either schema.

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?

Usage context is clear: this is the remediation step after a contrast-pair check fails, with a sensible default target of 4.5. However, it never states when NOT to use it — notably it does not distinguish itself from the sibling a11y_autofix, which an agent could reasonably confuse for the same fixer role.

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