Metadata-Version: 2.4
Name: mpy-workbench
Version: 0.3.0
Summary: Run, upload and debug MicroPython on a board over USB, from the terminal or any MCP client (Claude Code, Cursor…).
License-Expression: MIT
Project-URL: Homepage, https://github.com/DanielBustillos/mpy-workbench/tree/main/plugin
Project-URL: Repository, https://github.com/DanielBustillos/mpy-workbench
Project-URL: Issues, https://github.com/DanielBustillos/mpy-workbench/issues
Keywords: micropython,esp32,raspberry-pi-pico,mpremote,mcp
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: mpremote>=1.26

# MPY Workbench for Claude Code

<!-- mcp-name: io.github.DanielBustillos/mpy-workbench -->

Let Claude run, upload and debug MicroPython on your board. Plug in an ESP32, a Raspberry Pi Pico or another MicroPython board, and ask: *"make the LED blink every half second"*. Claude writes the code, runs it on the board, reads the output and the traceback, and fixes it.

No VS Code needed. The only requirement is Python 3.8 or newer: everything else (mpremote) is installed on first use, in a folder of its own.

## Install

In Claude Code:

```
/plugin marketplace add DanielBustillos/mpy-workbench
/plugin install mpy-workbench@mpy-workbench
```

Or only the board tools, in one line (needs [uv](https://docs.astral.sh/uv/getting-started/installation/)):

```bash
claude mcp add mpy-workbench -- uvx mpy-workbench mcp
```

In **Claude Desktop** (the chat app, not Claude Code): download `mpy-workbench-<version>.mcpb` from the newest
`plugin-v…` release on the [Releases page](https://github.com/DanielBustillos/mpy-workbench/releases), open it, pick
your project folder and click **Install**. Then ask Claude, for example, "blink the LED on my ESP32".

## What Claude can do

| Tool | What it does |
|---|---|
| `run_file` | Uploads every project file that changed (syntax-checked first), runs the file, returns output and traceback |
| `run_code` | Runs a few lines, like the REPL |
| `read_output` / `stop` | Reads what a program that keeps running printed, or stops it |
| `upload` | Uploads a file or folder; only what changed, checked by SHA-256 |
| `sync` / `diff` | Makes the board match the project folder, or shows what differs (with a line diff for one file) |
| `list_files` / `read_file` | Looks at the board's files |
| `board_info` / `list_ports` | Chip, MicroPython version, memory, ports |
| `soft_reset` | Clears memory and imported modules |

Project files keep their path on the board: `lib/util.py` here is `/lib/util.py` there.

**Live output.** A program that keeps running after `run_file`'s timeout (a blink, a sensor loop, a server)
goes on writing what it prints to `.mpy-workbench/output.log` in the project, live. Watch it with
`tail -f .mpy-workbench/output.log` or `mpywb follow`. A background process holds the port for that, and gives it
up as soon as any command needs the board, the program ends or Claude's session closes.

## The board follows the project

- **Auto-upload:** in a MicroPython project (one with a `.mpy-workbench/` folder or a `.mpyignore` file), every file Claude writes or edits goes to the board right away, and Claude is told. Other projects are never touched. Set `MPYWB_AUTO_UPLOAD=1` to do it in any project, or `0` to turn it off.
- **Ignore rules:** `.mpyignore` (or `.mpy-workbench/.mpyignore`, the one the VS Code extension uses) lists what stays off the board, one pattern per line: `*.md`, `docs/`, `/secret.py`, `**/test_*`. `.git`, `node_modules`, `__pycache__` and similar are always skipped.
- **Sync:** `sync` uploads every file that differs; files that are only on the board are kept unless you ask to delete them (`dry_run` shows the plan first).
- **Before running:** `run_file` first uploads every project file that differs from the board (so a changed module it imports is not left stale), never deleting anything.
- **Syntax check:** `run_file`, `upload`, `sync` and auto-upload compile changed `.py` files on your computer first; with a syntax error nothing is uploaded and the error names the file and line. `MPYWB_SYNTAX_CHECK=0` turns it off.
- **Two sessions, one board:** commands from different Claude Code sessions (or the terminal) take turns on a board; one waits up to 20 s (`MPYWB_LOCK_WAIT`) for the other, then says who has it. A busy port names the program holding it (macOS, Linux), and a port that doesn't exist says so and lists the ports there are.

## From the terminal

The same tool works without Claude:

```bash
pip install mpy-workbench   # or run python3 plugin/bin/mpywb without installing
mpywb run main.py
mpywb diff               # what differs between the project and the board
mpywb sync --dry-run     # what sync would upload
mpywb follow             # watch a running program's output live (Ctrl-C quits)
mpywb --help
```

## Other MCP clients (Cursor, VS Code Copilot, Windsurf…)

The board tools are a standard MCP server on stdio:

```json
{ "mcpServers": { "micropython-board": { "command": "uvx", "args": ["mpy-workbench", "mcp"] } } }
```

(or `"command": "mpywb", "args": ["mcp"]` after `pip install mpy-workbench`).

## With VS Code

The [MPY Workbench extension](https://marketplace.visualstudio.com/items?itemName=DanielBucam.mpy-workbench) keeps the port open while VS Code works with the board. From version 0.4.5 it shares it: Claude's calls go through VS Code, and what Claude runs shows in the **MPY Board** terminal. With an older version, run **MPY Workbench: Release Serial Port** there first.

## Windows

The plugin starts `python3`. If your Python is called `python` or `py`, set `MPYWB_PYTHON` (for example in the `env` section of Claude Code's `settings.json`: `"MPYWB_PYTHON": "python"`).

## Limits

- Boards with a USB-serial chip (CP210x, CH340, FTDI: many ESP32 dev boards) open with DTR and RTS low, so opening the port doesn't reset them. If a board needs the old behaviour, set `MPYWB_RESET_ON_OPEN=1`.
- Tested with a board on macOS (ESP32-S3). Windows and Linux are covered by the automatic tests, without a board.
