Skip to main content
Glama

a11y-toolkit: Contrast ratio + verdicts

a11y_contrast_pair
Read-onlyIdempotent

Calculate exact WCAG contrast ratio for a foreground/background color pair, with AA, AAA, and non-text verdicts plus a passing-color suggestion if AA fails.

Instructions

Exact WCAG contrast ratio for a color pair: per-criterion verdicts 1.4.3 (AA), 1.4.6 (AAA), 1.4.11 (non-text). Accepts #hex, rgb(), hsl(), CSS color names; rgba/hsl with alpha is composited over the background. If AA fails, suggests the nearest passing color. — For flat pairs; text over images needs a11y_contrast_image. Returns JSON: {text, background, ratio, verdicts [{criterion, level, threshold, passes}], aa_suggestion?}.

Input Schema

NameRequiredDescriptionDefault
bgYesBackground color: same formats; alpha composites over white
fgYesForeground/text color: #hex, rgb(), hsl() or a CSS color name; alpha composites over bg
langNooutput language (en default)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv4.0.0
    • addedInput schema / properties / bg / description
      Added value: +"Background color: same formats; alpha composites over white"
    • addedInput schema / properties / fg / description
      Added value: +"Foreground/text color: #hex, rgb(), hsl() or a CSS color name; alpha composites over bg"
  2. Changed1 schema field changedv3.12.0
    • changedInput schema / properties / lang / description
      Previous value: -"output language (es default)"New value: +"output language (en default)"
  3. Changed1 schema field changedv3.3.0
    • changedInput schema / properties / lang / description
      Previous value: -"Idioma de la salida (es por defecto)"New value: +"output language (es default)"
  4. First observedv2.3.0

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already establish this as a safe, idempotent, closed-world read, so the remaining burden is behavioral detail — and the description supplies it: accepted color syntaxes, alpha compositing rules (over bg for fg, over white for bg), automatic nearest-passing-color suggestion when AA fails, and the shape of the returned JSON object despite there being no output schema.

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?

Front-loaded with the core purpose, then formats, then the sibling disclaimer and return shape — all sentences earn their place. Slightly dense with em-dash-separated clauses, but nothing is wasted.

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 no output schema, the description compensates by documenting the returned JSON keys (text, background, ratio, verdicts, aa_suggestion). Combined with format acceptance, compositing behavior, and the sibling boundary, an agent has everything needed to call and interpret it.

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 description coverage is 100% and the description's parameter content (accepted formats, alpha compositing) largely restates what the fg/bg schema entries already say. The lang enum parameter is not mentioned in the description at all. Baseline 3 is appropriate when the schema carries the parameter semantics.

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?

States a specific verb+resource (exact WCAG contrast ratio for a color pair) and enumerates the verdict set it produces (1.4.3 AA, 1.4.6 AAA, 1.4.11 non-text). It explicitly distinguishes itself from the sibling a11y_contrast_image, so an agent can route correctly without opening a schema.

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

Usage Guidelines5/5

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

Gives both the inclusion condition ('For flat pairs') and the exclusion with a named alternative ('text over images needs a11y_contrast_image'). This is explicit when/when-not/alternative guidance rather than implied usage.

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