Skip to main content
Glama
tailwind-context-resolver-mcp

tailwind-context-resolver-mcp

by vola-trebla

tailwind-context-resolver-mcp 🎨🐸

npm version npm downloads CI License: MIT

An MCP server that loads your project's tailwind.config.ts/js and exposes its actual design system to AI agents β€” so they stop hallucinating class names.


πŸ€” The Problem

AI agents generate Tailwind classes based on training data β€” the default Tailwind docs. Your project is not the default docs.

You have a custom color palette. A non-standard spacing scale. Maybe a prefix like tw-. Brand tokens like bg-brand-primary. The agent doesn't know any of this. It guesses.

The result:

// Agent confidently generates this:
<div className="bg-primary-500 text-brand p-18 tw-flex-center">

// Your project has:
// - bg-brand-primary (not bg-primary-500)
// - no "text-brand" token
// - spacing.18 = 4.5rem (ok actually)
// - no "flex-center" utility
// - no "tw-" prefix

The agent can't validate what it writes because it has no access to your resolved config. It's working from memory of the default theme β€” not yours.


Related MCP server: TailwindCSS MCP Server

βœ… The Fix

This MCP server runs the Tailwind resolver locally and gives agents a typed, queryable interface to your actual config. Before writing a component, the agent can ask:

  • "What brand colors exist in this project?"

  • "Is p-18 a valid spacing value here?"

  • "Does this project use a custom prefix?"

  • "Is bg-brand-primary flex grid a valid class string?"


πŸ› οΈ Tools

resolve_theme_tokens

Query any namespace in the resolved Tailwind theme. Returns all design tokens as flat key-value pairs.

namespace: "colors.brand" β†’ { primary: "#3b82f6", secondary: "#8b5cf6", danger: "#ef4444" }
namespace: "spacing"      β†’ { "1": "0.25rem", "2": "0.5rem", "18": "4.5rem", ... }
namespace: "fontFamily"   β†’ { sans: ["Inter", "sans-serif"], mono: [...] }

Use before generating components to discover what tokens actually exist.

validate_class_string

Validates a Tailwind className string against the project's resolved config. Returns valid classes, invalid (hallucinated) classes, and conflict warnings.

{
  "valid_classes": ["bg-brand-primary", "text-white", "p-4", "hover:bg-brand-secondary", "flex"],
  "invalid_classes": ["bg-fake-token", "text-brand"],
  "warnings": ["Conflicting multiple layout models: flex, grid"],
  "config_prefix": ""
}

Use to catch hallucinated design tokens before writing code.

detect_css_conflicts

Detects conflicting Tailwind utilities β€” e.g. flex + grid, or absolute + fixed on the same element.

{
  "conflicts": [{ "classes": ["flex", "grid"], "reason": "multiple layout models" }],
  "has_conflicts": true
}

get_config_summary

Returns a compact overview: Tailwind version, prefix, which theme sections are customized, active plugins.

{
  "tailwind_version": "3.4.19",
  "prefix": "",
  "theme_extensions": ["colors", "spacing", "fontFamily"],
  "total_colors": 142,
  "total_spacing": 34,
  "plugins": ["@tailwindcss/forms"]
}

Use first to understand the project's design system before querying specific tokens.


πŸš€ Setup

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "tailwind-context-resolver": {
      "command": "npx",
      "args": ["-y", "tailwind-context-resolver-mcp"]
    }
  }
}

Cursor / VS Code / Any MCP client

{
  "tailwind-context-resolver": {
    "command": "npx",
    "args": ["-y", "tailwind-context-resolver-mcp"]
  }
}

πŸ“‹ Requirements

  • Tailwind CSS v3 β€” v4 uses a CSS-based config format and is not supported (the server will tell you clearly)

  • Node.js 18+

  • A tailwind.config.js or tailwind.config.ts in your project


πŸ”§ How It Works

The server uses the same config loading strategy as the Tailwind CLI:

  1. jiti loads your tailwind.config.ts at runtime β€” no ts-node required

  2. tailwindcss/resolveConfig merges your config with Tailwind defaults to produce the full resolved theme

  3. Tools perform token-based class validation β€” checking that bg-brand-primary maps to an actual colors.brand.primary token β€” without running the full PostCSS/JIT pipeline

