list_scenes
Retrieve all available lighting scenes from your LIFX account to manage and apply preset configurations for smart lights.
Instructions
List all scenes available in the account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | LIFX API token |
Implementation Reference
- src/index.ts:421-435 (handler)The handler for the 'list_scenes' tool. It extracts the LIFX token from arguments, calls makeLIFXRequest to fetch scenes from the '/scenes' endpoint, and returns a formatted text response listing the scenes with their names, UUIDs, state counts, and creation dates.case "list_scenes": { const { token } = args as { token: string }; const scenes = await makeLIFXRequest("/scenes", { token }); return { content: [ { type: "text", text: `Found ${scenes.length} scenes:\n\n${scenes.map((scene: LIFXScene) => `• ${scene.name} (${scene.uuid})\n States: ${scene.states.length} lights\n Created: ${new Date(scene.created_at * 1000).toLocaleDateString()}` ).join('\n\n')}`, }, ], }; }
- src/index.ts:223-233 (registration)Registration of the 'list_scenes' tool in the listTools handler, defining its name, description, and input schema requiring a LIFX API token.{ name: "list_scenes", description: "List all scenes available in the account", inputSchema: { type: "object", properties: { token: { type: "string", description: "LIFX API token" }, }, required: ["token"], }, },
- src/index.ts:51-69 (schema)TypeScript interface definition for LIFXScene, used to type the response data in the list_scenes handler.interface LIFXScene { uuid: string; name: string; account: { uuid: string; }; states: Array<{ selector: string; power: string; brightness: number; color: { hue: number; saturation: number; kelvin: number; }; }>; created_at: number; updated_at: number; }
- src/index.ts:72-114 (helper)Helper function used by list_scenes (and other tools) 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)}`); } }