Skip to main content
Glama
lenvolk
by lenvolk

validate_color

Check if a color string is valid for LIFX smart lights before applying it to ensure proper lighting control.

Instructions

Validate a color string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesLIFX API token
colorYesColor string to validate

Implementation Reference

  • The handler executes the validate_color tool by sending the color string to the LIFX /color API endpoint for validation and parsing, then returns the parsed result.
    case "validate_color": {
      const { token, color } = args as { token: string; color: string };
      const result = await makeLIFXRequest(`/color?color=${encodeURIComponent(color)}`, { token });
    
      return {
        content: [
          {
            type: "text",
            text: `Color validation result:\n${JSON.stringify(result, null, 2)}`,
          },
        ],
      };
    }
  • src/index.ts:248-259 (registration)
    Registration of the validate_color tool, including its name, description, and input schema definition.
    {
      name: "validate_color",
      description: "Validate a color string",
      inputSchema: {
        type: "object",
        properties: {
          token: { type: "string", description: "LIFX API token" },
          color: { type: "string", description: "Color string to validate" },
        },
        required: ["token", "color"],
      },
    },
  • Input schema defining the parameters for the validate_color tool: LIFX token and color string.
    inputSchema: {
      type: "object",
      properties: {
        token: { type: "string", description: "LIFX API token" },
        color: { type: "string", description: "Color string to validate" },
      },
      required: ["token", "color"],
    },
  • Shared helper function used by all tools, including validate_color, to make authenticated HTTP requests to the LIFX API.
    async function makeLIFXRequest(
      endpoint: string,
      options: {
        method?: string;
        body?: any;
        token: string;
      }
    ): Promise<any> {
      const { method = "GET", body, token } = options;
      
      const url = `${LIFX_API_BASE}${endpoint}`;
      const headers: Record<string, string> = {
        "Authorization": `Bearer ${token}`,
        "User-Agent": USER_AGENT,
      };
    
      if (body && (method === "POST" || method === "PUT")) {
        headers["Content-Type"] = "application/json";
      }
    
      try {
        const response = await fetch(url, {
          method,
          headers,
          body: body ? JSON.stringify(body) : undefined,
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          throw new Error(`LIFX API error: ${response.status} ${response.statusText} - ${errorText}`);
        }
    
        // Some endpoints return empty responses
        const contentType = response.headers.get("content-type");
        if (contentType?.includes("application/json")) {
          return await response.json();
        }
        
        return await response.text();
      } catch (error) {
        throw new Error(`Failed to make LIFX API request: ${error instanceof Error ? error.message : String(error)}`);
      }
    }

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/lenvolk/mcp-lifx'

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