Skip to main content

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), run_for_duration (soak/sample then halt/capture), 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
run_for_duration(duration_sec=30, capture={"expressions": ["rx_count"]})
run_for_duration(duration_sec=60, sample={"interval_ms": 500, "expressions": ["rx_count", "state"]})
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_execution first.
  • run_for_duration(sample=...) is best-effort low-rate debugger polling. It does not halt the target itself, but running-target expression reads may fail on some probes/MCUs; use SWO/ring-buffer firmware telemetry for higher-rate or guaranteed capture.
  • 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 / 三层引导

  1. Inline — most results carry suggested_next_actions (the next loop step).
  2. Always-on — the server's instructions (debug loop + key rules) inject automatically.
  3. On-demand — skills: stm32-debug (bring-up, HardFault, hang, minimal repro, replayable scenarios) and stm32-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

Hardware validation runs on a self-hosted runner labeled stm32; normal CI is hardware-free (lint, tests, compile, packaging).

Metadata

Release files for stm32-gdb-mcp 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stm32-gdb-mcp 0.4.0
File Size Uploaded
stm32_gdb_mcp-0.4.0.tar.gz 500.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stm32-gdb-mcp 0.4.0
File Interpreter ABI Platform
stm32_gdb_mcp-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 666.0 kB

Release files / stm32_gdb_mcp-0.4.0.tar.gz

Download URL stm32_gdb_mcp-0.4.0.tar.gz
Size 500.1 kB
Tags Source
SHA-256 checksum
How to use checksums
71f63e171518ad7e931c58fec2ab68b5447e979ec4a418f35173d060eaf09495
BLAKE2b-256 checksum
How to use checksums
847a60e4676ab475552c6da4002c9f4057b9dd107a95685cd77fe4fef8c05fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Release files / stm32_gdb_mcp-0.4.0-py3-none-any.whl

Download URL stm32_gdb_mcp-0.4.0-py3-none-any.whl
Size 165.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acbdf7a37b7f59d2e7815570cd6d559ccb277fd995101ebb634d3fc0bbe9f905
BLAKE2b-256 checksum
How to use checksums
04f0991533d6f088a6e539417e1a467dd4fb0981bbad64ae8f440fc245a7efaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.1

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page