惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
H
Help Net Security
月光博客
月光博客
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
GbyAI
GbyAI
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Your AI Agent Hallucinates Tailwind Classes. Here's the Fix
Albert Alov · 2026-05-17 · via DEV Community
Cover image for Your AI Agent Hallucinates Tailwind Classes. Here's the Fix

Albert Alov

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-primary is a valid class in this project
  • What your custom spacing scale looks like (is p-18 valid here?)
  • Whether you're using a custom prefix like tw-
  • Which brand colors exist beyond the Tailwind defaults
  • Whether flex grid on 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

Enter fullscreen mode Exit fullscreen mode

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"]
}

Enter fullscreen mode Exit fullscreen mode


How It Works

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

  1. jiti loads your tailwind.config.ts at runtime — no ts-node setup needed
  2. tailwindcss/resolveConfig merges your config with Tailwind defaults → full resolved theme
  3. Token-based validation — checks that bg-brand-primary maps to an actual colors.brand.primary token — 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:, /50 before lookup
  • bg-[#ff0000] → arbitrary values are always valid
  • -mt-4 → negative prefix stripped, looks up spacing token 4
  • group-hover:text-white → multi-word variants handled correctly
  • Unknown classes when plugins are active → possibly_valid_classes (can't verify btn or prose without PostCSS)

Setup

Add to Claude Desktop / Cursor / any MCP client:

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

Enter fullscreen mode Exit fullscreen mode

Then pass your config path on each tool call:

config_path: "/absolute/path/to/tailwind.config.ts"

Enter fullscreen mode Exit fullscreen mode


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.