Your AI agent is confidently writing Tailwind classes that don't exist in your project.
bg-primary-500? Your project uses bg-brand-primary.
p-18? Only valid if your spacing scale includes it.
tw-flex? Only if your config sets prefix: "tw-".
The agent doesn't know. It's working from training data — the default Tailwind docs, not your config.
The Epistemic Blindness
When an agent generates a React component, it has no idea:
- Whether
bg-brand-primaryis a valid class in this project - What your custom spacing scale looks like (is
p-18valid here?) - Whether you're using a custom prefix like
tw- - Which brand colors exist beyond the Tailwind defaults
- Whether
flex gridon the same element is a conflict
It guesses. Custom tokens = hallucinations. Every time.
The Fix: Give the Agent Your Actual Config
tailwind-context-resolver-mcp is an MCP server that loads your tailwind.config.ts/js and exposes its resolved design system as queryable tools.
Before writing a component, the agent can:
→ get_config_summary understand the project's design system
→ resolve_theme_tokens query what colors/spacing actually exist
→ validate_class_string verify the className before committing it
→ detect_css_conflicts catch flex+grid on the same element
Real output from validate_class_string:
{
"valid_classes": ["bg-brand-primary", "text-white", "p-4", "hover:dark:bg-brand-secondary"],
"invalid_classes": ["bg-fake-token"],
"possibly_valid_classes": ["btn", "prose"],
"warnings": ["Conflicting multiple layout models: flex, grid"]
}
How It Works
The server uses the same config loading strategy as the Tailwind CLI itself:
-
jitiloads yourtailwind.config.tsat runtime — nots-nodesetup needed -
tailwindcss/resolveConfigmerges your config with Tailwind defaults → full resolved theme -
Token-based validation — checks that
bg-brand-primarymaps to an actualcolors.brand.primarytoken — without running PostCSS or the full JIT pipeline
The class parser handles the full Tailwind syntax:
-
!hover:dark:bg-brand-primary/50→ strips!,hover:dark:,/50before lookup -
bg-[#ff0000]→ arbitrary values are always valid -
-mt-4→ negative prefix stripped, looks up spacing token4 -
group-hover:text-white→ multi-word variants handled correctly - Unknown classes when plugins are active →
possibly_valid_classes(can't verifybtnorprosewithout PostCSS)
Setup
Add to Claude Desktop / Cursor / any MCP client:
{
"mcpServers": {
"tailwind-context-resolver": {
"command": "npx",
"args": ["-y", "tailwind-context-resolver-mcp"]
}
}
}
Then pass your config path on each tool call:
config_path: "/absolute/path/to/tailwind.config.ts"
Tailwind v3 Only
v4 uses a CSS-based config format — the programmatic resolveConfig API doesn't apply. The server detects v4 and returns a clear error instead of silently failing.
Links
Part of a series of MCP tools for making AI agents actually useful in real codebases. Also check out v8-cpu-profile-decoder-mcp for Node.js performance profiling.
Top comments (0)