Skip to main content
Glama
phryniszak

stm32-stlink-mcp

by phryniszak

stm32-stlink-mcp

用于通过 ST-LINK 调试 STM32 微控制器的 MCP 服务器,基于 STMicroelectronics 自家的 STM32CubeCLT 工具集构建——ST-LINK_gdbserverSTM32_Programmer_CLIarm-none-eabi-gdb(通过 GDB/MI2 驱动)。不涉及 OpenOCD、J-Link 或 probe-rs。

架构

调试会话由一对子进程组成,精确复刻 ST 官方文档描述的工作流程(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 以 MI2 模式驱动,因此服务器无需自行实现 GDB 远程串行协议,即可免费获得源码级单步、符号断点和符号感知的表达式求值。ST-LINK_gdbserver 在会话生命周期内持有探针的 USB 句柄;通过 gdb 的 load(MI:-target-download)进行的烧录由服务器透明地委托给 STM32CubeProgrammer,因此重新烧录无需拆除会话。独立的一次性烧录(flash_standalone,无需会话)直接调用 STM32_Programmer_CLI,因此会与同一探针上已打开的会话冲突——请参阅工具描述。

Related MCP server: dbgprobe-mcp-server

安装

npm install
npm run build

需要安装 STM32CubeCLT 并确保其 bin/ 目录可访问——要么已经位于 PATH 中(CLT 安装程序默认会这样做),要么通过 STMCP_CUBECLT_PATH / 按工具的覆盖路径指定。运行 npm run doctor 进行检查。

运行

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

向 MCP 客户端注册

{
  "mcpServers": {
    "stm32-stlink": {
      "command": "node",
      "args": ["<path-to-this-repo>/stmcp/dist/index.js"]
    }
  }
}

配置(环境变量)

变量

默认值

用途

STMCP_GDBSERVER_PATH / STMCP_PROGRAMMER_CLI_PATH / STMCP_ARM_GDB_PATH

单个二进制文件的覆盖路径(优先级最高)

STMCP_CUBECLT_PATH

CubeCLT 安装根目录;子路径通过 STM32CubeCLT_metadata.sh -j 解析

STMCP_STLINK_SERIAL

默认探针序列号(省略时,若仅连接一个探针则自动选择)

STMCP_DEFAULT_DEVICE

STM32G431CBTx

默认 MCU 设备字符串

STMCP_DEFAULT_INTERFACE

swd

swdjtag

STMCP_DEFAULT_FREQUENCY_KHZ

4000

SWD/JTAG 时钟频率

STMCP_MAX_SESSIONS

1

并发调试会话上限

STMCP_GDBSERVER_READY_TIMEOUT_MS

8000

等待 "Waiting for debugger connection..." 的超时时间

STMCP_LOG_LEVEL

info

error | warn | info | debug

STMCP_LOG_FILE

可选日志文件(无论如何都会使用 stderr——stdout 保留给 MCP 帧)

STMCP_ALLOW_FLASH_ERASE

false

启用擦除路径

STMCP_ALLOW_MEMORY_WRITE

true

启用 memory_write

STMCP_ALLOW_FLASH_ADDRESS_WRITE

false

允许 memory_write 以 flash 地址窗口为目标(通常被阻止——请改用 flash 工具)

STMCP_ALLOWED_FILE_PATHS

(不受限制)

用于 ELF/bin 文件参数的逗号分隔白名单根目录

STMCP_MAX_FILE_SIZE_BYTES

16777216

文件参数的最大大小

STMCP_FLASH_RANGE_START / STMCP_FLASH_RANGE_END

0x08000000 / 0x08020000

写入保护的 flash 地址窗口(默认:128KB,STM32G431CB)

工具

领域

工具

用途

探针

list_probes

列出已连接的 ST-LINK 探针

会话

debug_connect

启动 gdbserver+gdb,加载 ELF 符号,连接

会话

debug_disconnect

干净地拆除会话

会话

debug_session_status

会话信息(单个或全部)

烧录

flash_standalone

通过 STM32_Programmer_CLI 进行一次性烧录,无需会话

烧录

flash_load_in_session

在已打开的会话中通过 gdb load 重新烧录

执行

debug_run

恢复/继续

执行

debug_halt

中断

执行

debug_reset

复位(monitor reset [halt])

执行

debug_step

单步跳过/进入/跳出

断点

breakpoint_set / breakpoint_clear / breakpoint_list

按 file:line、符号或 *addr

内存

memory_read / memory_write

原始内存访问(写入受保护)

寄存器

register_read / register_write

按名称访问的核心寄存器

寄存器

read_fault_registers

一次调用即可转储 Cortex-M SCB 故障寄存器(CFSR/HFSR/... 已解码)

表达式

evaluate_expression

通过 gdb MI 进行符号感知的求值

推迟到 v2

SVD 外设寄存器工具(memory_read/write + evaluate_expression 已经可以通过地址访问一切)、实时/流式内存轮询、插件系统、按芯片划分的内存区域白名单、任意 gdb monitor 透传,以及选项字节/RDP 工具(可能导致变砖,有意不在范围内)。

RTT

RTT(SEGGER 实时传输——实时、不暂停内核的控制台/变量跟踪)有意在此服务器中实现。ST-LINK_gdbserver 的 GDB/MI 存根没有非停止模式,因此通过此服务器的 debug_connect 会话读取内存需要先暂停内核——这违背了 RTT 的目的。正确的机制是永不暂停内核的直接 AP 内存访问(通过阅读 ST 自家的 STM32CubeMonitor 源码确认,它正是使用这种方式,STM32_Programmer_CLI-r32fast 也是如此)。

这正是 strtt 已经实现的功能,strtt-mcp 将其封装为独立的 MCP 服务器(strtt_start/strtt_stop/strtt_status/strtt_read/strtt_write)。请将其与此服务器并列注册,而不是通过它注册:

{
  "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>" }
    }
  }
}

