Power Switch Pro MCP Server

Power Switch Pro MCP Server

MCP server for controlling and monitoring Digital Loggers Power Switch Pro devices, enabling outlet control, power monitoring, and device management through natural language.

Category
访问服务器

README

Power Switch Pro MCP Server

An MCP (Model Context Protocol) server that provides tools for controlling and monitoring Digital Loggers Power Switch Pro devices. This allows AI assistants and other MCP clients to interact with your power switch hardware.

Features

  • 🔌 Outlet Control - Turn outlets on/off/cycle individually or in bulk
  • 📊 Power Monitoring - Read real-time voltage, current, power, and energy metrics
  • 📝 Device Management - Get device info and configure outlet names
  • 🔒 Secure - Uses HTTP Digest Authentication via environment variables
  • 🚀 Easy Integration - Works with any MCP-compatible client (Warp, Claude Desktop, etc.)
  • 🌐 Multiple Transports - Supports both stdio (local) and HTTP (remote) via MCP streamable-http transport
  • 🐳 Docker Ready - Easy containerized deployment with docker-compose

Installation

Prerequisites

  • Python 3.10 or higher
  • A Digital Loggers Power Switch Pro device with firmware 1.7.0+
  • Network access to your device

Install from Source

git clone https://github.com/bryankemp/power-switch-pro-mcp.git
cd power-switch-pro-mcp
pip install .

Configuration

The MCP server is configured via environment variables:

  • POWER_SWITCH_HOST - IP address or hostname of your device (required)
  • POWER_SWITCH_PASSWORD - Admin password (required)
  • POWER_SWITCH_USERNAME - Username (default: "admin")
  • POWER_SWITCH_USE_HTTPS - Use HTTPS instead of HTTP (default: "false")

For Warp

Add to your Warp MCP settings configuration file:

{
  "mcpServers": {
    "power-switch-pro": {
      "command": "python",
      "args": ["-m", "power_switch_pro_mcp.server"],
      "env": {
        "POWER_SWITCH_HOST": "192.168.0.100",
        "POWER_SWITCH_PASSWORD": "your-password",
        "POWER_SWITCH_USERNAME": "admin",
        "POWER_SWITCH_USE_HTTPS": "false"
      }
    }
  }
}

For Claude Desktop

Add to your Claude Desktop MCP settings (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "power-switch-pro": {
      "command": "python",
      "args": ["-m", "power_switch_pro_mcp.server"],
      "env": {
        "POWER_SWITCH_HOST": "192.168.0.100",
        "POWER_SWITCH_PASSWORD": "your-password",
        "POWER_SWITCH_USERNAME": "admin"
      }
    }
  }
}

Note: POWER_SWITCH_USERNAME is optional and defaults to "admin" if not specified.

For Other MCP Clients

Refer to your MCP client's documentation for how to configure external MCP servers. You'll need to:

  1. Set the command to run: python -m power_switch_pro_mcp.server
  2. Configure the required environment variables

Available Tools

The server exposes the following MCP tools:

Outlet Control

  • outlet_on - Turn on a specific outlet

    • Parameters: outlet_id (0-7)
  • outlet_off - Turn off a specific outlet

    • Parameters: outlet_id (0-7)
  • outlet_cycle - Power cycle an outlet (off, wait, on)

    • Parameters: outlet_id (0-7)
  • bulk_outlet_operation - Perform operations on multiple outlets

    • Parameters: action ("on", "off", or "cycle"), optional outlet_ids array

Status and Monitoring

  • get_outlet_state - Get the power state of a specific outlet

    • Parameters: outlet_id (0-7)
  • get_all_outlet_states - Get power states of all outlets

  • get_outlet_info - Get detailed info about an outlet (name, state, lock status)

    • Parameters: outlet_id (0-7)
  • get_power_metrics - Get real-time power measurements (voltage, current, power, energy)

  • get_device_info - Get device information (serial, firmware version, etc.)

Configuration

  • set_outlet_name - Rename an outlet
    • Parameters: outlet_id (0-7), name (string, max 16 chars)

Usage Examples

Once configured, you can use natural language with your MCP client:

"Turn on outlet 3"
"What's the current power consumption?"
"Cycle the server outlet"
"Show me all outlet states"
"Rename outlet 0 to 'Lab Server'"
"Turn off all outlets"

Running the Server

Stdio Transport (Local)

For local MCP clients like Claude Desktop or Warp:

# Set environment variables
export POWER_SWITCH_HOST="192.168.0.100"
export POWER_SWITCH_PASSWORD="your-password"
export POWER_SWITCH_USERNAME="admin"  # Optional, defaults to "admin"

# Run the stdio server
python -m power_switch_pro_mcp.server

The server will start and wait for MCP protocol messages on stdin/stdout.

HTTP Transport (Remote)

For remote access using the MCP streamable-http transport:

# Set environment variables
export POWER_SWITCH_HOST="192.168.0.100"
export POWER_SWITCH_PASSWORD="your-password"
export POWER_SWITCH_USERNAME="admin"  # Optional, defaults to "admin"

