Skip to main content
Glama

a11y-toolkit: Contrast ratio + verdicts

a11y_contrast_pair
Read-onlyIdempotent

Calculate WCAG contrast ratio for any color pair and verify AA, AAA, and non-text compliance. Offers a passing color suggestion when 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.

Input Schema

TableJSON 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.7/5.0
Behavior5/5

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

Beyond the readOnly/idempotent annotations, the description reveals key behavior: alpha is composited over the background (or white for bg), per-criterion verdicts are returned, and a nearest passing color is suggested when AA fails. This materially helps an agent predict side effects and output shape.

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

Conciseness5/5

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

Two tight sentences front-load the core function and verdicts, then add format support, compositing behavior, fallback suggestion, and the key sibling exclusion. Every clause earns its place with no fluff.

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?

For a simple read-only calculation tool, the description covers what it computes, what inputs it accepts, how alpha is handled, what outputs to expect, and when not to use it. No critical gap remains for an agent to invoke it correctly.

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%, so the schema already documents formats and compositing for both fg and bg. The description reinforces those semantics but does not add significant meaning beyond the structured schema; baseline 3 is appropriate.

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 an exact, specific function: computing WCAG contrast ratio for a color pair with per-criterion verdicts (1.4.3, 1.4.6, 1.4.11). It clearly differentiates from a11y_contrast_image by explicitly noting flat pairs vs. text over images.

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?

It gives direct usage context: use for flat color pairs, and explicitly says text-over-images needs a11y_contrast_image. This names the alternative and the condition that selects it, leaving no ambiguity about when this tool is appropriate.

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