Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@DLI Power Switch MCP ServerShow me the status of all connected power switches"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
DLI Power Switch MCP Server
Overview
This project implements a Model Context Protocol (MCP) server that allows an AI agent to control Digital Loggers (DLI). The system provides tools for discovering hardware, querying outlet status, and performing power operations (On/Off/Cycle).
Crucial Constraint: This system interacts with physical hardware. Strict safety protocols are enforced to prevent accidental power loss to critical infrastructure.
Key Files
server.py: The main entry point. Contains the FastMCP server implementation, tool definitions, and hardware interaction logic using thepower-switch-prolibrary.switches_config.json: The source of truth for device configuration. Defines IP addresses, authentication, outlet aliases, and safety types (standard,critical,prohibited).requirements.txt: Python dependencies (power-switch-pro).tests/: Unit tests for the server logic.
Architecture & Performance
This server is designed for responsiveness and safety:
Asynchronous Core: Built on Python's
asyncioto handle multiple operations efficiently.Non-Blocking I/O: Interactions with physical hardware (which can be slow) are offloaded to background threads, ensuring the main server loop remains responsive.
Parallel Discovery: The
get_inventorytool fetches status from all configured switches concurrently, significantly reducing latency in systems with multiple devices.
Installation
Install this server from PyPI using pip:
Configuring with Gemini CLI (and Antigravity)
Once installed, register the server with the Gemini CLI (or Antigravity) using the mcp add command. This ensures the server starts automatically.
Parameters:
The first
dli-mcp-serveris the name you assign to this server instance.The second
dli-mcp-serveris the command that runs the server (made available bypip install).-e DLI_MCP_CONFIG="...": (Optional) Sets the environment variable for the configuration file path. If omitted, it defaults toswitches_config.jsonin the current directory.-s useror-s project: (Optional) Sets the configuration scope. Defaults toproject.
Command-Line Usage
The server.py script can be used directly from the command line to control the power switches.
inventory
Lists all switches and their outlet statuses.
power_action
Performs a power action (on, off, cycle) on a specific outlet.
switch_id: Alias or IP address of the switch.
outlet_id: Index or name of the outlet.action:on,off, orcycle.--confirmation: Required for critical outlets.
group_power_action
Performs a power action on a group of outlets.
sync_config_from_hardware
Synchronizes outlet names from the hardware.
list_outlets
Lists all outlets on a given switch.
add_switch
Adds a new DLI power switch to the configuration. If the configuration file does not exist, it will be automatically created.
ip_address: IP address of the new switch.
username: Username for the new switch.password: Password for the new switch.
remove_switch
Removes a DLI power switch from the configuration.
switch_id: Alias or IP address of the switch to remove.
update_outlet
Updates the definition of an outlet.
switch_id: Alias or IP address of the switch.
outlet_id: Index or name of the outlet (e.g., "Modem" or "1").--name: New name for the outlet.--description: New description for the outlet.--type: New type for the outlet (standard,critical, orprohibited).
Type | Agent Permission | Behavior |
| Full Access | Can be turned On, Off, or Cycled immediately. |
| Restricted | "Off" or "Cycle" actions require explicit user confirmation ( |
| No Access | NEVER modify this outlet. The server will raise a |
Available Tools
1. get_inventory()
Purpose: The "eyes" of the agent. Call this first to see what switches and outlets are available and their current state (ON/OFF).
Returns: A JSON object containing all switches, outlets, groups, and their descriptions.
2. power_action(switch_id, outlet_id, action, confirmation="NO")
Purpose: Controls a specific physical outlet.
Inputs:
switch_id: The Alias (e.g., "garage_rack") or IP.outlet_id: The Name (e.g., "Modem") or Index (e.g., "1").action: "on", "off", or "cycle".confirmation: Must be set to "YES" only if the user has explicitly approved a dangerous action on acriticaloutlet.
3. group_power_action(target, action)
Purpose: Controls a logical group of outlets (e.g., "Restart the Network Stack").
Behavior: Executes sequentially. If any member of the group is
prohibited, the entire operation aborts immediately.
4. sync_config_from_hardware(switch_id)
Purpose: Updates the
switches_config.jsonfile with the actual outlet names found on the device.Note: This does not overwrite safety types (
critical/prohibited) or descriptions.
5. add_switch(ip_address, username, password)
Purpose: Adds a new DLI power switch to the configuration.
Inputs:
ip_address: IP address of the new switch.username: Username for the new switch.password: Password for the new switch.
6. remove_switch(switch_id)
Purpose: Removes a DLI power switch from the configuration.
Inputs:
switch_id: Alias or IP address of the switch to remove.
7. list_outlets(switch_id)
Purpose: Lists all outlets and their status for a given switch.
Inputs:
switch_id: The Alias or IP address of the switch.
Returns: A JSON array of outlet information.
8. update_outlet(switch_id, outlet_id, new_name=None, new_description=None, new_type=None)
Purpose: Updates the definition of an outlet in the configuration file and writes the new name to the hardware.
Inputs:
switch_id: The Alias or IP address of the switch.outlet_id: The Name or Index (e.g., "Modem" or "1").new_name(optional): The new name for the outlet. This is written to both the config file and the hardware.new_description(optional): The new description for the outlet. This is only written to the config file.new_type(optional): The new type for the outlet (standard,critical, orprohibited). This is only written to the config file.
Returns: A success message.
Operational Guidelines for the Agent
Always Check Inventory First: Before assuming an outlet exists or knowing its status, run
get_inventory.Respect "Prohibited" Outlets: If a user asks to turn off a prohibited device (e.g., "Security DVR"), explain that you cannot do so because it is restricted in the configuration.
Handle "Critical" Warnings: If
power_actionreturns a "SAFETY LOCK" message, stop and ask the user: "This is a critical device. Are you sure you want to turn it off?". Only proceed if they say "Yes".Use Aliases: Prefer using the friendly
aliasandname(e.g., "garage_rack", "Modem") over IP addresses and indices when communicating with the user.
Testing
The project includes a suite of unit tests to ensure the server logic is correct. The tests are located in the tests/ directory.
To run the tests, first install the testing dependencies:
Then, use the following command to run the tests:
The tests are designed to run without a physical DLI power switch. They use mocking to simulate the hardware and its behavior.
Automated Testing
The project uses GitHub Actions for continuous integration. Tests are automatically executed on every push and pull request to the main branch. The workflow runs on:
Operating Systems: Windows, Linux (Ubuntu), and macOS.
Python Versions: 3.10, 3.11, and 3.12.
This ensures cross-platform compatibility and stability across supported Python versions.
Test Coverage
To check the test coverage, you can use the coverage package (which is included in tests/requirements.txt).
Run the tests with coverage and generate a report:
The project aims for a high test coverage to ensure reliability.
Configuring with Gemini CLI (and Antigravity)
You can easily register this MCP server with the Gemini CLI (or Antigravity) using the mcp add command. This ensures the server starts automatically.
Windows:
Linux / macOS:
Parameters:
dli-mcp-server: The name you assign to the server.python "...": The command to start the server. Ensure you provide the full absolute path toserver.py.-e DLI_MCP_CONFIG="...": (Optional) Sets the environment variable for the configuration file path. If omitted, it defaults toswitches_config.jsonin the server's directory.-s user: Saves the configuration to your user settings (global), making it available across all projects.-s project(Default): Saves the configuration to the current project's.gemini/settings.json. Use this if you want the server configuration to be specific to the current workspace.
Configuration
By default, the server uses the switches_config.json file in the same directory. You can override this by setting the DLI_MCP_CONFIG environment variable to the path of your configuration file.
Example:
This is particularly useful for testing with different configurations without modifying the main switches_config.json file.
Example Interactions
User: "Turn off the Router."
Agent Action:
Calls
get_inventory(internal) -> sees Router iscritical.Calls
power_action("garage_rack", "Router", "off").Result: Returns "SAFETY LOCK...".
Agent Response: "The Router is marked as a critical device. Are you sure you want to turn it off?"
User: "Yes, do it."
Agent Action:
Calls
power_action("garage_rack", "Router", "off", confirmation="YES").Result: "Success..."
Agent Response: "The Router has been turned off."
Development Information
This MCP server was developed using Gemini CLI and Gemini 3.0 models.