stm32-stlink-mcp
MCP server for debugging STM32 microcontrollers over ST-LINK using STM32CubeCLT tools (GDB, ST-LINK_gdbserver, STM32_Programmer_CLI) with session management, flashing, breakpoints, memory/register access, and expression evaluation.
README
stm32-stlink-mcp
MCP server for debugging STM32 microcontrollers over ST-LINK, built on STMicroelectronics' own
STM32CubeCLT toolset — ST-LINK_gdbserver, STM32_Programmer_CLI, and arm-none-eabi-gdb
(driven via GDB/MI2). No OpenOCD, J-Link, or probe-rs involved.
Architecture
A debug session is a pair of child processes, exactly mirroring ST's own documented workflow (UM2576, "STM32CubeIDE ST-LINK GDB server"):
arm-none-eabi-gdb --interpreter=mi2 --(TCP, target extended-remote)--> ST-LINK_gdbserver --(USB)--> ST-LINK --(SWD)--> STM32
arm-none-eabi-gdb is driven in MI2 mode so the server gets source-level stepping, symbolic
breakpoints, and symbol-aware expression evaluation for free, instead of hand-rolling the GDB
Remote Serial Protocol. ST-LINK_gdbserver owns the USB handle to the probe for the lifetime of
the session; flashing via gdb's load (MI: -target-download) is transparently delegated by the
server to STM32CubeProgrammer, so no session teardown is needed to reflash. A standalone
one-shot flash (flash_standalone, no session required) invokes STM32_Programmer_CLI directly
and therefore conflicts with an already-open session on the same probe — see the tool description.
Setup
npm install
npm run build
Requires STM32CubeCLT to be installed and its bin/ directories reachable — either already on
PATH (the CLT installer does this by default) or via STMCP_CUBECLT_PATH / per-tool overrides.
Run npm run doctor to check.
Running
node dist/index.js serve # starts the MCP server on stdio (default mode)
node dist/index.js doctor # pre-flight check: tool resolution, connected probes, udev rules
node dist/index.js doctor --json
Registering with an MCP client
{
"mcpServers": {
"stm32-stlink": {
"command": "node",
"args": ["<path-to-this-repo>/stmcp/dist/index.js"]
}
}
}
Configuration (environment variables)
| Variable | Default | Purpose |
|---|---|---|
STMCP_GDBSERVER_PATH / STMCP_PROGRAMMER_CLI_PATH / STMCP_ARM_GDB_PATH |
— | Per-binary override (highest priority) |
STMCP_CUBECLT_PATH |
— | CubeCLT install root; subpaths resolved via STM32CubeCLT_metadata.sh -j |
STMCP_STLINK_SERIAL |
— | Default probe serial (omit to auto-select if exactly one is attached) |
STMCP_DEFAULT_DEVICE |
STM32G431CBTx |
Default MCU device string |
STMCP_DEFAULT_INTERFACE |
swd |
swd or jtag |
STMCP_DEFAULT_FREQUENCY_KHZ |
4000 |
SWD/JTAG clock |
STMCP_MAX_SESSIONS |
1 |
Concurrent debug session cap |
STMCP_GDBSERVER_READY_TIMEOUT_MS |
8000 |
How long to wait for "Waiting for debugger connection..." |
STMCP_LOG_LEVEL |
info |
error | warn | info | debug |
STMCP_LOG_FILE |
— | Optional log file (stderr always used regardless — stdout is reserved for MCP framing) |
STMCP_ALLOW_FLASH_ERASE |
false |
Enables the erase path |
STMCP_ALLOW_MEMORY_WRITE |
true |
Enables memory_write |
STMCP_ALLOW_FLASH_ADDRESS_WRITE |
false |
Allows memory_write to target the flash address window (normally blocked — use the flash tools instead) |
STMCP_ALLOWED_FILE_PATHS |
(unrestricted) | Comma-separated allowlist roots for ELF/bin file arguments |
STMCP_MAX_FILE_SIZE_BYTES |
16777216 |
Max size for file arguments |
STMCP_FLASH_RANGE_START / STMCP_FLASH_RANGE_END |
0x08000000 / 0x08020000 |
Flash address window for the write guard (default: 128KB, STM32G431CB) |
Tools
| Domain | Tool | Purpose |
|---|---|---|
| Probe | list_probes |
List connected ST-LINK probes |
| Session | debug_connect |
Spawn gdbserver+gdb, load ELF symbols, connect |
| Session | debug_disconnect |
Clean session teardown |
| Session | debug_session_status |
Session info (one, or all) |
| Flash | flash_standalone |
One-shot flash via STM32_Programmer_CLI, no session needed |
| Flash | flash_load_in_session |
Reflash via gdb load inside an open session |
| Execution | debug_run |
Resume/continue |
| Execution | debug_halt |
Interrupt |
| Execution | debug_reset |
Reset (monitor reset [halt]) |
| Execution | debug_step |
Step over/into/out |
| Breakpoints | breakpoint_set / breakpoint_clear / breakpoint_list |
By file:line, symbol, or *addr |
| Memory | memory_read / memory_write |
Raw memory access (write is guarded) |
| Registers | register_read / register_write |
Named core registers |
| Registers | read_fault_registers |
One-call Cortex-M SCB fault register dump (CFSR/HFSR/... decoded) |
| Expressions | evaluate_expression |
Symbol-aware evaluation via gdb MI |
Deferred to v2
SVD peripheral register tools (memory_read/write + evaluate_expression already reach everything by
address), live/streaming memory polling, a plugin system, per-chip memory-region allowlists,
arbitrary gdb monitor passthrough, and option-bytes/RDP tools (bricking-capable, intentionally
out of scope).
RTT
RTT (SEGGER Real Time Transfer — live, non-halting console/variable tracing) is intentionally
not implemented in this server. ST-LINK_gdbserver's GDB/MI stub has no non-stop mode, so
reading memory through this server's debug_connect session requires halting the core first —
which defeats RTT's purpose. The correct mechanism is direct AP memory access that never halts
the core (confirmed by reading ST's own STM32CubeMonitor source, which uses exactly this, and by
STM32_Programmer_CLI's -r32fast).
That's what strtt already does, and
strtt-mcp wraps it as its own MCP server
(strtt_start/strtt_stop/strtt_status/strtt_read/strtt_write). Register it alongside
this server rather than through it:
{
"mcpServers": {
"stm32-stlink": { "command": "node", "args": ["<...>/mcp-server/dist/index.js"] },
"strtt": {
"command": "node",
"args": ["<path-to-strtt-repo>/mcp/dist/index.js"],
"env": { "STRTT_BIN": "<path-to-strtt-binary>" }
}
}
}
Start strtt_start with tcp: true to connect through the shared ST-LINK Server instead of
claiming the USB device directly — this lets it run concurrently with an open debug_connect
session here, since GdbServerProcess always passes -t/--shared to ST-LINK_gdbserver.
Without tcp: true, strtt and an open debug session will contend for the same probe.
Hardware verification runbook
With an ST-LINK and target attached:
node dist/index.js doctor # confirm probe + tools resolve
npx @modelcontextprotocol/inspector node dist/index.js # interactive tool testing
Then, via the inspector or an MCP client:
list_probes→ the probe's serial appears.debug_connect { elfPath, device, interface: "swd", serial }→ returns asessionId.breakpoint_set { sessionId, location: "main" }→ returns a breakpoint number.debug_run { sessionId }→ halts withreason: "breakpoint-hit".register_read { sessionId, registers: ["pc","sp","lr","r0"] }.evaluate_expression { sessionId, expression: "<a known global>" }.read_fault_registers { sessionId }→ benign/zero flags right after reset.debug_disconnect { sessionId }→ confirm no orphaned processes:ps aux | grep -E 'ST-LINK_gdbserver|arm-none-eabi-gdb'.flash_standalone { file, reset: "hard", run: true }with no session open.- Negative test: open a session, then call
flash_standaloneon the same serial → expectDEVICE_BUSY.
Note: debug_connect halts the target's CPU. Don't attach to a board that's actively driving
actuators/outputs in a way where an unplanned halt would be unsafe, without first confirming that's OK.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。