Skip to main content
Glama
lenvolk
by lenvolk

toggle_power

Turn LIFX smart lights on or off using a selector and duration control.

Instructions

Toggle power state of lights

Input Schema

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

Implementation Reference

  • The execution logic for the toggle_power tool. It extracts parameters from args, constructs a request body with optional duration, calls the LIFX API toggle endpoint via makeLIFXRequest, and returns a success message with the API response.
    case "toggle_power": { const { token, selector = "all", duration } = args as { token: string; selector?: string; duration?: number; }; const body = duration !== undefined ? { duration } : {}; const result = await makeLIFXRequest(`/lights/${selector}/toggle`, { method: "POST", body, token, }); return { content: [ { type: "text", text: `Power toggled successfully for selector "${selector}". ${JSON.stringify(result, null, 2)}`, }, ], }; }
  • The tool definition including name, description, and input schema registered in the ListTools response.
    { name: "toggle_power", description: "Toggle power state of lights", inputSchema: { type: "object", properties: { token: { type: "string", description: "LIFX API token" }, selector: { type: "string", description: "Selector for filtering lights (default: 'all')" }, duration: { type: "number", minimum: 0, description: "Duration in seconds" }, }, required: ["token"], }, },
  • Utility function to perform authenticated HTTP requests to the LIFX API, used by the toggle_power handler and other tools.
    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