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
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | LIFX API token | |
| color | Yes | Color string to validate |
Implementation Reference
- src/index.ts:465-477 (handler)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"], }, },
- src/index.ts:251-258 (schema)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"], },
- src/index.ts:72-114 (helper)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)}`); } }