agent-mcu MCP server
# agent-mcu-flow
[](https://github.com/linxi27667/agent-mcu-flow/actions/workflows/ci.yml)
[](LICENSE)
[](pyproject.toml)
**AI-native end-to-end MCU development & Hardware-in-the-Loop (HIL) workflow engine for STM32 & ESP32** — zero runtime pip dependencies, unified CLI + stdio MCP server, declarative STM32CubeMX CLI automation, CMSIS-SVD register/clock/HardFault verification, and a 3-layer C architecture gate.
Part of the `agent-*` cross-surface automation suite:
- [`agent-browser-bridge`](https://github.com/linxi27667/agent-browser-bridge) — Browser CDP automation
- [`agent-desktop`](https://github.com/linxi27667/agent-desktop) — Windows UIA/vision desktop automation
- [`agent-mobile-auto`](https://github.com/linxi27667/agent-mobile-auto) — Android/iOS mobile automation
- **`agent-mcu-flow`** — Embedded MCU firmware & J-Link/SVD hardware closed-loop automation
---
## Why `agent-mcu-flow`?
1. **Human-readable GUI drawings + AI-driven CLI execution**: Complex STM32 PLL clock trees live in verified golden `.ioc` bases (`templates/base-ioc/`), while AI drives peripheral/pin assignment declaratively via `hardware_spec.json` -> ST UM1718 CubeMX CLI script -> `ioc-audit` verification. Humans can always double-click `.ioc` in CubeMX GUI at any time.
2. **Dual-Track Bottom-Up Entry**:
- **Track A (`stm32-cubemx-cmake` / `esp32-idf`)**: Production-grade HAL/LL/IDF with strict zero-conflict isolation (`cmake/user_app.cmake` + minimal `App_Init()`/`App_Poll()` facade in `Core/Src/main.c`).
- **Track B (`stm32-baremetal-reg`)**: Clean RM0090 register-level C11 bare-metal projects backed by offline SVD bitfield lookup and live J-Link register readback.
3. **Hardware Truth Over Guesswork (Zero-Dependency SVD Engine)**:
- `agent-mcu svd-query`: Look up exact peripheral/register/bitfield offsets from official `.svd` before writing register code.
- `agent-mcu clock-check`: Read real `RCC` & `FLASH_ACR` over J-Link to verify `SYSCLK / HCLK / PCLK1 / PCLK2` MHz and Flash wait-state safety (STM32 F4/F1/G4/L4/H7/F0).
- `agent-mcu svd-read --expect`: Assert real hardware register bitfields as automated pass/fail gates.
- `agent-mcu fault-decode`: Automatically decode ARM Cortex-M `CFSR/HFSR/MMFAR/BFAR`, detect `MSP/PSP` stacked exception frames, and resolve faulting `PC/LR` via `arm-none-eabi-addr2line`.
4. **Native CLI + Zero-Dependency Stdio MCP Server**: Works seamlessly with Claude Code, Cursor, Codex, and Antigravity (`agent-mcu mcp`, 9 tools).
---
## Quick Start
```bash
# Install with uv (zero runtime dependencies)
uv sync --extra dev
# 1. Detect local toolchains (CubeMX, CubeCLT, ARM-GCC/GDB, Keil, J-Link, ESP-IDF, SVD)
uv run agent-mcu detect .
# 2. Scaffold a new standardized project (3 tracks)
uv run agent-mcu scaffold --track stm32-cubemx-cmake --out ./my_fw --name lift_ctrl --mcu STM32F407ZET6 --hse-mhz 8 --sysclk-mhz 168
# 3. Compile declarative CubeMX UM1718 CLI script from hardware_spec.json (add --execute with CubeMX installed)
uv run agent-mcu cubemx-apply examples/stm32f407-dual-track/hardware_spec.json \
--out-dir examples/stm32f407-dual-track/track_a_cubemx_cmake
# 4. Audit .ioc against schematic hardware_spec.json & export read-only Markdown snapshot
uv run agent-mcu ioc-audit examples/stm32f407-dual-track/track_a_cubemx_cmake/stm32f407_pilot.ioc \
--hardware-spec examples/stm32f407-dual-track/hardware_spec.json --require-cmake
# 5. Enforce 3-layer C architecture gate (config -> driver -> application -> task)
uv run agent-mcu arch-check examples/stm32f407-dual-track/track_b_baremetal_reg --strict
# 6. On hardware with J-Link: verify real 168 MHz SYSCLK + Flash Wait States
uv run agent-mcu clock-check --device STM32F407ZE --usb-serial <SERIAL> --hse-mhz 8 --expect-sysclk-mhz 168 --strict-warnings
# 7. Start stdio MCP server for AI coding agents
uv run agent-mcu mcp
```
## STM32F407ZET6 Dual-Track Pilot
See [`examples/stm32f407-dual-track/`](examples/stm32f407-dual-track/README.md):
- `track_a_cubemx_cmake/`: Declarative CubeMX + CMake + isolated 3-layer app (`App_Init`/`App_Poll` top facade + domain-named `Heartbeat_Step`).
- `track_b_baremetal_reg/`: Self-contained RM0090 pure-register firmware (`HSE 8MHz -> PLL 168MHz`, `PG2 LED_RUN`, `USART1 115200 8N1`), continuously cross-compiled by real `arm-none-eabi-gcc` in GitHub Actions CI.
## MCP Server Tools (`agent-mcu mcp`)
| Tool | Purpose |
| :--- | :--- |
| `mcu_detect_env` | Probe installed CubeMX, CubeCLT, CMake, ARM-GCC/GDB, Keil, J-Link, ESP-IDF, SVD files |
| `mcu_svd_query` | Offline CMSIS-SVD peripheral/register/bitfield lookup |
| `mcu_svd_read` | Live J-Link/GDB/mock register readback + bitfield assertions |
| `mcu_clock_check` | Real STM32 RCC + FLASH_ACR frequency & wait-state audit |
| `mcu_fault_decode` | Cortex-M HardFault/BusFault/UsageFault + PSP/MSP stack frame + ELF line resolution |
| `mcu_ioc_audit` | Parse `.ioc` and cross-verify against `hardware_spec.json` |
| `mcu_cubemx_apply` | Compile/execute UM1718 CubeMX CLI script from golden `.ioc` base + `hardware_spec.json` |
| `mcu_arch_check` | 3-layer C architecture boundary linter |
| `mcu_scaffold` | Generate 3-track MCU project skeletons |
TDQS
Scored across 9 tools
Each tool targets a distinct action (read registers, check clocks, decode faults, audit .ioc, apply CubeMX config, check arch, scaffold, detect env, query SVD). The closest pair is mcu_svd_read vs mcu_svd_query and mcu_ioc_audit vs mcu_cubemx_apply, but descriptions clearly distinguish hardware-read vs offline-query and read-only-audit vs generate/apply.
All tools use a uniform mcu_<verb>_<noun> snake_case pattern (svd_read, clock_check, fault_decode, ioc_audit, cubemx_apply, arch_check, detect_env, svd_query). No mixing of conventions or casing.
Nine tools is well within the ideal 3-15 range and each maps to a concrete stage of an embedded workflow (detect, scaffold, configure, verify, decode). No obviously redundant or filler tools.
Coverage spans environment detection, scaffolding, SVD introspection, clock/fault verification, config audit and CubeMX application, which is a coherent lifecycle. The main gap is the absence of an explicit build/flash/serial-monitor tool, which agents would have to handle via shell.