This approach is fast, stable, and works with any Tailwind v3 project without additional configuration.


πŸ“– Agent Workflow Example

1. get_config_summary       β†’ understand the project's design system
2. resolve_theme_tokens     β†’ query specific namespaces before writing classes
   (namespace: "colors.brand", "spacing")
3. validate_class_string    β†’ validate the className string before committing it
4. detect_css_conflicts     β†’ final sanity check for conflicting utilities

🐸 Part of the MCP Toolbelt

Built alongside:


License

MIT

Available Tools

7 tools
audit_theme_usageA

Identifies dead design tokens by scanning the project files. Checks each CSS custom property defined in @theme blocks to see if it is referenced anywhere in the source code.

Inputs: css_path (required), project_root (required), scan_dirs.

detect_css_conflictsA

Detects conflicting Tailwind utility classes in a className string β€” e.g. applying both 'flex' and 'grid', or multiple position utilities. Use to prevent silent CSS bugs before generating or reviewing component code.

Inputs: config_path (required), class_string (required).

get_config_summaryA

Returns a compact overview of the project's Tailwind configuration: version, prefix, which theme sections have been customized, and what plugins are active. Use first to understand the project's design system before querying specific tokens.

Inputs: config_path (required).

resolve_theme_tokensA

Queries the resolved Tailwind CSS theme for a specific namespace and returns all design tokens. Use before generating components to discover what colors, spacing, or font values actually exist in this project. Example namespaces: 'colors', 'colors.brand', 'spacing', 'fontFamily', 'fontSize', 'screens'.

Inputs: namespace (required), config_path (required), filter.

resolve_v4_theme_variablesA

Parses the project's root CSS file (Tailwind CSS v4) and extracts all design tokens defined in @theme blocks. Returns a flat map of CSS custom properties (e.g., --color-primary-500 -> oklch(...)).

Inputs: css_path (required).

simulate_jit_compilationA

Validates Tailwind utility classes against the JIT engine by programmatically compiling them. Supports complex arbitrary values, JIT modifiers, and custom plugin classes. Returns the generated CSS rules.

Inputs: class_string (required), css_path, config_path.

validate_class_stringA

Validates a Tailwind CSS className string against the project's actual config. Returns valid_classes, invalid_classes (hallucinated tokens), possibly_valid_classes (plugin-generated β€” cannot verify without PostCSS), and conflict warnings. Handles variants (hover:, dark:, lg:), important (!), opacity modifiers (/50), negative values (-mt-4), and arbitrary values ([32rem]). Use to catch hallucinated design tokens before writing code.

Inputs: config_path (required), class_string (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool targets a distinct aspect of Tailwind CSS context: config overview, theme variable extraction, dead-token auditing, class compilation simulation, theme token querying, class string validation, and conflict detection. There is no meaningful overlap; even the two token-related tools are clearly differentiated by their source (CSS @theme vs resolved theme).

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern using lowercase with underscores (get_, resolve_, audit_, simulate_, validate_, detect_). Though the verbs differ, they accurately reflect the unique action each tool performs, and the pattern is uniform throughout.

    Tool Count5/5

    Seven tools is well within the ideal range and each tool directly serves the server's purpose of resolving and validating Tailwind CSS context. No redundant tools and no missing essential operations for a read-only context resolver.

    Completeness5/5

    The toolset covers the full lifecycle of working with Tailwind design tokens and classes: config summary, theme token extraction and querying, dead-token auditing, class validation, conflict detection, and JIT simulation. There are no obvious gaps; it handles both Tailwind v3/v4 scenarios and provides actionable checks for developers.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Provides comprehensive tools for TailwindCSS development including utility class retrieval, CSS-to-Tailwind conversion, and color palette generation. It enables AI assistants to search documentation, generate component templates, and provide framework-specific installation guides.
      8
      3,233 npm
      41
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables coding agents to query a workspace's design system before writing UI and validate generated code against the same system afterward, using configurable token and component sources.
      13 npm
      1
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables AI coding agents to inspect a project's design tokens and component catalog, audit React/Tailwind files against seven static UI quality rules, score overall UI health, and apply auto-fixes that are re-audited and reverted on regression. It works both locally over filesystem access and remotely on raw TSX/JSX or CSS snippets passed directly as strings.
      -