Skip to main content
Glama

analyze_color

Analyze color properties like brightness, temperature, contrast, and accessibility, with optional comparison to another color for design evaluation.

Instructions

Analyze color properties including brightness, temperature, contrast, accessibility, and optionally compare with another color

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler function executing the core logic: input validation, color parsing, analysis delegation to ColorAnalyzer, summary generation, recommendations, and response formatting.
    export async function analyzeColor(
      params: AnalyzeColorParams
    ): Promise<ToolResponse | ErrorResponse> {
      const startTime = Date.now();
    
      try {
        // Validate input parameters using Joi schema
        const validation = validateInput(analyzeColorSchema, params);
        if (!validation.isValid) {
          logger.warn('Color analysis validation failed', {
            tool: 'analyze_color',
            executionTime: Date.now() - startTime,
          });
          return createValidationErrorResponse(
            'analyze_color',
            validation.error!,
            Date.now() - startTime
          );
        }
    
        const validatedParams = validation.value!;
    
        // Parse colors
        const color = new UnifiedColor(validatedParams.color);
        let compareColor: UnifiedColor | undefined;
    
        if (validatedParams.compare_color) {
          compareColor = new UnifiedColor(validatedParams.compare_color);
        }
    
        const analysisTypes = validatedParams.analysis_types;
    
        // Perform analysis
        const analysis = ColorAnalyzer.analyzeColor(
          color,
          analysisTypes,
          compareColor
        );
    
        // Calculate overall score and generate summary
        const summary = generateAnalysisSummary(analysis);
    
        // Prepare response data
        const responseData: AnalyzeColorResponse = {
          color: params.color,
          analysis,
          summary,
        };
    
        if (compareColor && analysis.distance) {
          responseData.comparison = {
            compare_color: params.compare_color!,
            distance: analysis.distance,
          };
        }
    
        const executionTime = Date.now() - startTime;
    
        // Generate accessibility notes
        const accessibilityNotes: string[] = [];
        if (!analysis.accessibility.wcag_aa_normal) {
          accessibilityNotes.push(
            'Does not meet WCAG AA standards for normal text'
          );
        }
        if (!analysis.accessibility.color_blind_safe) {
          accessibilityNotes.push('May be difficult for color-blind users');
        }
        if (analysis.contrast.best_contrast < 3.0) {
          accessibilityNotes.push('Very low contrast - avoid using for text');
        }
    
        // Generate recommendations
        const recommendations: string[] = [
          ...analysis.accessibility.recommendations,
        ];
    
        if (analysis.brightness.brightness_category === 'very_dark') {
          recommendations.push(
            'Consider using white or light text on this background'
          );
        } else if (analysis.brightness.brightness_category === 'very_light') {
          recommendations.push('Consider using dark text on this background');
        }
    
        if (analysis.temperature.temperature === 'warm') {
          recommendations.push(
            'This warm color works well for energetic, friendly designs'
          );
        } else if (analysis.temperature.temperature === 'cool') {
          recommendations.push(
            'This cool color works well for professional, calming designs'
          );
        }
    
        return createSuccessResponse('analyze_color', responseData, executionTime, {
          colorSpaceUsed: 'sRGB',
          accessibilityNotes: accessibilityNotes,
          recommendations: recommendations.slice(0, 5), // Limit to top 5 recommendations
        });
      } catch (error) {
        const executionTime = Date.now() - startTime;
        return createErrorResponse(
          'analyze_color',
          'ANALYSIS_ERROR',
          `Failed to analyze color: ${error instanceof Error ? error.message : 'Unknown error'}`,
          executionTime,
          {
            details: {
              color: params.color,
            },
            suggestions: [
              'Check that the color format is supported',
              'Try a different color format',
            ],
          }
        );
      }
    }
  • Joi validation schema defining input parameters for analyze_color tool: color (required), analysis_types (array), compare_color (optional), include_recommendations (boolean).
    export const analyzeColorSchema = Joi.object({
      color: colorSchema,
      analysis_types: Joi.array()
        .items(
          Joi.string().valid(
            'brightness',
            'contrast',
            'temperature',
            'accessibility',
            'all'
          )
        )
        .min(1)
        .max(10) // Prevent excessive analysis types
        .default(['all'])
        .messages({
          'array.min': 'At least one analysis type must be specified',
          'array.max': 'Too many analysis types (max 10)',
        }),
      compare_color: colorSchema.optional(),
      include_recommendations: Joi.boolean().default(true),
    }).required();
  • Central registration of the analyze_color tool into the ToolRegistry singleton, making it available for MCP execution.
    toolRegistry.registerTool(analyzeColorTool);
  • Tool definition object with name, description, parameters schema, and handler wrapper that invokes the main analyzeColor function.
    export const analyzeColorTool = {
      name: 'analyze_color',
      description:
        'Analyze color properties including brightness, temperature, contrast, accessibility, and optionally compare with another color',
      parameters: analyzeColorSchema.describe(),
      handler: async (params: unknown) =>
        analyzeColor(params as AnalyzeColorParams),
    };
  • Core static method in ColorAnalyzer class that orchestrates detailed analysis of brightness, temperature, contrast, accessibility, and optional distance comparison.
    static analyzeColor(
      color: UnifiedColor,
      _analysisTypes: string[] = ['all'],
      compareColor?: UnifiedColor
    ): ColorAnalysisResult {
      const result: ColorAnalysisResult = {
        brightness: this.analyzeBrightness(color),
        temperature: this.analyzeTemperature(color),
        contrast: this.analyzeContrast(color),
        accessibility: this.analyzeAccessibility(color),
      };
    
      // Add distance analysis if comparison color provided
      if (compareColor) {
        result.distance = this.analyzeDistance(color, compareColor);
      }
    
      return result;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions what properties are analyzed, it doesn't describe the tool's behavior: what format the analysis returns, whether it's a read-only operation, if there are rate limits, computational costs, or what happens when 'include_recommendations' is enabled. For a tool with 4 parameters and no 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 that communicates the core functionality without wasted words. It's appropriately sized for the tool's complexity and front-loads the essential information about what properties are analyzed.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the analysis returns, how results are structured, what 'recommendations' entail, or provide behavioral context needed for proper tool selection. The description should compensate for the lack of structured metadata but doesn't.

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 mentions 'optionally compare with another color' which hints at the 'compare_color' parameter, but doesn't add meaningful semantic context beyond what's in the schema. The baseline of 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 tool's purpose: 'Analyze color properties including brightness, temperature, contrast, accessibility, and optionally compare with another color'. It specifies the verb ('analyze') and resources (color properties), but doesn't explicitly differentiate from sibling tools like 'check_contrast' or 'optimize_for_accessibility' which might have overlapping functionality.

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. With many sibling tools for color analysis and manipulation (e.g., 'check_contrast', 'optimize_for_accessibility', 'simulate_colorblindness'), there's no indication of when this comprehensive analysis tool is preferred over more specialized alternatives.

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