Skip to main content
Glama
Rigol DL3021 MCP Server

Rigol DL3021 MCP Server

by amahpour
README.md
# Rigol DL3021 MCP Server

A Model Context Protocol (MCP) server for controlling Rigol DL3021 electronic loads via Ethernet. Enables AI agents to perform automated load testing workflows through SCPI commands over VISA TCP/IP.

## Features

- **Ethernet-only** communication via PyVISA TCP/IP
- **Network auto-discovery** when no IP is configured
- **22 MCP tools** covering measurements, input control, mode configuration, and device management

### Available Tools

| Category | Tools |
|----------|-------|
| Connection | `ping`, `discover_devices`, `test_connection`, `connect`, `disconnect` |
| Device | `get_device_info`, `reset_device` |
| Measurements | `measure_voltage`, `measure_current`, `measure_power`, `measure_resistance`, `measure_all` |
| Input Control | `enable_input`, `disable_input`, `get_input_state` |
| Mode | `set_mode`, `query_mode` |
| CC Mode | `set_cc_current`, `set_cc_slew_rate`, `cc_mode` |
| CP Mode | `set_cp_power`, `set_cp_current_limit`, `cp_mode` |

## Installation

First, install the package and its dependencies:

```bash
pip install -e .
```

Or with `uv`:

```bash
uv pip install -e .
```

This installs the following dependencies:

- `pyvisa >= 1.11.0` - VISA instrument communication
- `pyvisa-py` - Pure Python VISA backend
- `fastmcp >= 2.10.6` - MCP server framework

## Configuration

The server uses environment variables for configuration:

| Variable | Description | Default |
|----------|-------------|---------|
| `RIGOL_DL3021_IP` | Device IP address (optional, auto-discovers if not set) | None |
| `RIGOL_DL3021_PORT` | SCPI port | `5555` |

### Claude Code

After installing the package, add the following to your `~/.claude.json` file under the `mcpServers` key:

```json
{
  "mcpServers": {
    "rigol-dl3021": {
      "type": "stdio",
      "command": "uv",
      "args": [
        "run",
        "--with", "fastmcp",
        "--with", "pyvisa",
        "--with", "pyvisa-py",
        "fastmcp", "run",
        "/path/to/rigol_dl3021_mcp_server/mcp_rigol_dl3021.py"
      ],
      "env": {
        "RIGOL_DL3021_PORT": "5555"
      }
    }
  }
}
```

Replace `/path/to/rigol_dl3021_mcp_server/` with the actual path to this repository.

### Cursor

After installing the package, add the following to `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (project-level):

```json
{
  "mcpServers": {
    "rigol-dl3021": {
      "command": "uv",
      "args": [
        "run",
        "--with", "fastmcp",
        "--with", "pyvisa",
        "--with", "pyvisa-py",
        "fastmcp", "run",
        "/path/to/rigol_dl3021_mcp_server/mcp_rigol_dl3021.py"
      ],
      "env": {
        "RIGOL_DL3021_PORT": "5555"
      }
    }
  }
}
```

Replace `/path/to/rigol_dl3021_mcp_server/` with the actual path to this repository.

## Usage

### Running Directly

```bash
python mcp_rigol_dl3021.py
```

### With FastMCP

```bash
fastmcp run mcp_rigol_dl3021.py
```

### As Installed Package

```bash
rigol-dl3021-mcp
```

### Network Discovery

To find your DL3021 on the network:

```bash
python rigol_dl3021/find_dl3021.py
```

To test a specific IP:

```bash
python rigol_dl3021/test_ip.py 192.168.1.100
```

## Project Structure

```
rigol_dl3021_mcp_server/
├── mcp_rigol_dl3021.py          # MCP server (22 tools)
├── pyproject.toml               # Package configuration
└── rigol_dl3021/
    ├── comm_base.py             # Ethernet-only VISA communication
    ├── dl3021.py                # DL3021 SCPI driver
    ├── find_dl3021.py           # Network auto-discovery
    └── test_ip.py               # Single IP connectivity test
```

## License

MIT