Skip to main content
Glama
Tai-DT
by Tai-DT

convert_to_tailwind

Convert CSS, SCSS, or HTML styles into optimized Tailwind CSS utility classes for streamlined development workflows.

Instructions

Convert CSS/SCSS to Tailwind classes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesCSS, SCSS, or HTML with styles to convert
formatYesInput format
preserveCustomNoPreserve custom properties that cannot be converted
optimizeNoOptimize the converted classes

Implementation Reference

  • src/index.ts:302-330 (registration)
    Registration of the 'convert_to_tailwind' tool in the TOOLS array, including input schema definition.
    {
      name: 'convert_to_tailwind',
      description: 'Convert CSS/SCSS to Tailwind classes',
      inputSchema: {
        type: 'object',
        properties: {
          code: {
            type: 'string',
            description: 'CSS, SCSS, or HTML with styles to convert'
          },
          format: {
            type: 'string',
            enum: ['css', 'scss', 'html'],
            description: 'Input format'
          },
          preserveCustom: {
            type: 'boolean',
            default: false,
            description: 'Preserve custom properties that cannot be converted'
          },
          optimize: {
            type: 'boolean',
            default: true,
            description: 'Optimize the converted classes'
          }
        },
        required: ['code', 'format']
      }
    },
  • The handler function called by the tool dispatcher to execute the conversion logic. Currently implemented as a placeholder returning mock response.
    export async function convertToTailwind(args: ConversionOptions) {
      return {
        content: [
          {
            type: 'text',
            text: `Converted CSS to Tailwind\nSource: ${args.source || 'css'}\nTarget: ${args.target || 'tailwind'}`
          }
        ]
      };
    }
  • TypeScript interface defining the expected input parameters for the convertToTailwind function.
    export interface ConversionOptions {
      css: string;
      source?: 'css' | 'scss' | 'less' | 'stylus';
      target?: 'tailwind' | 'utility-first';
      framework?: 'tailwind' | 'unocss' | 'windicss';
      optimization?: 'none' | 'basic' | 'aggressive';
      preserveComments?: boolean;
      generateVariables?: boolean;
    }
  • Tool dispatcher switch case that routes calls to the specific 'convert_to_tailwind' handler.
    case 'convert_to_tailwind':
      return await convertToTailwind(args as unknown as ConversionOptions);
  • Comprehensive helper function implementing CSS/SCSS/HTML to Tailwind conversion using AI (Gemini) with fallback manual mapping. Matches tool input schema perfectly, likely intended for use in production.
    export async function convertToTailwind(args: ConvertRequest) {
      try {
        const {
          code,
          format,
          preserveCustom = false,
          optimize = true
        } = args;
    
        let convertedCode = '';
        let conversionNotes: string[] = [];
        let unconvertedStyles: string[] = [];
    
        if (isGeminiAvailable()) {
          // Use AI for advanced conversion
          const prompt = `Convert the following ${format.toUpperCase()} code to Tailwind CSS classes:
    
    ${code}
    
    Requirements:
    1. Convert all possible CSS properties to equivalent Tailwind classes
    2. ${preserveCustom ? 'Preserve custom properties that cannot be converted as CSS custom properties' : 'Note any styles that cannot be converted to Tailwind'}
    3. ${optimize ? 'Optimize the resulting classes for performance and readability' : ''}
    4. Maintain the visual appearance exactly
    5. Use modern Tailwind practices and utilities
    
    Return a JSON response with:
    {
      "convertedCode": "HTML/CSS with Tailwind classes",
      "conversionNotes": ["List of conversion notes and decisions made"],
      "unconvertedStyles": ["List of styles that couldn't be converted"],
      "suggestions": ["List of optimization suggestions"]
    }
    
    Focus on:
    - Accurate class mapping
    - Responsive design patterns
    - Accessibility considerations
    - Performance optimization
    - Maintainable code structure`;
    
          const aiResponse = await callGemini(prompt);
          
          try {
            const jsonMatch = aiResponse.match(/\{[\s\S]*\}/);
            if (jsonMatch) {
              const result = JSON.parse(jsonMatch[0]);
              convertedCode = result.convertedCode;
              conversionNotes = result.conversionNotes || [];
              unconvertedStyles = result.unconvertedStyles || [];
            } else {
              throw new Error('No valid JSON found in AI response');
            }
          } catch (parseError) {
            // Fallback to manual conversion
            const manualResult = performManualConversion(code, format);
            convertedCode = manualResult.code;
            conversionNotes = manualResult.notes;
            unconvertedStyles = manualResult.unconverted;
          }
        } else {
          // Manual conversion
          const manualResult = performManualConversion(code, format);
          convertedCode = manualResult.code;
          conversionNotes = manualResult.notes;
          unconvertedStyles = manualResult.unconverted;
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `# CSS to Tailwind Conversion
    
    ## Converted Code
    \`\`\`${format === 'html' ? 'html' : 'css'}
    ${convertedCode}
    \`\`\`
    
    ## Conversion Summary
    ${conversionNotes.length > 0 ? conversionNotes.map(note => `- ${note}`).join('\n') : 'No specific conversion notes.'}
    
    ${unconvertedStyles.length > 0 ? `## Unconverted Styles
    The following styles could not be converted to Tailwind classes:
    ${unconvertedStyles.map(style => `- \`${style}\``).join('\n')}
    
    Consider using CSS custom properties or Tailwind plugins for these styles.` : ''}
    
    ## Usage Tips
    - Test the converted code to ensure visual consistency
    - Consider extracting repeated class patterns into components
    - Use Tailwind's JIT mode for optimal performance
    - Add responsive variants as needed (sm:, md:, lg:, xl:)`
            }
          ]
        };
      } catch (error) {
        console.error('CSS conversion error:', error);
        throw new Error(`Failed to convert CSS: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
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 states the conversion action but doesn't describe what happens during conversion (e.g., whether it's a read-only transformation or modifies data, error handling for invalid input, or performance considerations like rate limits). This leaves significant gaps for a tool that performs code transformation.

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 a single, efficient sentence with zero waste. It's front-loaded with the core purpose, making it easy to understand at a glance without unnecessary elaboration.

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 complexity of a code conversion tool with 4 parameters and no annotations or output schema, the description is incomplete. It doesn't explain the return values, error cases, or behavioral traits like whether the conversion is idempotent or has side effects. This makes it inadequate for guiding an AI agent effectively.

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 all parameters thoroughly. The description adds no additional meaning beyond the schema, such as examples of input code or details on how 'preserveCustom' or 'optimize' affect the output. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb 'convert' and the resources 'CSS/SCSS to Tailwind classes', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'optimize_classes' or 'suggest_improvements', which might have overlapping functionality with CSS optimization or improvement suggestions.

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 like 'optimize_classes' or 'suggest_improvements'. It lacks context about prerequisites, such as needing valid CSS/SCSS/HTML input, and doesn't mention any exclusions or specific scenarios where this tool is preferred over others.

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/Tai-DT/mcp-tailwind-gemini'

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