# Run the HTTP server (default port 5000)
python -m power_switch_pro_mcp.http_server

# Or specify a custom port
PORT=3000 python -m power_switch_pro_mcp.http_server

The HTTP server will be available at http://localhost:5000 and supports the MCP streamable-http protocol.

Docker Deployment

Using Pre-built Image from GitHub Container Registry

The easiest way to run the server is using the pre-built Docker image:

# Pull the latest image
docker pull ghcr.io/bryankemp/power-switch-pro-mcp:latest

# Run the container
docker run -d \
  -p 5000:5000 \
  -e POWER_SWITCH_HOST="192.168.0.100" \
  -e POWER_SWITCH_PASSWORD="your-password" \
  -e POWER_SWITCH_USERNAME="admin" \
  --name power-switch-pro-mcp \
  ghcr.io/bryankemp/power-switch-pro-mcp:latest

Using Docker Compose (Recommended)

# Copy and configure environment variables
cp .env.docker .env
# Edit .env with your Power Switch Pro settings

# Start the server
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the server
docker-compose down

Using Docker Directly

# Build the image
docker build -t power-switch-pro-mcp .

# Run the container
docker run -d \
  -p 5000:5000 \
  -e POWER_SWITCH_HOST="192.168.0.100" \
  -e POWER_SWITCH_PASSWORD="your-password" \
  -e POWER_SWITCH_USERNAME="admin" \
  --name power-switch-pro-mcp \
  power-switch-pro-mcp

# View logs
docker logs -f power-switch-pro-mcp

# Stop the container
docker stop power-switch-pro-mcp

CI/CD

This project uses GitHub Actions to automatically build and publish Docker images to GitHub Container Registry (ghcr.io).

Automated Docker Builds

Docker images are automatically built and published:

  • On every push to main: Tagged as latest and main-{sha}
  • On version tags (e.g., v1.0.0): Tagged with semantic versions
  • On pull requests: Built but not published (for testing)

The workflow builds multi-platform images for:

  • linux/amd64 (x86_64)
  • linux/arm64 (ARM64/Apple Silicon)

Available Tags

  • latest - Latest stable build from main branch
  • v1.0.0, v1.0, v1 - Semantic version tags
  • main-{sha} - Specific commit from main branch

Development

Setting Up Development Environment

# Clone the repository
git clone https://github.com/bryankemp/power-switch-pro-mcp.git
cd power-switch-pro-mcp

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

Code Quality

This project uses:

  • Black - Code formatting (line length: 100)
  • Ruff - Fast Python linting
  • mypy - Static type checking
  • pytest - Testing framework
  • pre-commit - Git hooks for code quality

Run checks:

# Format code
black src

# Lint code
ruff check src

# Type check
mypy src

# Run all checks together
black src && ruff check src && mypy src

# Run tests
pytest

Git Hooks

The project includes automated git hooks for code quality and Docker testing:

Pre-commit Hooks

Automatically run on every commit:

  • Black code formatting
  • Ruff linting
  • mypy type checking
  • YAML/TOML validation

Pre-push Hook

Automatically run before every push:

  • Docker image build test
  • Container runtime verification
  • HTTP endpoint health check

Installation

# Install pre-commit framework
pip install pre-commit

# Install all git hooks
pre-commit install
./hooks/install.sh

# Run hooks manually on all files
pre-commit run --all-files

Project Structure

power-switch-pro-mcp/
├── src/
│   └── power_switch_pro_mcp/
│       ├── __init__.py
│       ├── server.py          # Stdio MCP server implementation
│       └── http_server.py     # HTTP MCP server implementation
├── docs/                       # Sphinx documentation
├── tests/                      # Test suite
├── hooks/                      # Git hooks
│   ├── pre-push               # Pre-push hook (Docker testing)
│   └── install.sh             # Hook installation script
├── Dockerfile                  # Docker container definition
├── docker-compose.yml         # Docker Compose configuration
├── .pre-commit-config.yaml    # Pre-commit hooks configuration
├── pyproject.toml             # Project configuration
├── README.md                  # This file
├── LICENSE                    # BSD-3-Clause license
├── .env.example               # Example environment configuration
└── .env.docker                # Docker environment template

Security Considerations

  • Never commit credentials - Use environment variables or secure configuration
  • Use HTTPS - Enable POWER_SWITCH_USE_HTTPS=true when possible
  • Network Security - Ensure your power switch is on a secure network
  • Access Control - Use the admin account or create restricted users on the device

Troubleshooting

Server won't start

  • Check that environment variables are set correctly
  • Verify you can reach the device at the configured host
  • Ensure the password is correct

"Authentication Error"

  • Double-check your username and password
  • Verify the device firmware supports REST API (1.7.0+)

Tools not appearing in client

  • Restart your MCP client after configuration changes
  • Check the client's logs for MCP server errors
  • Verify the server starts successfully in standalone mode

Related Projects

License

BSD-3-Clause License - See LICENSE file for details

Author

Bryan Kemp (bryan@kempville.com)

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run code quality checks
  5. Submit a pull request

Support

Test change

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选