Metadata-Version: 2.5
Name: embeddedci-mcp
Version: 3.0.4
Summary: MCP server that lets AI agents drive an EmbeddedCI BenchPod hardware-in-the-loop bench
Project-URL: Homepage, https://www.embeddedci.com/docs/benchpod-mcp
Project-URL: Repository, https://github.com/embeddedci-com/embeddedci-python
Project-URL: Issues, https://github.com/embeddedci-com/embeddedci-python/issues
Author: EmbeddedCI
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent,benchpod,embedded,hardware-in-the-loop,mcp,swd
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: anyio>=4
Requires-Dist: embeddedci[analysis,cloud,discovery,yaml]<4,>=3.0.4
Requires-Dist: mcp<2,>=1.12
Requires-Dist: pydantic>=2.7
Requires-Dist: starlette>=0.27
Requires-Dist: uvicorn>=0.30
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# embeddedci-mcp

<!-- mcp-name: io.github.embeddedci-com/embeddedci-mcp -->

An [MCP](https://modelcontextprotocol.io) server that lets an AI agent drive an
**EmbeddedCI BenchPod** — a hardware-in-the-loop tester wired to a real board. Ask Claude (or any
MCP client) to flash a build, power-cycle the target, watch its UART, pretend to be the sensor it
expects, probe its I2C/CAN traffic or drive and measure analog signals, and the pod does it.

It is a thin layer over the [`embeddedci`](https://pypi.org/project/embeddedci/) SDK: every tool
maps to SDK calls, so anything an agent discovers interactively can become a pytest test.

## Requirements

- Python 3.10+ and [uv](https://docs.astral.sh/uv/) (for `uvx`), or `pip`.
- A BenchPod reachable over the network, the embeddedci.com cloud, or USB. With firmware 3.9.0
  and later, connection `usb` reaches the full API over the pod's USB network adapter (unless
  Wi-Fi is configured on the pod, which turns USB networking off); `status` then reports kind
  `usb_net`. A serial device path, or `usb` on older firmware, is the USB console: status, LA
  voltage and power only, since the STM32 pod's console has no JSON mode. With several pods
  plugged into one computer, `usb` errors and lists them by name; pick one with `usb:<name>`
  (for example `usb:benchpod-baea06`).
- For `flash`: OpenOCD with the `cmsis_dap_tcp` backend (newer than 0.12.0 — e.g.
  `brew install --HEAD open-ocd`, or the xPack build) on the machine running the server. The
  firmware `file` is read from that machine too. Flashing a build uploaded to embeddedci.com
  (`build`/`repo`/`ref`) over a cloud connection needs neither: embeddedci.com runs OpenOCD.

## Set up your client

### Claude Code

```bash
claude mcp add benchpod \
  -e BENCHPOD_CONNECTION=192.168.1.213 -e BENCHPOD_LA_VOLTAGE=3.3 \
  -- uvx embeddedci-mcp
```

`BENCHPOD_LA_VOLTAGE` overrides the board's I/O voltage (`1.8` for a 1V8 board). Usually it is
not needed: the pod's wiring profile carries it (`la_mv`), and `connect` sets it from there. Only
when neither sets one is the agent told to ask for it and set it in the profile or with
`set_la_voltage`.

Both variables are optional. `connect` picks the pod, first match wins:

1. its `connection` argument;
2. the server default, `--connection`;
3. `BENCHPOD_CONNECTION`;
4. the default connection `benchpod-cli` saved with `benchpod set-connection <address|device|usb>`
   (read-only, from `~/.config/benchpod-cli/config.json`, or under `$XDG_CONFIG_HOME`);
5. mDNS discovery of the one pod on the LAN.

So the CLI, the SDK and the MCP server share one saved connection. With none of the first four,
`connect` looks for a BenchPod on the LAN over mDNS (like `discover`) and uses it when it finds
exactly one. When it finds none or several, the error
lists the pods it heard (name and address) and what to pass instead: `host[:port]`, `usb`, or
`embeddedci:<device>` for a cloud pod (`cloud_list_devices` lists those). So
`claude mcp add benchpod -- uvx embeddedci-mcp` is enough for a single pod on your network: just
ask the agent to connect.

**TLS.** A network address uses TLS on port 8443 when the pod has it (firmware 3.9.3+) and pins
the pod's certificate on first use, in the same `known_pods.json` as `benchpod-cli`; older pods
stay on plaintext 8080. `BENCHPOD_TLS=on|off` and `BENCHPOD_TLS_CA` work as in the SDK. A changed
certificate stops `connect` with both fingerprints: after a deliberate change, the user runs
`benchpod lan-tls trust`. The `lan_tls` tool shows the certificate and switches HTTPS-only.

### Claude Desktop / Cursor

`claude_desktop_config.json` (Claude Desktop) or `.cursor/mcp.json` (Cursor):

```json
{
  "mcpServers": {
    "benchpod": {
      "command": "uvx",
      "args": ["embeddedci-mcp"],
      "env": {
        "BENCHPOD_CONNECTION": "192.168.1.213",
        "BENCHPOD_LA_VOLTAGE": "3.3"
      }
    }
  }
}
```

### Codex

The Codex CLI keeps its MCP servers in `~/.codex/config.toml`. Add it with the CLI:

```bash
codex mcp add benchpod \
  --env BENCHPOD_CONNECTION=192.168.1.213 --env BENCHPOD_LA_VOLTAGE=3.3 \
  -- uvx embeddedci-mcp
```

…or write the entry yourself (`codex mcp list` shows what is configured):

```toml
# ~/.codex/config.toml
[mcp_servers.benchpod]
command = "uvx"
args = ["embeddedci-mcp"]
env = { BENCHPOD_CONNECTION = "192.168.1.213", BENCHPOD_LA_VOLTAGE = "3.3" }
```

### A pod in the cloud

Use the device name and an [API key](https://www.embeddedci.com/docs/benchpod-mcp) — the cloud
transport is included:

```json
"env": {
  "BENCHPOD_CONNECTION": "embeddedci:my-bench",
  "BENCHPOD_API_KEY": "eci_…",
  "BENCHPOD_LA_VOLTAGE": "3.3"
}
```

Or skip the API key: after `benchpod login`, the server reuses that session
(`~/.config/benchpod-cli/token.json`, refreshed and written back when it has expired) for
`cloud_list_devices`, `connect("embeddedci:<name>")` and, on a LAN or USB connection, the pod's
stored wiring profile. `BENCHPOD_API_KEY` wins when set, and
inside GitHub Actions the SDK uses OIDC instead.

`cloud_list_devices` lists the pods on your account and which are online, without connecting to
one; pass a result's `connection` to `connect`. `cloud_runs_list`, `cloud_run_get`,
`cloud_run_compare` and `cloud_run_trace` read the test runs uploaded to embeddedci.com, so an agent
can see why a run failed (the failed cases, the measurements outside their limits, the pod calls of
a failed test) and what changed since an earlier run, without the bench. The session token behind a cloud connection is
renewed before it expires, so a long session keeps working.

A pod is shared, so `connect` takes an exclusive lease, waiting up to `--lease-wait` seconds if
someone else holds it: the server's lease for a cloud pod, and the pod's own lease on the LAN and
the USB network when the pod's firmware has the `lease` feature. The lease is released by
`disconnect`, or after `--idle-timeout` seconds without a tool call. The next call reconnects
transparently, so an idle chat never blocks CI on that pod. `status` shows the pod's lease
(`local_lease`) and warns when someone else holds it.

## Options

| Flag | Environment | Default | |
| --- | --- | --- | --- |
| `--connection` | `BENCHPOD_CONNECTION` | the CLI's saved connection, else mDNS | host[:port], serial device, `usb`, `usb:<name>`, `discover`, `saved`, or `embeddedci:<device>`; unset = `benchpod set-connection`'s saved one, else find the one pod on the LAN |
| `--la-voltage` | `BENCHPOD_LA_VOLTAGE` | — | LA I/O voltage (1.8 or 3.3) applied on connect |
| `--wiring-autosave` | `BENCHPOD_WIRING_AUTOSAVE` | off | `set_wiring` also stores the profile on the pod (not a change of the I/O voltage, power rail or SWD target: those need `save_wiring`) |
| — | `BENCHPOD_API_KEY` | — | cloud pods and the waveform library (without it, cloud tools use the `benchpod login` session) |
| — | `BENCHPOD_API_BASE` | `https://www.embeddedci.com` | another embeddedci server |
| — | `BENCHPOD_WIRING` | — | wiring profile file (`.json`/`.toml`) that wins over the stored profile |
| — | `BENCHPOD_WIRING_SOURCE` | `auto` | `local` never asks embeddedci.com for the pod's stored wiring profile |
| `--lease-wait` | — | `30` | seconds to wait for a busy pod (its lease, or the cloud device's) |
| `--idle-timeout` | — | `600` | release the lease after this many idle seconds (0 = never) |
| `--timeout` | — | `30` | per-command device timeout |
| `--transport` | — | `stdio` | `stdio` or `http` |
| `--host` / `--port` | — | `127.0.0.1` / `8000` | HTTP bind address |
| `--auth-token` | `EMBEDDEDCI_MCP_TOKEN` | — | require `Authorization: Bearer <token>` (mandatory off loopback); prefer the variable or `--auth-token-file`, since a command-line token shows in `ps` |
| `--auth-token-file` | — | — | read the bearer token from this file's first line |
| `--allowed-host` | — | — | Host header(s) to accept on a network bind (DNS-rebinding protection) |
| `--allow-unauthenticated` | — | off | serve a network address without a token (isolated networks only) |

### Serving a bench over HTTP

Run the server on the machine next to the pod, and point clients at it:

```bash
export EMBEDDEDCI_MCP_TOKEN=$(openssl rand -hex 32)
embeddedci-mcp --transport http --host 0.0.0.0 --connection 192.168.1.213 --la-voltage 3.3
```

```bash
claude mcp add --transport http benchpod http://bench-host:8000/mcp \
  --header "Authorization: Bearer $EMBEDDEDCI_MCP_TOKEN"
```

The server drives real hardware, so it refuses a non-loopback bind without a token. It holds one
pod connection shared by all HTTP clients, and serialises their tool calls.

## Tools

Every tool, grouped as in the server. Parameters in **bold** are required; the others are optional
and show their default when they have one (no default means "from the wiring profile", "keep the
current setting" or "not used"). Units are volts, amps, seconds and hertz. LA channel arguments take
a number (1-14) or a name from the wiring profile. Each tool's input schema carries the full
description, ranges and enums, so an agent sees more than this table.

### Connection

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `connect` | Open a connection (closing any previous one) and report status, capabilities and where the wiring profile came from. Without a `connection` or a configured default (`--connection`, `BENCHPOD_CONNECTION`, the CLI's saved connection), finds the one pod on the LAN over mDNS. `wiring_profile` names a profile stored on the pod (default: the pod's default profile). | `connection`, `la_voltage`, `lease_wait=30`, `wiring_profile` |
| `disconnect` | Close UART/CAN sessions and the connection, releasing a cloud lease. | none |
| `status` | Firmware, capabilities, LA voltage, open sessions and warnings (works when not connected); `eth_mac` and `wifi_mac`, the MACs a network admin registers before the pod gets an address (from the pod with firmware after 3.10.7, else from embeddedci.com's record; `wifi_mac` null until the pod scanned for Wi-Fi or joined). | none |
| `set_la_voltage` | Select the LA I/O voltage to match the DUT (1.8 V needs a rev3 pod). Usually not needed: `connect` sets it from the wiring profile's `la_mv`. | **`voltage`** |

### Cloud (embeddedci.com)

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `cloud_list_devices` | The pods on your embeddedci.com organization and whether each is online, without connecting. | none |
| `cloud_runs_list` | Test runs uploaded to embeddedci.com (`benchpod ci`, `pytest --embeddedci-upload`, `build_report`), newest first, with outcome and counts; `before` is the previous page's `next_before`. | `suite`, `dut`, `build`, `pod`, `ref`, `limit=20`, `before` |
| `cloud_run_get` | One test run: outcome, counts, health, pod and tests, the failed cases with the first line of their message, the measurements outside their limits and the uploaded files; `full=true` adds the whole `run.json`. | **`run_id`**, `full=false` |
| `cloud_run_compare` | What changed between an earlier run and this one: newly failing and fixed cases, measurements, slower tests and pod calls, and the inputs that differ (pod firmware, wiring, DUT firmware). `compare_with`: `previous`, a run id, or `baseline:<branch>`. | **`run_id`**, `compare_with="previous"` |
| `cloud_run_trace` | The pod calls of one test case from its uploaded trace (only failed and error cases have one): what was sent, how long it took, the answer or error; long requests and replies are shortened. `case_id` may be a unique end of the id. | **`run_id`**, **`case_id`**, `errors_only=false`, `limit=200` |

### Wiring profile

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `wiring` | Which DUT signal is on which LA channel, plus the I/O voltage, power rail, UART baud and SWD target; the profiles stored on the pod and `unsaved_changes` (what this connection changed that is not stored); `board_header` and `header_map`, the profile on the pod's real I/O header as text (each pin in its place, then what to connect to it). What a profile does not set is undefined. | none |
| `set_wiring` | Replace the wiring profile for this connection only (version 2: what it leaves out is undefined); `save=true`, or the server's `--wiring-autosave`, also stores it on the pod. Autosave never stores a change of the I/O voltage, rail or SWD target. Also sends the profile's pin directions to the pod (`la_dir`, firmware 3.10.4+). | **`profile`**, `save=false` |
| `save_wiring` | Store this connection's profile (or `profile`) on the pod, under `name` or the profile it was loaded from. Saving the loaded profile refuses with `BP0009` when someone else saved it meanwhile. Never changes the pod's default. | `name`, `profile` |
| `load_wiring` | Switch this connection to a profile stored on the pod (omit `name`: the pod's default). Nothing on the pod changes. | `name` |
| `set_default_wiring` | Make a stored profile the pod's default: what every connection uses when it names none. | **`name`** |
| `delete_wiring` | Delete a stored profile (not the default: `BP0013`). | **`name`** |

### Power

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `power_on` | Power the board on with its wiring profile applied first: the profile's I/O voltage (when the pod has none or another one), its pull resistors (`pulls`, at 3.3 V), then the rail; the pod records the profile. Never changes the I/O voltage under a powered board. `wiring_profile` powers on with a stored profile. | `efuse`, `delay`, `wiring_profile` |
| `power_off` | Switch the target's power rail off. | `efuse`, `delay` |
| `power_status` | Both target-power rails, internal 5 V (efuse 1) and external (efuse 2): on/off, tripped, bus voltage and current, and the pod's own draw. | none |
| `reset_target` | Drive the DUT's reset line from the pod's reset pin. | `action=pulse`, `pulse=0.1` |

### Power profiles

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `measure_power` | Sample supply current and voltage for a window: average, min, peak, energy and charge. | **`duration`**, `efuse`, `rate_hz=500`, `points=0` |
| `power_profile_start` | Start sampling the rail in the background while other tools run. | `efuse`, `rate_hz=500`, `max_duration=60` |
| `power_profile_stop` | Stop the running profile and return its statistics (and a trace). | `points=0` |

### Flash

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `flash` | Program the DUT over SWD through the pod's CMSIS-DAP probe: a local `file` (OpenOCD runs next to the server), or a build uploaded to embeddedci.com (`build` id or `latest`, `repo`, `ref`; embeddedci.com runs OpenOCD on a cloud connection, LAN/USB downloads it). With `target` `esp32` (or `esp32s3`, `esp32c3`, ...) the pod flashes an ESP32-family target over its UART ROM bootloader instead: `file` is a `.bin` or an ESP-IDF `flasher_args.json`, TXD0/RXD0 on `rx`/`tx` (default: the profile's `uart_rx`/`uart_tx`), IO0 on `boot`, EN on the pod's reset pin (`nreset`), a `.bin` at `load_address`. | `swclk`, `swdio`, `target`, `file`, `nreset`, `load_address`, `target_power`, `verify=true`, `reset=true`, `connect_under_reset`, `extra_configs`, `extra_args`, `timeout=300`, `connect_attempts=5`, `build`, `repo`, `ref`, `artifact`, `server_side`, `rx`, `tx`, `boot` |

### SPI flash and SPI devices

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `spi_flash_info` | Read the JEDEC ID and size of the SPI NOR flash on the SPI pins. | `sck`, `mosi`, `miso`, `cs`, `hz=1000000`, `mode=0` |
| `spi_flash_program` | Erase, write and verify an image in the SPI NOR flash. | **`file`**, `addr=0`, `erase=true`, `verify=true`, `hold_reset=false`, `sck`, `mosi`, `miso`, `cs`, `hz=6000000`, `mode=0` |
| `spi_flash_read` | Read flash bytes to a file, or up to 4096 bytes as hex. | **`addr`**, **`length`**, `file`, `sck`, `mosi`, `miso`, `cs`, `hz=6000000`, `mode=0` |
| `spi_transfer` | One full-duplex SPI transaction with any device on the SPI pins. | **`tx_hex`**, `sck`, `mosi`, `miso`, `cs`, `hz=1000000`, `mode=0` |

`mode` is 0 to 3; modes 1 and 2 need gateware v55+.

### I2C master

The pod as an I2C master on two LA pins (gateware v55+), to read and write registers of a chip on
the DUT's board. The bus needs pull-ups: the pod's on LA1-LA6 (`set_pull(pull="up")` first, LA voltage 3.3), or
the board's with `pullups="external"`.

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `i2c_open` | Make the pod an I2C master on two LA pins; `hz` in the result is the SCL rate the pod runs (a real bus is somewhat slower: the rise time adds to each period). | `sda`, `scl`, `hz=100000`, `pullups=pod` |
| `i2c_transfer` | Write, read, or write then read (repeated START); neither is a probe. A NACK returns `ack: false` and `nack_at`. | **`addr`**, `write_hex`, `read=0` |
| `i2c_scan` | Which addresses answer. | `start=8`, `end=119` |
| `i2c_close` | Release the I2C master's pins. | none |

### UART

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `capture_uart` | Record the DUT's UART for a window, or until a regex matches. | **`duration`**, `rx`, `tx`, `baud`, `until_regex`, `parity`, `stop_bits`, `half_duplex`, `entry`, `de`, `de_active_low` |
| `power_cycle_and_capture` | Power-cycle the target and capture UART across the boot. | `rx`, `tx`, `efuse`, `delay=1`, `duration=4`, `baud`, `until_regex`, `off_settle=0.3`, `parity`, `stop_bits` |
| `uart_open` | Start buffering the DUT's UART in the background. The frame is the profile's (`uart_parity`, `uart_stop_bits`; 8N1 unless set) unless `parity` (`none`/`even`/`odd`) or `stop_bits` (1/2) say otherwise; anything but 8N1 needs firmware 3.10.8+. `half_duplex` runs it on one wire (`rx`; `tx` defaults to it) and `entry` (`reset_ms`, `tx_low`, `hold_ms`, `idle_ms`, `data_hex`) runs a pod-timed boot-mode entry first: reset with TX held low, release, the first bytes (gateware v57, for boot-ROM pins such as RL78 TOOL0). | `rx`, `tx`, `baud`, `parity`, `stop_bits`, `half_duplex`, `entry`, `de`, `de_active_low` |
| `uart_write` | Send text to the DUT through the open UART session. | **`text`**, `line_ending=lf` |
| `uart_read` | Return output received since the last read, optionally waiting for a match. | `until_regex`, `timeout=2` |
| `uart_close` | Stop the background UART session. | none |

### Emulated sensors

The pod plays I2C, SPI, UART and analog sensors from a **definition** (YAML or JSON, the format of
the public [sensor library](https://github.com/embeddedci-com/benchpod-sensors)): a library entry
such as `bme280`, `sht4x`, `mpu6050` or `gps_nmea`, or one the agent writes from a datasheet. Up to
4 I2C sensors, 1 SPI and 1 UART sensor run at once, each a named instance. Needs pod firmware with
the `sensors` capability; older firmware fails with "this pod's firmware is too old for sensor
emulation; update the firmware". The library tools need no pod. The server uses the library
version the SDK pins (0.1.0, bundled) unless `BENCHPOD_SENSOR_LIBRARY`, the CLI's
`sensor_library` setting or a `version` argument says otherwise.

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `sensor_library` | The library's sensors and stimuli (name, kind, label) and the version in use; `version` switches it for the other sensor tools. | `version` (`latest`, `0.2.0`, `default`) |
| `sensor_show` | One library entry: its YAML (a starting point for your own part) and the params `sensor_set` takes. | **`name`**, `version` |
| `sensor_format` | The definition and stimulus format reference (Markdown), to write a definition from a datasheet. | `version` |
| `sensor_validate` | Check a definition: the header here, then a dry-run compile on the pod (header only when no pod is connected). | **`definition`** (a library name, YAML/JSON text, a JSON object or a path) |
| `sensor_start` | Upload a definition and start it on `pins` (set the LA voltage and, for I2C, the pull-ups first); returns the params and whether the emulation FPGA image was loaded. | **`definition`**, `instance` (1 to 16 characters; default: its name), `pins` (`sda`/`scl`/`drdy`, `sclk`/`mosi`/`miso`/`cs` (no data-ready pin on SPI), `tx`/`rx`, `output`; channels or wiring names, I2C and SPI default to the profile), `address`, `baud`, `values` |
| `sensor_set` | Change what a running sensor reports; out-of-range values are refused with the range. | **`instance`**, **`values`** |
| `sensor_stimulus_load` | Upload values over time (and timed faults) for the running sensors. | **`stimulus`** (YAML/JSON text, a JSON object or a path) |
| `sensor_stimulus_start` | Play the loaded stimulus. | `at_s` |
| `sensor_stimulus_stop` | Stop it; values stay where it left them. | none |
| `sensor_fault` | Make a sensor misbehave now: `stuck`, `offset`, `gain`, `no_response`, `corrupt`, `bus_stuck`, `garbage`, `drop`, `baud_error`, `open`, `short`. | **`instance`**, **`type`**, `duration_s` (default: until cleared), `param`, `value`, `at`, `mask`, `rate_hz` |
| `sensor_fault_clear` | End a sensor's faults. | **`instance`** |
| `sensor_stop` | Stop one sensor, or all; the pod releases the pins and forgets the definition; returns the names it stopped. The emulation image stays loaded. | `instance` (default: all) |
| `sensor_status` | Running sensors (slot, pins, values, faults with `left_s`, bus counters such as `writes`; `transfers` is always null), the stimulus and the FPGA image, every page in one reply. | none |
| `sensor_regs` | The bytes an I2C/SPI sensor answers now. | **`instance`**, `start=0` (0..255), `length` (default: to the end of the 256-byte image) |
| `sensor_capture` | Wait for the DUT's next transaction on an I2C sensor's bus (up to 2 s; firmware with `sensor_la_trigger`, older firmware captures at once), capture it and decode it into a transaction trace (I2C only; `capture_la` for SPI and UART sensors). | **`instance`**, `samples=4096` (1..4096 packed bytes), `address`, `register` |

### Pull resistors

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `set_pull` | Pull LA channels `up` or `down`, or switch their resistor `off`; the pod picks the value. Today LA1-LA6 pull up, LA7/LA8 down, LA9-LA14 have none; another direction is refused (BP0024, BP0023). `enabled` is the older on/off form. | **`las`**, `pull`, `enabled` |
| `pull_status` | Every LA channel's pull resistor: state (`up`, `down` or `off`), the directions it supports and its value. | none |
| `lan_tls` | The pod's LAN API over TLS (firmware 3.9.3+): port 8443, the HTTPS-only setting and the certificate's sha256 (what clients pin). Turning HTTPS-only off and regenerating need a TLS, USB or cloud connection. | `https_only`, `regenerate` |
| `usb_network` | Read the pod's USB network setting (firmware 3.9.0+), or turn the adapter off over the USB link. Only the device changes it; turning it back on is `benchpod usb-network on` on the USB console. | `set=off` |
| `log_level` | Read or set how much the pod prints on its USB console (firmware newer than 3.10.12): `error`, `warn`, `info` (the default) or `debug`, which adds every command trace and the reconnect retry detail. Stored on the pod. | `level` |

### GPIO on the LA pins

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `la_pins` | What owns each of the 14 LA channels, with GPIO mode, level and bias resistor. | none |
| `gpio_mode` | Claim LA channels as GPIO (input, output or open drain). | **`la`**, `mode=output`, `level` |
| `gpio_write` | Set the level of GPIO output and open-drain channels (and EXT pins); `level` is one level or a list, one per channel. | **`la`**, **`level`** |
| `gpio_read` | The live level of LA channels and EXT pins (all of them when `la` is omitted). | `la` |
| `gpio_wait` | Wait until an LA channel reads a level (`reached: false` on timeout). | **`la`**, `level=1`, `timeout=5` |
| `gpio_pulse` | FPGA-timed pulses on an LA channel: `width` 4 us to 65.535 ms, `count` up to 65535. | **`la`**, **`width`**, `count=1` |
| `gpio_release` | Return channels to high-Z, watched by captures (EXT pins to input). | `la` |
| `expansion` | Attach an I2C/SPI GPIO expander board (chips: `tca9555`, `pca9555`, `mcp23017`, `pcf8574`, `pcf8574a`, `pcf8575`, `tca6416a`, `tca6424a`, `mcp23s17`, `74hc595`, `74hc165`), report it, or detach it. Its pins become `EXT1`..`EXTn`, which `gpio_mode`, `gpio_write`, `gpio_read`, `gpio_wait` and `gpio_release` take next to LA channels; `gpio_pulse`, triggers and `la_dir` refuse them. | `chip` (omit for the status), `detach=false`, `addr`, `sda`, `scl`, `spi` (`[sck, mosi, miso, cs]`), `load` (74hc165), `count` (chains), `hz`, `pullups`, `names` |
| `la_dir` | Which way each pin's DUT signal goes (`dut_input`, `dut_output`, `bidir`, `unknown`); on a DUT output the pod refuses push-pull drivers. `connect` and `set_wiring` already send the wiring profile's; `from_wiring` sends them again; no arguments lists every pin. | `la`, `dir`, `from_wiring=false` |

### Analog

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `analog_path` | Set every analog mux and relay for a named path in one step; `range` sets the ADC input range too. | **`path`**, `range` |
| `dac_output` | Route a DAC output and drive a calibrated DC voltage on it. | **`path`**, `volts` |
| `current_out` | Hold a current on the 4-20 mA output (J9), in amps, or read its range. | `current` |
| `adc_read` | One calibrated reading: front SMA, DAC loopbacks or the 4-20 mA input (J8); reports the ADC range, its full scale and overrange. | `source=ext`, `range` |
| `adc_range` | Read or switch the ADC input range: normal ±32.8 V or low ±5.46 V at 6x the resolution (analog module v3r4+, firmware 3.9.5+; 1x leads, the low range's input is 1.82 MΩ), or self-test it through the cal1 loopback. | `range`, `test=false` |
| `calibration` | The stored calibration: the ADC offset (measured on the 4-20 mA input) and the fit it uses, plus the DMM lines and gains (firmware 3.9.4+). | none |
| `calibrate` | Measure and store the ADC offset on the 4-20 mA input (J8 open), or clear the calibration (all of it, or one part). | `source=current_in`, `clear=false`, `clear_part` |
| `calibrate_dac` | Store this pod's line for a DAC output from two DMM readings of set points driven with `dac_output` (firmware 3.9.4+). | **`path`**, **`code1`**, **`volts1`**, **`code2`**, **`volts2`** |
| `calibrate_adc_gain` | Measure an ADC source's gain through a loopback against a DMM-calibrated output (firmware 3.9.4+); `range=low` the ADC low range's gain through cal1 (firmware 3.9.5+). | **`source`**, `range=normal` |

### Capture and decode

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `capture_adc` | Capture the ADC: calibrated statistics, dominant frequency and a min/max envelope; `clipped_samples` counts samples past the range's full scale. `oversample` converts at 400 kS/s and averages down to `sample_rate_hz` for lower noise, about 5 s at most. | `samples=4096`, `sample_rate_hz`, `source`, `points=200`, `trigger_la`, `trigger_edge=rising`, `trigger_timeout=10`, `range`, `oversample` |
| `capture_la` | Capture all 14 LA channels: levels, edge count, first edge and frequency per channel. Up to 48 MS/s on gateware v50+. `send` (gateware v55+) runs one transaction right after the capture arms: `{"bus":"i2c","addr":118,"write_hex":"d0","read":1}` (the `i2c_open` session, else one from the wiring), `{"bus":"spi","tx_hex":"9f00"}` (SPI pins from the wiring) or `{"bus":"gpio","la":6,"level":0}` (a GPIO output); without `trigger_la` it triggers on SDA or CS falling or the pin's edge, and the result's `send` has the reply. | `samples=4096`, `sample_rate_hz`, `stop_dac_after`, `trigger_la`, `trigger_edge=rising`, `trigger_timeout=10`, `trigger_pre_samples=0`, `send` |
| `capture_correlated` | ADC and LA from one hardware trigger, on one timebase. | `adc_samples=4096`, `adc_sample_rate_hz`, `la_samples=4096`, `la_sample_rate_hz`, `stop_dac_after`, `points=200`, `trigger_la`, `trigger_edge=rising`, `trigger_timeout=10`, `source` |
| `decode_la` | Decode I2C, UART or SPI from the last LA capture (or a new one). | **`protocol`**, `sda`, `scl`, `rx`, `baud`, `sclk`, `mosi`, `miso`, `cs`, `mode=0`, `capture=last`, `samples=16384`, `sample_rate_hz=1000000`, `max_items=200` |
| `la_timing` | Edge timestamps, pulse widths, frequency, duty cycle and channel-to-channel delay from the last capture. | **`la`**, `edge=rising`, `to_la`, `to_edge=rising`, `after=0`, `max_edges=100` |

### DAC

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `generate` | Drive a sine, square or sawtooth on a DAC output (volts, or amps on `current_out`). | **`waveform`**, **`freq_hz`**, **`amplitude`**, `offset`, `dac_path=3v3`, `duration`, `sample_rate_hz`, `on_capture=false`, `route=true` |
| `dac_stop` | Stop any DAC output: generator, replay or control loop. | none |
| `replay` | Loop your own samples, or the last ADC capture, out of the DAC. | `volts`, `from_last_capture=false`, `dac_path=3v3`, `mapping=faithful`, `sample_rate_hz`, `fault`, `on_capture=false`, `route=true`, `switch_image=true` |
| `list_waveforms` | The organization's cloud waveform library. | none |
| `replay_waveform` | Loop a cloud-library waveform out of the DAC. | **`waveform_id`**, `dac_path`, `mapping=faithful`, `sample_rate_hz`, `window_start=0`, `window_len=0`, `target_samples=0`, `fault`, `on_capture=false`, `switch_image=true` |
| `save_capture_as_recording` | Save the last ADC capture to the cloud waveform library. | **`name`**, `full_scale_v` |

### Control loop

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `control_loop` | Run a tabulated transfer function in the FPGA (for example a solar panel I-V curve). | `curve`, `voc_code`, `sharpness=4`, `points=256`, `k=8192`, `vmin=0`, `vmax=65535`, `tick_div=64`, `source`, `input_code=0`, `step=0`, `input_map`, `switch_image=true` |
| `loop_input` | Re-target the running loop's input without re-arming. | `input_code`, `source`, `step` |
| `loop_probe` | The running loop's live operating point. | none |
| `fpga_image` | Switch the FPGA to the `loop`, `deep_replay` or `emulation` gateware image (~2-3 s); refused while I2C, SPI or UART sensors run on the emulation image. | **`image`** |

### CAN

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `can_open` | Bring up the pod's CAN interface (normal, loopback or listen-only): classic CAN, or CAN FD with `data_bitrate` (firmware 3.10.2+, up to 8 Mbit/s, 64-byte frames). | `bitrate=500000`, `mode=normal`, `term=false`, `data_bitrate` |
| `can_write` | Queue one CAN frame: up to 8 bytes, or 64 on a CAN FD bus (FD with bit-rate switching unless `fd=false` / `brs=false`). | **`can_id`**, `data`, `ext=false`, `rtr=false`, `fd`, `brs` |
| `can_read` | Read received frames, or wait for one id. | `timeout=0`, `can_id`, `max_frames=32` |
| `can_respond` | Answer a CAN id from the pod firmware (ECU simulation), or clear all rules. | `match_id`, `reply_id`, `reply_data`, `match_ext=false`, `reply_ext=false`, `reply_fd`, `reply_brs`, `clear=false` |
| `can_status` | Link state: mode, bitrate, error counters, bus-off. | none |
| `can_close` | Clear responder rules, stop CAN and switch the 120 Ω termination off. | none |

### Other

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `la_step` | Step pulses for step/dir motor drivers: `delay` is half the step period (4 us to 65.535 ms), `steps` up to 65535. | **`la`**, **`steps`**, **`delay`**, `dir_la`, `direction=0` |
| `command` | Raw firmware JSON command, for anything no tool covers. | **`request`** |

### AI Vision board

For a bench with an AI Vision board (ai-vision-2): a camera on the DUT's screen that reads text,
finds buttons and presses them through its actuator. Its connection is separate from the pod's, so
one session drives both. Without `vision_connect`, the first `vision_*` call connects to
`AIVISION_CONNECTION` (token in `AIVISION_TOKEN`). Boxes and taps are in screen pixels once the
screen is calibrated.

A board paired with embeddedci.com is reached from anywhere as `embeddedci:<name>`:
`vision_cloud_boards` lists the organization's boards, and `vision_connect` takes the `connection`
it returns. Over embeddedci.com the server's sign-in applies (`BENCHPOD_API_KEY`, an API key with
the "Control AI Vision" scope, else the `benchpod login` session) and `lease_as` takes the
server's device lease, the one the web app and other runs see.

| Tool | Purpose | Parameters |
| --- | --- | --- |
| `vision_cloud_boards` | The AI Vision boards on embeddedci.com, online or not, with the `connection` to pass to `vision_connect`. | none |
| `vision_connect` | Open the AI Vision connection (a LAN address, `discover` or `embeddedci:<name>`; closing a previous one) and report its status. | `connection`, `token`, `lease_as` |
| `vision_disconnect` | Close the connection and release its lease. | none |
| `vision_status` | Version, calibration, camera lock, actuators, lease, capabilities, with warnings. | none |
| `vision_look` | The screen as an image (an image content block), or what the camera sees; a `region` zooms in at full sensor resolution. | `space=screen`, `overlay`, `region` |
| `vision_ocr` | All text on the screen or in a region, in reading order, with boxes. | `region`, `zoom` |
| `vision_find` | Elements matching text, a kind (`button`, `icon`, `text`) or a template, best first. | `text`, `label`, `template`, `match`, `region` |
| `vision_wait_for` | Wait until text appears (or with `gone`, disappears); `met: false` on timeout. | **`text`**, `timeout_s=10`, `gone=false`, `match`, `region` |
| `vision_compare` | Similarity of the screen to a stored reference screen. | **`reference`**, `mask` |
| `vision_screen_health` | Black, dim, frozen, flickering or stuck pixels over a window. | `window_ms=1000`, `expect_motion=false` |
| `vision_calibrate` | Map camera pixels to screen pixels: four corners and the screen size, or `method` auto/markers. | `corners`, `screen_size`, `method` |
| `vision_add_reference` | Store the current screen (or a region, as a template) as a reference. | **`name`**, `kind=screen`, `region`, `overwrite=false` |
| `vision_press` | Find an element, tap its center, optionally wait for `verify_text`. Fails with the visible text when it is not there. | **`text`**, `verify_text`, `verify_timeout_s=5`, `match`, `actuator` |
| `vision_tap` | Tap a point in screen pixels (`hold_ms` for a long press). | **`x`**, **`y`**, `hold_ms=0`, `actuator` |

Resources: `benchpod://wiring` (the connected bench's own wiring profile, then LA channels, bias
resistors and analog paths) and `benchpod://help` (the server instructions). For drawing captures
in an app (the BenchPod desktop app's capture view), three more give the last capture in full:

| Resource | JSON |
|---|---|
| `benchpod://capture/la` | The last `capture_la` / `capture_correlated` as run-length `edges`, `[sample index, 14-bit word]` from sample 0, plus `sample_rate_hz`, `count`, `pre_samples`, `seq`, `correlated`. |
| `benchpod://capture/adc` | The last `capture_adc` / `capture_correlated`: `samples` in volts (or mA for `current_in`), `unit`, `sample_rate_hz`, `source`, `seq`, `correlated`. |
| `benchpod://capture/decode` | The last `decode_la`: `protocol`, `channels`, and I2C `transactions` with timed segments, or UART / SPI `frames` with `start_us` / `end_us`; `seq` is the capture it decoded. |

Each is `{"seq": 0}` before the first capture. `seq` numbers the captures, and `correlated` says
the LA and ADC captures share one timebase. They can be megabytes: an agent should read the
capture tools' summaries, `la_timing` and `decode_la` instead.

## How it behaves

- **Instructions.** The server sends usage instructions at initialisation — session start, typical
  flows, units, error contract — so the agent knows to `connect` first, and that the I/O voltage comes
  from the wiring profile.
- **Typed, structured results.** Every tool has an input schema with enums and ranges (paths,
  sources, LA channels 1-14, internal 5 V (efuse 1) or external (efuse 2), …) and an output
  schema; results come back as structured content. Units are volts, seconds and hertz.
- **Errors.** A tool that cannot do what was asked fails with an MCP tool error whose message names
  the cause, e.g. `FirmwareError: la voltage not set` or `NotConnectedError: …`. A completed
  operation with a negative outcome is a normal result: `flash` returns `ok: false` with its logs,
  a UART capture `matched: false`.
- **Refusals.** When the pod or the server refuses a command, the error names the kind and ends
  with a one-line hint on what to do: `PodLockedError` (the pod's LAN policy keeps the command for
  the cloud or USB), `PodLeasedError` (a cloud job holds the pod; the message names who and for
  how long), `PodBusyError` (a capture or upload is running), `PermissionDeniedError` (the
  credential lacks the right, for example an API key without the `benchpod:admin` scope) and
  `TransportTimeout` (the pod did not answer). A dropped link is a `ConnectionClosedError`.
  `UnsupportedFeatureError` means the pod cannot do it at all: its firmware or gateware lacks the
  feature, or it is the digital-only board without the analog front end; the hint says which.
  `status` also warns when a cloud job holds the pod or the LAN policy is locked.
  Refusals whose fix the firmware spells as a raw protocol command name the tool instead:
  `FirmwareError: uart_proxy_start: la voltage not set; the wiring profile sets no I/O voltage: ask
  the user for the board's (1.8 or 3.3), set it in the profile (set_wiring with la_mv 1800 or 3300,
  then save_wiring) or call set_la_voltage` and `PinConflictError: uart_proxy_start: pin conflict: LA4 is in use
  by gpio; release it with gpio_release(la=[4])`. The other pin owners point to `uart_close` and
  `sensor_stop`; a pull conflict to `set_pull(las=[7], pull="off")`.
- **Capabilities.** `connect` and `status` report what the pod can do as flags, so an agent can
  check before it calls a tool: for example `la_pins`, `capture_trigger`, `power_profile`,
  `nrst_pin`, `can`, `calibrate`, `cal_dmm`, `current_out`, `pod_current`, `sensors` and `analog` (false on the
  digital-only board), plus the pod's policy and cloud settings (`dac_limits`, `flash_kb`,
  `ota_sig`, `sig_policy`, `lan_policy`, `tunnel_max_tier`, `lease_state`, `cloud_ca`,
  `cloud_proxy`).
- **Wiring profile.** `wiring` is the bench's map of DUT signal → LA channel, plus the target-power
  rail, the UART baud and the SWD target. Omitted channel / baud / rail / SWD arguments come from
  it, and channel arguments also accept its names (`trigger_la: "READY"`, `rx: "uart_rx"`), so an
  agent that read `wiring` once can call `flash()`, `uart_open()` or `power_on()` with no
  pin numbers at all. `set_wiring` replaces it for the connection, or stores it on embeddedci.com
  with `save: true`.

  It is the same profile the web UI's Wiring tab edits. The SDK resolves it, first match wins:
  `BENCHPOD_WIRING` (a file); the profile stored on embeddedci.com for this pod (a cloud pod by
  name; a LAN or USB pod by the device it reports it is registered as, when `BENCHPOD_API_KEY` or
  the `benchpod login` session is available and that device is on the same account); the
  defaults. `wiring` and `connect`/`status` (`wiring_source`) report where it came from: `server`,
  `file`, `dict` (from `set_wiring`) or `defaults`. When the lookup fails (not signed in, pod not
  registered, server unreachable, another account) the defaults apply and nothing fails; over the
  LAN or USB it gives up after about 3 seconds. The STM32 pod's USB text console cannot report its
  registration, so over USB the defaults apply. `BENCHPOD_WIRING_SOURCE=local` skips the lookup.
- **Pin directions on by default.** Every wired role and signal has a DUT direction, shown per
  channel in `wiring` (`dut_dir`): `uart_rx` and `spi_miso` are DUT outputs; `uart_tx`, the other
  SPI pins and SWCLK DUT inputs; I2C and SWDIO bidirectional; a signal the pod watches (`input`) a
  DUT output, one it drives (`output`) a DUT input. So the direction follows from what a pin is used
  for. Older profiles may carry `dut_dirs`, which still overrides the defaults.
  On firmware 3.10.4+ `connect` and `set_wiring` send them to the pod (`la_dir`), which then
  refuses a push-pull driver on a DUT output pin, so the pod never drives against the DUT. Older
  firmware is skipped quietly. `wiring` and `set_wiring` report `directions`, and `status` warns
  when a driven pin kept them from going out.
- **Agent-sized captures.** `capture_adc` returns calibrated statistics, the dominant frequency and a
  min/max envelope; `capture_la` returns per-channel levels, edges and frequencies. The last captures
  stay in the session, so `decode_la`, `replay(from_last_capture=true)` and
  `save_capture_as_recording` don't capture again.
- **Triggered captures.** `capture_adc`, `capture_la` and `capture_correlated` take `trigger_la`
  (+ `trigger_edge` rising/falling/high/low and `trigger_timeout`) so sampling starts on an event —
  t = 0 is the trigger — and the summary echoes it as `trigger: "LA9 rising"`. A condition that
  never happens fails with `TriggerTimeout: …`.
- **Pins and GPIO.** Each LA channel has one owner at a time: none, GPIO, a UART proxy, SWD, the
  an emulated sensor (owner `sensor:<instance>`) or a step train. `la_pins` shows the table, `gpio_mode` / `gpio_write` /
  `gpio_read` / `gpio_wait` / `gpio_pulse` drive and watch channels, `gpio_release` frees them. A
  second claim fails with `PinConflictError: pin conflict: LA5 is in use by uart_rx; …` naming the
  owner and how to free it — so the agent releases GPIO before opening a UART session on that
  channel. Captures observe all 14 channels whatever owns them.
- **Power profiles.** `measure_power(duration)` reports average, minimum and peak current, voltage,
  energy and charge. Every sample is timestamped and the integrals run over those timestamps, so
  energy is integrated rather than estimated. `rate_hz` (100-500, default 500) tracks the request to
  ~200 Hz and then flattens near 365 Hz — the result reports the rate actually delivered in
  `rate_hz` and the sensor's configured rate in `adc_rate_hz`. Optional downsampled trace (`points`). `power_profile_start` / `power_profile_stop` bracket other
  tool calls; the running profile lives on the session (`status` reports it) and is dropped on
  `disconnect`.
- **Sessions.** `uart_open` buffers the DUT's console in the background (open it before
  `power_on`, then `uart_read` / `uart_write`); `can_open` keeps a CAN bus open across calls.
- **Gateware images.** The pod's FPGA runs either the `loop` image (`control_loop`) or the
  `deep_replay` image (replays longer than 2048 samples). `control_loop`, `replay` and
  `replay_waveform` switch automatically (~3 s) and report it as `switched_image`;
  `switch_image: false` fails instead. A switch resets the FPGA — a running DAC output, UART session
  or sensor emulation stops — and the server instructions tell the agent to start those after it.
  `fpga_image` switches explicitly. I2C, SPI and UART sensors run on a third, emulation image that
  `sensor_start` loads by itself; the pod never switches back, so `control_loop` and the deep
  replays switch back once no such sensor runs (and name `sensor_stop` while one does).
- **Non-blocking.** Tools run on worker threads under one device lock: a 5-minute flash doesn't
  freeze the server, sends progress notifications, and concurrent calls can't interleave commands.
- **Annotations.** Read-only tools (`status`, `power_status`, `adc_read`, …) are marked so clients
  can auto-approve them; tools that power, flash or drive voltages are marked destructive.

## Example

> Connect to the bench, flash `build/app.elf` to the STM32F4 (SWCLK on LA11, SWDIO on LA12,
> reset wired), then power-cycle it and tell me whether it reaches `APP_OK` on the UART (DUT TX on
> LA5, RX on LA4).

```
connect()                                   # BENCHPOD_CONNECTION + BENCHPOD_LA_VOLTAGE
flash(swclk=11, swdio=12, nreset=true, target="target/stm32f4x.cfg", file="build/app.elf", target_power=1)
power_cycle_and_capture(rx=5, tx=4, delay=1.0, duration=5.0, until_regex="APP_OK")
```

With a wiring profile stored for the bench, the same run needs no pin numbers:

```
connect()
wiring()                                    # SWCLK on LA11, DUT TX on LA5, rail internal 5 V (efuse 1), …
flash(file="build/app.elf")
power_cycle_and_capture(delay=1.0, duration=5.0, until_regex="APP_OK")
measure_power(duration=2.0, points=100)     # what the firmware draws once it is up
```

## Stability

2.x freezes the tool names, input schemas and annotations (`tests/tools_surface.json`; CI fails on
any unreviewed change): tools and optional parameters may be added, nothing is renamed or removed
within a major version. See [CHANGELOG.md](CHANGELOG.md) for migrating from 0.1.

## Publishing to the MCP Registry

`server.json` describes this package for the [MCP Registry](https://registry.modelcontextprotocol.io).
The `embeddedci-mcp-v*` release workflow publishes it after the PyPI upload (which is what makes
`uvx embeddedci-mcp` work), logged in with GitHub OIDC. Bump both `version` fields in `server.json`
together with `pyproject.toml`: the release fails when they differ, and so does CI.

To publish by hand instead:

```bash
mcp-publisher login github
mcp-publisher publish
```

The registry verifies PyPI ownership through the `mcp-name` comment at the top of this README.

## Development

```bash
pip install -e "../embeddedci[dev]" -e ".[dev]"
pytest
```
