Skip to main content
Glama

export_scss

Export color palettes as SCSS variables, maps, and mixins with utility functions for consistent styling in web projects.

Instructions

Generate SCSS variables, maps, and mixins for color palettes with utility functions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that validates input parameters, parses colors, generates SCSS code including variables/maps/mixins, creates additional formats, and returns structured response.
    async function exportScss(
      params: ExportScssParams
    ): Promise<ToolResponse | ErrorResponse> {
      const startTime = Date.now();
    
      try {
        // Validate parameters
        const { error, value: validatedParams } = exportScssSchema.validate(params);
        if (error) {
          return createErrorResponse(
            'export_scss',
            'INVALID_PARAMETERS',
            `Invalid parameters: ${error.details.map(d => d.message).join(', ')}`,
            Date.now() - startTime
          );
        }
    
        // Parse colors
        const colors: UnifiedColor[] = [];
        for (const colorStr of validatedParams.colors) {
          try {
            const color = new UnifiedColor(colorStr);
            colors.push(color);
          } catch {
            return createErrorResponse(
              'export_scss',
              'INVALID_COLOR',
              `Invalid color format: ${colorStr}`,
              Date.now() - startTime,
              {
                details: { provided: colorStr },
                suggestions: [
                  'Use hex format like #FF0000',
                  'Use RGB format like rgb(255, 0, 0)',
                  'Use HSL format like hsl(0, 100%, 50%)',
                ],
              }
            );
          }
        }
    
        // Generate SCSS
        const scss = generateSCSS(colors, validatedParams);
    
        // Generate additional export formats
        const exportFormats = {
          scss,
          css: convertScssToCSS(scss),
          json: {
            colors: colors.map((color, index) => ({
              index: index + 1,
              hex: color.hex,
              rgb: color.rgb,
              hsl: color.hsl,
              semantic_name: validatedParams.semantic_names?.[index],
              variable_name: getVariableName(index, validatedParams),
            })),
            format: validatedParams.format,
            prefix: validatedParams.prefix,
            namespace: validatedParams.namespace,
            metadata: {
              total_colors: colors.length,
              includes_functions: validatedParams.include_functions,
              includes_variants: validatedParams.include_variants,
            },
          },
        };
    
        const executionTime = Date.now() - startTime;
    
        return createSuccessResponse(
          'export_scss',
          {
            scss_output: scss,
            format: validatedParams.format,
            color_count: colors.length,
            prefix: validatedParams.prefix,
            namespace: validatedParams.namespace,
            includes_functions: validatedParams.include_functions,
            includes_variants: validatedParams.include_variants,
          },
          executionTime,
          {
            recommendations: [
              'Use SCSS maps for better organization of large color palettes',
              'Consider using mixins for consistent color application',
              'Use functions for dynamic color manipulation',
            ],
            exportFormats,
          }
        );
      } catch (error) {
        return createErrorResponse(
          'export_scss',
          'PROCESSING_ERROR',
          error instanceof Error ? error.message : 'Unknown error occurred',
          Date.now() - startTime
        );
      }
    }
  • Joi schema defining input parameters for the export_scss tool including colors array, format options, prefixes, flags, and optional semantic names/namespace.
    const exportScssSchema = Joi.object({
      colors: Joi.array()
        .items(Joi.string())
        .min(1)
        .max(100)
        .required()
        .description('Array of colors to export'),
    
      format: Joi.string()
        .valid('variables', 'map', 'mixins', 'all')
        .default('all')
        .description('SCSS format type'),
    
      prefix: Joi.string()
        .pattern(/^[a-zA-Z][a-zA-Z0-9-_]*$/)
        .default('color')
        .description('Prefix for SCSS variable names'),
    
      include_functions: Joi.boolean()
        .default(true)
        .description('Include utility functions and mixins'),
    
      include_variants: Joi.boolean()
        .default(true)
        .description('Include lighter/darker variants'),
    
      semantic_names: Joi.array()
        .items(Joi.string())
        .description('Optional semantic names for colors'),
    
      namespace: Joi.string()
        .pattern(/^[a-zA-Z][a-zA-Z0-9-_]*$/)
        .description('Optional namespace for variables'),
    });
  • ToolHandler object exporting the tool with name, description, schema-derived parameters, and wrapper around the main exportScss handler.
    export const exportScssTool: ToolHandler = {
      name: 'export_scss',
      description:
        'Generate SCSS variables, maps, and mixins for color palettes with utility functions',
      parameters: exportScssSchema.describe(),
      handler: async (params: unknown) => exportScss(params as ExportScssParams),
    };
  • Central registration of the export_scss tool (and related export tools) into the ToolRegistry singleton.
    toolRegistry.registerTool(exportCssTool);
    toolRegistry.registerTool(exportScssTool);
    toolRegistry.registerTool(exportTailwindTool);
    toolRegistry.registerTool(exportJsonTool);
  • Helper function that generates the actual SCSS code: variables, color maps, utility functions, and mixins based on format, prefixes, variants, etc.
    function generateSCSS(
      colors: UnifiedColor[],
      params: ExportScssParams
    ): string {
      const {
        format,
        prefix,
        include_functions,
        include_variants,
        semantic_names,
        namespace,
      } = params;
    
      let scss = '';
      const ns = namespace ? `${namespace}-` : '';
    
      // Header comment
      scss += `// Generated SCSS Color Palette\n`;
      scss += `// Format: ${format}\n`;
      scss += `// Colors: ${colors.length}\n\n`;
    
      // Generate SCSS variables
      if (format === 'variables' || format === 'all') {
        scss += `// Color Variables\n`;
    
        colors.forEach((color, index) => {
          const name = semantic_names?.[index] || `${prefix}-${index + 1}`;
          const safeName = name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
    
          scss += `$${ns}${safeName}: ${color.hex};\n`;
    
          if (include_variants) {
            const lighterColor = new UnifiedColor(
              `hsl(${color.hsl.h}, ${color.hsl.s}%, ${Math.min(100, color.hsl.l + 15)}%)`
            );
            const darkerColor = new UnifiedColor(
              `hsl(${color.hsl.h}, ${color.hsl.s}%, ${Math.max(0, color.hsl.l - 15)}%)`
            );
    
            scss += `$${ns}${safeName}-light: ${lighterColor.hex};\n`;
            scss += `$${ns}${safeName}-dark: ${darkerColor.hex};\n`;
          }
        });
    
        scss += '\n';
      }
    
      // Generate SCSS color map
      if (format === 'map' || format === 'all') {
        scss += `// Color Map\n`;
        scss += `$${ns}colors: (\n`;
    
        colors.forEach((color, index) => {
          const name = semantic_names?.[index] || `${prefix}-${index + 1}`;
          const safeName = name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
    
          scss += `  '${safeName}': ${color.hex},\n`;
    
          if (include_variants) {
            const lighterColor = new UnifiedColor(
              `hsl(${color.hsl.h}, ${color.hsl.s}%, ${Math.min(100, color.hsl.l + 15)}%)`
            );
            const darkerColor = new UnifiedColor(
              `hsl(${color.hsl.h}, ${color.hsl.s}%, ${Math.max(0, color.hsl.l - 15)}%)`
            );
    
            scss += `  '${safeName}-light': ${lighterColor.hex},\n`;
            scss += `  '${safeName}-dark': ${darkerColor.hex},\n`;
          }
        });
    
        scss += `);\n\n`;
      }
    
      // Generate utility functions and mixins
      if ((format === 'mixins' || format === 'all') && include_functions) {
        scss += `// Utility Functions\n`;
    
        // Color getter function
        scss += `@function ${ns}color($name) {\n`;
        scss += `  @if map-has-key($${ns}colors, $name) {\n`;
        scss += `    @return map-get($${ns}colors, $name);\n`;
        scss += `  }\n`;
        scss += `  @warn "Color '#{$name}' not found in $${ns}colors map";\n`;
        scss += `  @return null;\n`;
        scss += `}\n\n`;
    
        // Background color mixin
        scss += `// Background Color Mixin\n`;
        scss += `@mixin ${ns}bg-color($name, $opacity: 1) {\n`;
        scss += `  $color: ${ns}color($name);\n`;
        scss += `  @if $color {\n`;
        scss += `    @if $opacity == 1 {\n`;
        scss += `      background-color: $color;\n`;
        scss += `    } @else {\n`;
        scss += `      background-color: rgba($color, $opacity);\n`;
        scss += `    }\n`;
        scss += `  }\n`;
        scss += `}\n\n`;
    
        // Text color mixin
        scss += `// Text Color Mixin\n`;
        scss += `@mixin ${ns}text-color($name, $opacity: 1) {\n`;
        scss += `  $color: ${ns}color($name);\n`;
        scss += `  @if $color {\n`;
        scss += `    @if $opacity == 1 {\n`;
        scss += `      color: $color;\n`;
        scss += `    } @else {\n`;
        scss += `      color: rgba($color, $opacity);\n`;
        scss += `    }\n`;
        scss += `  }\n`;
        scss += `}\n\n`;
    
        // Border color mixin
        scss += `// Border Color Mixin\n`;
        scss += `@mixin ${ns}border-color($name, $width: 1px, $style: solid) {\n`;
        scss += `  $color: ${ns}color($name);\n`;
        scss += `  @if $color {\n`;
        scss += `    border: $width $style $color;\n`;
        scss += `  }\n`;
        scss += `}\n\n`;
    
        // Theme mixin
        scss += `// Theme Mixin\n`;
        scss += `@mixin ${ns}theme($background, $text, $accent: null) {\n`;
        scss += `  @include ${ns}bg-color($background);\n`;
        scss += `  @include ${ns}text-color($text);\n`;
        scss += `  \n`;
        scss += `  @if $accent {\n`;
        scss += `    a, .accent {\n`;
        scss += `      @include ${ns}text-color($accent);\n`;
        scss += `    }\n`;
        scss += `  }\n`;
        scss += `}\n\n`;
      }
    
      return scss;
    }
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 tool 'generates' SCSS code, implying a read-only output operation, but doesn't clarify if it modifies any state, requires specific permissions, has rate limits, or what the output format looks like (e.g., file, string). For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 that front-loads the core purpose without unnecessary words. It directly states what the tool does ('Generate SCSS variables, maps, and mixins') and the context ('for color palettes with utility functions'), with zero waste or redundancy.

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 the tool's complexity (7 parameters, no output schema, no annotations), the description is minimally adequate. It covers the purpose but lacks behavioral details, usage guidelines, and output information. With no annotations or output schema, the description should do more to compensate, but it only meets the bare minimum for understanding what the tool produces.

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%, meaning all parameters are documented in the schema itself. The description doesn't add any parameter-specific details beyond what's in the schema (e.g., it doesn't explain how 'colors' array maps to SCSS output or what 'utility functions' entail). With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but doesn't need to.

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 tool's purpose: 'Generate SCSS variables, maps, and mixins for color palettes with utility functions.' It specifies the verb ('generate'), resource ('SCSS variables, maps, and mixins'), and context ('color palettes with utility functions'). However, it doesn't explicitly distinguish this from sibling tools like 'export_css' or 'export_json' beyond mentioning SCSS format.

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 doesn't mention sibling tools like 'export_css' or 'export_json' for comparison, nor does it specify prerequisites, constraints, or typical use cases. The agent 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/keyurgolani/ColorMcp'

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