Skip to main content
Glama

list_lights

Retrieve all smart lights connected to your LIFX account to view available devices and their current status for management.

Instructions

Get lights belonging to the authenticated account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesLIFX API token
selectorNoSelector for filtering lights (default: 'all')

Implementation Reference

  • The handler function for the 'list_lights' tool that fetches lights from the LIFX API using the provided selector and token, then formats and returns a detailed text summary of each light.
    case "list_lights": { const { token, selector = "all" } = args as { token: string; selector?: string }; const lights = await makeLIFXRequest(`/lights/${selector}`, { token }); return { content: [ { type: "text", text: `Found ${lights.length} lights:\n\n${lights.map((light: LIFXLight) => `• ${light.label} (${light.id})\n Power: ${light.power}\n Brightness: ${(light.brightness * 100).toFixed(1)}%\n Color: H:${light.color.hue}° S:${(light.color.saturation * 100).toFixed(1)}% K:${light.color.kelvin}\n Connected: ${light.connected ? 'Yes' : 'No'}\n Group: ${light.group.name}\n Location: ${light.location.name}` ).join('\n\n')}`, }, ], }; }
  • src/index.ts:143-153 (registration)
    Registers the 'list_lights' tool in the ListTools response, including its name, description, and input schema definition.
    name: "list_lights", description: "Get lights belonging to the authenticated account", inputSchema: { type: "object", properties: { token: { type: "string", description: "LIFX API token" }, selector: { type: "string", description: "Selector for filtering lights (default: 'all')" }, }, required: ["token"], }, },
  • TypeScript interface defining the LIFXLight type used in the list_lights handler for typing the API response.
    interface LIFXLight { id: string; uuid: string; label: string; connected: boolean; power: string; color: { hue: number; saturation: number; kelvin: number; }; brightness: number; group: { id: string; name: string; }; location: { id: string; name: string; }; product: { name: string; identifier: string; company: string; capabilities: { has_color: boolean; has_variable_color_temp: boolean; has_ir: boolean; has_chain: boolean; has_matrix: boolean; has_multizone: boolean; }; }; }
  • Helper function to perform authenticated HTTP requests to the LIFX API, directly used by the list_lights handler.
    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