MCP server for STM32 debugging with GDB
Project description
STM32 GDB MCP Server
An MCP server that lets an AI agent debug STM32 firmware on real hardware — drive GDB + OpenOCD/ST-Link/J-Link to flash, breakpoint, inspect memory/registers/RTOS, triage HardFaults, and profile — and get back decoded, structured evidence instead of raw GDB text.
让 AI 智能体在真实硬件上调试 STM32:通过 GDB + OpenOCD/ST-Link/J-Link 烧录、打断点、查 内存/寄存器/RTOS、定位 HardFault、做性能采样,返回已解码的结构化证据而非原始 GDB 文本。
What you get / 能力一览
| Bring-up & flash | suggest_server_args, build_firmware, flash_and_run, self_check, reset_target |
| Execution | run_and_wait (structured stop events), breakpoint, step, halt/continue, debug_until |
| Inspect (halted) | capture_state, read_memory/read_variable, read_registers, frame, read_peripheral_register |
| Fault triage | reconstruct_fault_context (faulting PC → source), diagnose_fault, analyze_stack |
| RTOS | detect_rtos, read_freertos, snapshot(scope=rtos) |
| Observe | logging (RTT/SWO/UART), setup_swo (printf, no decoder), sample_pc (symbolized profiler) |
| Determinism | run_scenario (replay), batch, journal/metrics via get_session, export_debug_report |
| Multi-board | pass session="name" to any tool; list_sessions/close_session |
Two cross-cutting goals: low comprehension cost (decoded outputs, suggested_next_actions)
and minimal repro steps (composites like flash_and_run / debug_until collapse 5–15 calls
into one). Lean surface: ~31 tools in compact mode (full ~60); reach any tool via call(tool, args).
Install / 安装
| Client | One command |
|---|---|
| Claude Code (best — tools + skills + always-on rules) | /plugin marketplace add Zeraissh/stm32-gdb-mcp then /plugin install stm32-debug-kit@zeraissh-stm32 |
| Cursor / VSCode / Codex / Windsurf / Trae | python scripts/deploy.py --project "<firmware dir>" --ide vscode,cursor |
| Manual (any MCP client) | pip install -e . then point your client at stm32-gdb-mcp |
deploy.py installs the server, writes the IDE's MCP config, and drops a project-aware rules
file into your firmware project. Per-client config snippets + the rules template are in
docs/install-ides.md. Compact mode is on by default.
Requirements — on PATH: arm-none-eabi-gdb, plus one server (openocd / JLinkGDBServerCL
/ st-util). Check with python setup_env.py.
30-second quickstart / 快速上手
suggest_server_args(mcu="STM32L431", probe="stlink") # → the -f interface/target cfgs
start_debug_session(server_type="openocd", server_args=[...])
self_check() # ALWAYS first: byte order, core, family
debug_profile(action=set, mcu="STM32L431", elf_path="build/app.elf", svd_path="STM32L4.svd")
flash_and_run(file_path="build/app.elf", run_to="main")
breakpoint(action=set, location="my_func", condition="state == BAD")
run_and_wait() # structured stop event + next actions
reconstruct_fault_context() # on a crash: faulting PC → file:line
The full tool reference (lean families with action=/what=) is
skills/stm32-debug/reference/tool-map.md. The server
also ships always-on instructions, so any MCP client gets the debug loop without setup.
Key rules (the target must cooperate) / 关键规则
- Reads need a HALTED core. If a read says
target_unresponsive,halt_executionfirst. - A breakpoint TIMEOUT means the path was NOT reached — don't just retry. Halt,
capture_state,breakpoint(action=list)(hit_count=0 confirms), read the gating flag, set an earlier breakpoint or drive the precondition. - Writes are guarded (option bytes/IWDG/WWDG blocked) —
write_guard(action=policy)to allow. - Never hard-kill OpenOCD (wedges the ST-Link USB) — use
recover_session. SWD is exclusive.
Response shape / 响应结构
Every tool returns a stable JSON envelope inside the MCP TextContent transport:
{ "ok": true, "data": {}, "error": null, "raw_response": null, "suggested_next_actions": [] }
Human-readable text lives in data.message / error.message; raw GDB output stays in
raw_response when it aids diagnosis. Errors carry a code (e.g. target_unresponsive).
Agent guidance — three layers / 三层引导
- Inline — most results carry
suggested_next_actions(the next loop step). - Always-on — the server's
instructions(debug loop + key rules) inject automatically. - On-demand — skills:
stm32-debug(bring-up, HardFault, hang, minimal repro, replayable scenarios) andstm32-instrument(write-time SWO/ITM trace). In other IDEs the same guidance travels as a rules file (AGENTS.md).
Repeatable config / 可复现配置
Load a YAML debug profile so sessions reproduce across clients:
debug_config(action=load, path="mcp/board.yaml").
mcu: STM32L431CCUx
probe: stlink
server_type: openocd
server_args: ["-f", "interface/stlink.cfg", "-f", "target/stm32l4x.cfg"]
elf_path: build/app.elf
svd_path: STM32L4.svd
See examples/configs/ for J-Link and OpenOCD samples.
Develop / 开发
pip install -e ".[dev]"
python -m ruff check . && python -m pytest && python -m compileall src tests
docs/install-ides.md— per-IDE install + rules templatedocs/TROUBLESHOOTING.md— common failures + recoverydocs/hil-validation.md— hardware-in-the-loop validation (STM32_GDB_MCP_HIL=1)CONTRIBUTING.md,SECURITY.md,docs/release.md
Hardware validation runs on a self-hosted runner labeled stm32; normal CI is hardware-free
(lint, tests, compile, packaging).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stm32_gdb_mcp-0.3.0.tar.gz.
File metadata
- Download URL: stm32_gdb_mcp-0.3.0.tar.gz
- Upload date:
- Size: 492.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baa3acd4e44b00cf3621301c88cded9bde2638d0b4c5768d33bde1370c1c51ba
|
|
| MD5 |
079e524eb6f08b9f52c1fd2ed945703c
|
|
| BLAKE2b-256 |
59b1e80b8dc292bea57ba22f1e6e135bed7516260c89eff402568a879c484726
|
Provenance
The following attestation bundles were made for stm32_gdb_mcp-0.3.0.tar.gz:
Publisher:
release.yml on Zeraissh/stm32-gdb-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stm32_gdb_mcp-0.3.0.tar.gz -
Subject digest:
baa3acd4e44b00cf3621301c88cded9bde2638d0b4c5768d33bde1370c1c51ba - Sigstore transparency entry: 2034644703
- Sigstore integration time:
-
Permalink:
Zeraissh/stm32-gdb-mcp@73e68b4dca1abfe0fdf902592cab306002054341 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Zeraissh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73e68b4dca1abfe0fdf902592cab306002054341 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stm32_gdb_mcp-0.3.0-py3-none-any.whl.
File metadata
- Download URL: stm32_gdb_mcp-0.3.0-py3-none-any.whl
- Upload date:
- Size: 161.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7a6566d51b6c44597027ccc3a2afdf4a6e5b51d382137c7bd372d793ac1ac13
|
|
| MD5 |
b531f61c0aef1fd7426b7a9ea7269e6d
|
|
| BLAKE2b-256 |
0e47af0fb9a93e187e98f2f293d24b5a6d8448189ea908e14a15bb6405aa0050
|
Provenance
The following attestation bundles were made for stm32_gdb_mcp-0.3.0-py3-none-any.whl:
Publisher:
release.yml on Zeraissh/stm32-gdb-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stm32_gdb_mcp-0.3.0-py3-none-any.whl -
Subject digest:
d7a6566d51b6c44597027ccc3a2afdf4a6e5b51d382137c7bd372d793ac1ac13 - Sigstore transparency entry: 2034644868
- Sigstore integration time:
-
Permalink:
Zeraissh/stm32-gdb-mcp@73e68b4dca1abfe0fdf902592cab306002054341 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Zeraissh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73e68b4dca1abfe0fdf902592cab306002054341 -
Trigger Event:
push
-
Statement type: