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)}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('toggle power state') but doesn't explain what 'toggle' entails (e.g., switching between on/off states), potential side effects, authentication needs (implied by 'token' parameter but not described), or rate limits. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste—it directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like what 'toggle' does operationally, error handling, or response format, leaving the agent with insufficient context for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters ('token', 'selector', 'duration') with their types and basic descriptions. The description adds no additional meaning beyond what the schema provides, such as explaining 'selector' options or 'duration' implications, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('toggle') and resource ('power state of lights'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'set_state' or 'effects_off', but the specific action is well-defined.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'set_state' for more granular control or 'effects_off' for stopping effects. The description lacks context about use cases, prerequisites, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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