Skip to main content
Glama
lenvolk
by lenvolk

activate_scene

Apply a saved lighting scene to LIFX smart lights by specifying the scene UUID and duration for transition.

Instructions

Activate a scene

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesLIFX API token
scene_uuidYesScene UUID
durationNoDuration in seconds
fastNoFast mode (skip confirmation)

Implementation Reference

  • src/index.ts:234-247 (registration)
    Registration of the activate_scene tool in the ListToolsRequestSchema handler. Includes the tool name, description, and JSON input schema defining parameters: token (required), scene_uuid (required), duration (optional), fast (optional).
    {
      name: "activate_scene",
      description: "Activate a scene",
      inputSchema: {
        type: "object",
        properties: {
          token: { type: "string", description: "LIFX API token" },
          scene_uuid: { type: "string", description: "Scene UUID" },
          duration: { type: "number", minimum: 0, description: "Duration in seconds" },
          fast: { type: "boolean", description: "Fast mode (skip confirmation)" },
        },
        required: ["token", "scene_uuid"],
      },
    },
  • The core handler logic for the activate_scene tool within the CallToolRequestSchema switch statement. Extracts arguments, builds the request body from optional duration and fast params, invokes makeLIFXRequest to PUT /scenes/scene_id:{scene_uuid}/activate, and returns success message with API response.
    case "activate_scene": {
      const { token, scene_uuid, duration, fast } = args as {
        token: string;
        scene_uuid: string;
        duration?: number;
        fast?: boolean;
      };
    
      const body = Object.fromEntries(
        Object.entries({ duration, fast }).filter(([_, value]) => value !== undefined)
      );
    
      const result = await makeLIFXRequest(`/scenes/scene_id:${scene_uuid}/activate`, {
        method: "PUT",
        body,
        token,
      });
    
      return {
        content: [
          {
            type: "text",
            text: `Scene activated successfully. ${JSON.stringify(result, null, 2)}`,
          },
        ],
      };
    }
  • Shared helper function makeLIFXRequest used by the activate_scene handler (and all other tools) to perform authenticated HTTP requests to the LIFX API, handling headers, JSON body, error checking, and response parsing.
    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)}`);
      }
    }
  • TypeScript interface definition for LIFXScene, used in related tools like list_scenes, providing structure for scene data relevant to activate_scene.
    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;
    }

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