litra

repository·main·Indexed 41 days ago

https://github.com/timrogers/litra-rs

A tool and Rust library for controlling Logitech Litra lighting devices (Glow, Beam, and Beam LX). It provides a command-line interface, a Model Context Protocol (MCP) server for AI agents, and a Rust crate for application integration. Version 3.3.0 supports power control, brightness (lumens/percentage), color temperature (Kelvin), and RGB backlight management for the Beam LX model.

Tokens
5.1K
Snippets
20
Records
28
Agent score
50%

What's inside litra

  1. Install litra via Homebrew

    main

    On macOS or Linux, you can install the latest version of litra using Homebrew.

    Note for older installations: If you installed via the timrogers/homebrew-tap before January 30, 2026, you should reinstall it from homebrew-core by running: brew uninstall litra && brew install litra.

    brew install litra
  2. Use litra as an MCP server

    main

    You can run litra mcp to start a Model Context Protocol (MCP) server, allowing AI agents (like Claude Desktop) to control your lights.

    Configure Claude Desktop

    Add the following to your mcpServers configuration in the Claude App Config file:

    {
      "mcpServers": {
        "litra": {
          "command": "litra",
          "args": [
            "mcp"
          ]
        }
      }
    }

    Available MCP Tools

    • litra_devices: List devices.
    • litra_on / litra_off / litra_toggle: Power control.
    • litra_brightness / litra_brightness_up / litra_brightness_down: Brightness control (lumens or percentage).
    • litra_temperature / litra_temperature_up / litra_temperature_down: Temperature control (Kelvin, multiples of 100).
    • litra_back_on / litra_back_off / litra_back_toggle: Backlight power.
    • litra_back_brightness / litra_back_brightness_up / litra_back_brightness_down: Backlight brightness (percentage).
    • litra_back_color: Set backlight color (hex code) and optional zone (1-7).
  3. Configure udev permissions on Linux

    main

    On Linux, you must configure udev permissions to allow non-root users to manage Litra devices.

    1. Add your user to the video group: sudo usermod -aG video $USER
    2. Copy the 99-litra.rules file into /etc/udev/rules.d/.
    3. Reload rules and trigger the changes as root: sudo udevadm control --reload-rules sudo udevadm trigger
    sudo usermod -aG video $USER
    # After copying 99-litra.rules to /etc/udev/rules.d/
    sudo udevadm control --reload-rules
    sudo udevadm trigger
  4. Supported DeviceTypes

    main

    The library supports the following Logitech Litra models:

    • LitraGlow: Streaming light with TrueSoft.
    • LitraBeam: LED streaming key light.
    • LitraBeamLX: Dual-sided RGB streaming key light (supports back-side color/brightness controls).
    // Check if a device has a colorful back side
    if device.device_type().has_back_side() {
        // ...
    }
  5. How the Litra MCP Server works

    main

    The LitraMcpServer implements the Model Context Protocol (MCP) to allow AI agents and other clients to control Litra hardware via standard input/output (stdio).

    Architecture

    • Transport: Uses stdio for communication.
    • Routing: Uses a tool_router to map incoming MCP tool calls to specific Rust handler functions.
    • Error Handling: Errors are returned as McpError and communicated back to the client as text content within a CallToolResult error block.
    • Lifecycle: The server is initialized via LitraMcpServer::new(), served via .serve(stdio()), and enters a waiting state with .waiting().

    Implementation Note

    To run the MCP server, the handle_mcp_command() function must be called. This initializes tracing (logging to stderr) and starts the Tokio runtime to manage the asynchronous MCP service.

  6. Target specific Litra devices in CLI commands

    main

    Most litra CLI commands allow you to target specific devices instead of all connected devices. You can use one of the following three methods to filter your target. Note that these options are mutually exclusive: you cannot use more than one at a time.

    • --serial-number (-s): Target a device by its unique serial number.
    • --device-path (-p): Target a device by its system path (useful if the device lacks a serial number).
    • --device-type (-t): Target all devices of a specific type. Supported types are glow, beam, or beam_lx.
    # Examples of targeting specific devices
    litra on --serial-number "12345"
    litra brightness --device-path "/dev/bus/usb/001/002"
    litra off --device-type beam
  7. Initialize and use the Litra context

    main

    To interact with Logitech Litra lights, you must first create a Litra context. This context manages the underlying HID API and provides methods to discover connected devices. Use Litra::new() to initialize the context and get_connected_devices() to retrieve an iterator of available Device objects. If you need to detect newly plugged-in devices, call refresh_connected_devices() on the context.

    use litra::Litra;
    
    let context = Litra::new().expect("Failed to initialize litra.");
    for device in context.get_connected_devices() {
        // Work with device...
    }