Skip to main content
Glama

tailwind_optimize_classes

Optimize and deduplicate Tailwind CSS classes in HTML to reduce file size and improve performance by removing unused styles.

Instructions

Optimize and deduplicate Tailwind classes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
htmlYes
purgeNo

Implementation Reference

  • Main handler function that extracts Tailwind classes from HTML, deduplicates, sorts, groups them, generates optimizations and suggestions.
    async optimizeClasses(args: any) {
      const params = TailwindOptimizeSchema.parse(args);
      
      try {
        // Extract and optimize Tailwind classes from HTML
        const classRegex = /class(?:Name)?=["']([^"']+)["']/g;
        const allClasses = new Set<string>();
        let match;
    
        while ((match = classRegex.exec(params.html)) !== null) {
          match[1].split(/\s+/).forEach(cls => allClasses.add(cls));
        }
    
        // Sort and deduplicate classes
        const sortedClasses = this.sortTailwindClasses(Array.from(allClasses));
        
        // Group classes by component/utility type
        const groupedClasses = this.groupTailwindClasses(sortedClasses);
    
        // Generate optimized class strings
        const optimized: any = {
          allClasses: sortedClasses,
          grouped: groupedClasses,
          duplicates: this.findDuplicatePatterns(sortedClasses),
          suggestions: this.generateOptimizationSuggestions(sortedClasses)
        };
    
        if (params.purge) {
          // Simulate purging unused classes
          optimized.purged = {
            before: sortedClasses.length,
            after: Math.floor(sortedClasses.length * 0.7),
            saved: `${(sortedClasses.length * 0.3 * 0.1).toFixed(2)}kb`
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(optimized, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Error optimizing Tailwind classes: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema for input validation of html string and optional purge boolean.
    const TailwindOptimizeSchema = z.object({
      html: z.string(),
      purge: z.boolean().default(false)
    });
  • src/index.ts:107-118 (registration)
    Tool registration in the listTools handler, including name, description, and input schema.
    {
      name: 'tailwind_optimize_classes',
      description: 'Optimize and deduplicate Tailwind classes',
      inputSchema: {
        type: 'object',
        properties: {
          html: { type: 'string' },
          purge: { type: 'boolean', default: false }
        },
        required: ['html']
      }
    },
  • src/index.ts:310-311 (registration)
    Dispatch in the CallToolRequestSchema switch statement to the optimizeClasses handler.
    case 'tailwind_optimize_classes':
      return await this.tailwindTools.optimizeClasses(args);
  • Helper method to sort Tailwind classes according to recommended order.
    private sortTailwindClasses(classes: string[]): string[] {
      // Sort classes by Tailwind's recommended order
      const order = [
        'container', 'sr-only', 'static', 'fixed', 'absolute', 'relative', 'sticky',
        'block', 'inline-block', 'inline', 'flex', 'inline-flex', 'grid', 'inline-grid',
        'hidden', 'w-', 'h-', 'p-', 'm-', 'text-', 'bg-', 'border-', 'rounded-'
      ];
      
      return classes.sort((a, b) => {
        const aIndex = order.findIndex(prefix => a.startsWith(prefix));
        const bIndex = order.findIndex(prefix => b.startsWith(prefix));
        
        if (aIndex === -1 && bIndex === -1) return a.localeCompare(b);
        if (aIndex === -1) return 1;
        if (bIndex === -1) return -1;
        
        return aIndex - bIndex;
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'optimize and deduplicate' but does not explain what this entails (e.g., whether it modifies input, requires specific permissions, has rate limits, or returns structured output). For a tool with two parameters and no output schema, this leaves significant gaps in understanding its behavior and effects.

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?

The description is extremely concise with a single phrase, 'Optimize and deduplicate Tailwind classes', which is front-loaded and wastes no words. Every part of the sentence directly contributes to the purpose, making it efficient and well-structured despite its brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has two parameters, no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It does not address input/output behavior, error handling, or practical use cases, leaving users with insufficient context to effectively invoke the tool or understand its results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It does not mention the 'html' parameter (required) or the 'purge' parameter (optional with default), nor does it explain their roles (e.g., 'html' as input content, 'purge' for removing unused classes). With two parameters and no schema descriptions, the description adds minimal value beyond the tool name.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool's purpose as 'Optimize and deduplicate Tailwind classes', which is clear but vague. It specifies the action ('optimize and deduplicate') and resource ('Tailwind classes'), but lacks details on scope (e.g., HTML input) or how it distinguishes from siblings like 'tailwind_generate_config' or 'workflow_optimize_ux'. This makes it minimally adequate but not specific enough for full differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention context (e.g., for cleaning up HTML), prerequisites, or exclusions, nor does it reference sibling tools like 'component_analyze' or 'workflow_optimize_ux' that might overlap. Without such information, users must infer usage from the purpose alone.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/willem4130/ui-ux-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server