使用 tcp: true 启动 strtt_start,通过共享的 ST-LINK Server 连接,而不是直接占用 USB 设备——这样它就可以与此处打开的 debug_connect 会话并发运行,因为 GdbServerProcess 总是将 -t/--shared 传递给 ST-LINK_gdbserver。如果不使用 tcp: truestrtt 和已打开的调试会话将争用同一个探针。

硬件验证手册

连接好 ST-LINK 和目标板后:

node dist/index.js doctor                     # confirm probe + tools resolve
npx @modelcontextprotocol/inspector node dist/index.js   # interactive tool testing

然后,通过检查器或 MCP 客户端:

  1. list_probes → 探针的序列号会出现。

  2. debug_connect { elfPath, device, interface: "swd", serial } → 返回一个 sessionId

  3. breakpoint_set { sessionId, location: "main" } → 返回一个断点编号。

  4. debug_run { sessionId } → 以 reason: "breakpoint-hit" 暂停。

  5. register_read { sessionId, registers: ["pc","sp","lr","r0"] }

  6. evaluate_expression { sessionId, expression: "<a known global>" }

  7. read_fault_registers { sessionId } → 复位后标志为良性/零值。

  8. debug_disconnect { sessionId } → 确认没有孤儿进程:ps aux | grep -E 'ST-LINK_gdbserver|arm-none-eabi-gdb'

  9. flash_standalone { file, reset: "hard", run: true },且没有打开的会话。

  10. 负向测试:打开一个会话,然后在同一序列号上调用 flash_standalone → 预期返回 DEVICE_BUSY

注意: debug_connect 会暂停目标 CPU。如果电路板正在主动驱动执行器/输出,且意外暂停可能不安全,请勿在未事先确认可行的情况下连接。

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Stateful MCP server for driving debug probes (J-Link) to flash, debug, and inspect embedded targets. Enables AI agents to perform flash, memory, breakpoint, and ELF/SVD-aware operations conversationally.
    41
    11
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    MCP server for embedded debugging based on probe-rs, providing 22 tools for ARM Cortex-M and RISC-V microcontrollers, including connection, memory operations, breakpoints, flash programming, and RTT communication.
    2
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server that provides comprehensive debugging capabilities for J-Link debuggers, enabling memory, flash, register, and RTT operations through AI assistants.
    32
    MIT

View all related MCP servers

Related MCP Connectors

  • MCP server for Klever blockchain smart contract development.

  • An MCP server that let you interact with Cycloid.io Internal Development Portal and Platform

  • A MCP server built for developers enabling Git based project management with project and personal…

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/phryniszak/stmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server