Skip to main content
Glama
CarbonoDev

TailwindCSS MCP Server

by CarbonoDev

convert_css_to_tailwind

Convert traditional CSS code into TailwindCSS utility classes for streamlined development. Choose output formats like inline classes, component directives, or space-separated utilities.

Instructions

Convert traditional CSS to TailwindCSS utility classes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cssYesCSS code to convert to TailwindCSS utilities
modeNoOutput format: 'classes' for space-separated utilities, 'inline' for class attribute, 'component' for @apply directive (default: classes)

Implementation Reference

  • The implementation of convertCSSToTailwind, which processes CSS and maps it to Tailwind utility classes.
    async convertCSSToTailwind(css: string, mode: "inline" | "classes" | "component" = "classes"): Promise<ConversionResult> {
      try {
        const result = await postcss().process(css, { from: undefined });
        const root = result.root;
    
        const tailwindClasses: string[] = [];
        const unsupportedStyles: string[] = [];
        const suggestions: string[] = [];
    
        root.walkDecls((decl) => {
          const cssProperty = decl.prop;
          const cssValue = decl.value;
          
          const utilities = this.cssPropertyMap.get(cssProperty);
          
          if (utilities && utilities.length > 0) {
            const matchingUtility = this.findBestUtilityMatch(cssProperty, cssValue);
            if (matchingUtility) {
              tailwindClasses.push(matchingUtility);
            } else {
              // Try to create arbitrary value
              const arbitraryUtility = this.createArbitraryUtility(cssProperty, cssValue);
              if (arbitraryUtility) {
                tailwindClasses.push(arbitraryUtility);
                suggestions.push(`Consider using ${arbitraryUtility} for ${cssProperty}: ${cssValue}`);
              } else {
                unsupportedStyles.push(`${cssProperty}: ${cssValue}`);
              }
            }
          } else {
            unsupportedStyles.push(`${cssProperty}: ${cssValue}`);
          }
        });
    
        return {
          tailwindClasses: tailwindClasses.join(' '),
          unsupportedStyles: unsupportedStyles.length > 0 ? unsupportedStyles : undefined,
          suggestions: suggestions.length > 0 ? suggestions : undefined,
        };
    
      } catch (error) {
        throw new ServiceError(
          'Failed to convert CSS to TailwindCSS',
          'UtilityMapperService',
          'convertCSSToTailwind',
          error
        );
      }
    }
  • src/index.ts:199-215 (registration)
    Tool registration for convert_css_to_tailwind in the MCP server.
    name: "convert_css_to_tailwind",
    description: "Convert traditional CSS to TailwindCSS utility classes",
    inputSchema: {
      type: "object",
      properties: {
        css: {
          type: "string",
          description: "CSS code to convert to TailwindCSS utilities",
        },
        mode: {
          type: "string",
          enum: ["inline", "classes", "component"],
          description: "Output format: 'classes' for space-separated utilities, 'inline' for class attribute, 'component' for @apply directive (default: classes)",
        },
      },
      required: ["css"],
    },
  • The handler function that links the MCP tool request to the utility-mapper service.
    private async handleConvertCSSToTailwind(args: any): Promise<any> {
      try {
        const params = this.validateConvertCSSParams(args);
        const result = await this.conversionService.convertCSS(params);
        return this.createSuccessResponse(result);
      } catch (error) {
        this.handleServiceError(error, "Failed to convert CSS to TailwindCSS");
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only transformation or has side effects, error handling, performance characteristics, or output format beyond what's implied by parameters. For a conversion tool with zero annotation coverage, this is insufficient.

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—front-loaded and exactly conveys the core purpose without unnecessary elaboration. Every word earns its place.

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

Completeness3/5

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

Given 2 parameters with full schema coverage and no output schema, the description is minimally complete for a conversion tool but lacks context on behavioral traits due to no annotations. It's adequate but has clear gaps in usage and transparency.

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 parameters are fully documented in the schema. The description adds no additional meaning beyond implying conversion, which aligns with the schema. 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.

Purpose5/5

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

The description clearly states the specific action ('Convert') and target resources ('traditional CSS to TailwindCSS utility classes'), distinguishing it from sibling tools that generate palettes, templates, colors, configs, utilities, install, or search docs. It precisely defines the transformation being performed.

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 'get_tailwind_utilities' or 'generate_component_template', nor does it mention prerequisites or context for conversion. It states what the tool does but not when it's appropriate.

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/CarbonoDev/tailwindcss-mcp-server'

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