stm32-stlink-mcp
stm32-stlink-mcp
用于通过 ST-LINK 调试 STM32 微控制器的 MCP 服务器,基于 STMicroelectronics 自家的 STM32CubeCLT 工具集构建——ST-LINK_gdbserver、STM32_Programmer_CLI 和 arm-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)--> STM32arm-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"]
}
}
}配置(环境变量)
变量 | 默认值 | 用途 |
| — | 单个二进制文件的覆盖路径(优先级最高) |
| — | CubeCLT 安装根目录;子路径通过 |
| — | 默认探针序列号(省略时,若仅连接一个探针则自动选择) |
|
| 默认 MCU 设备字符串 |
|
|
|
|
| SWD/JTAG 时钟频率 |
|
| 并发调试会话上限 |
|
| 等待 "Waiting for debugger connection..." 的超时时间 |
|
|
|
| — | 可选日志文件(无论如何都会使用 stderr——stdout 保留给 MCP 帧) |
|
| 启用擦除路径 |
|
| 启用 |
|
| 允许 |
| (不受限制) | 用于 ELF/bin 文件参数的逗号分隔白名单根目录 |
|
| 文件参数的最大大小 |
|
| 写入保护的 flash 地址窗口(默认:128KB,STM32G431CB) |
工具
领域 | 工具 | 用途 |
探针 |
| 列出已连接的 ST-LINK 探针 |
会话 |
| 启动 gdbserver+gdb,加载 ELF 符号,连接 |
会话 |
| 干净地拆除会话 |
会话 |
| 会话信息(单个或全部) |
烧录 |
| 通过 STM32_Programmer_CLI 进行一次性烧录,无需会话 |
烧录 |
| 在已打开的会话中通过 gdb |
执行 |
| 恢复/继续 |
执行 |
| 中断 |
执行 |
| 复位(monitor reset [halt]) |
执行 |
| 单步跳过/进入/跳出 |
断点 |
| 按 file:line、符号或 |
内存 |
| 原始内存访问(写入受保护) |
寄存器 |
| 按名称访问的核心寄存器 |
寄存器 |
| 一次调用即可转储 Cortex-M SCB 故障寄存器(CFSR/HFSR/... 已解码) |
表达式 |
| 通过 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: true,strtt 和已打开的调试会话将争用同一个探针。
硬件验证手册
连接好 ST-LINK 和目标板后:
node dist/index.js doctor # confirm probe + tools resolve
npx @modelcontextprotocol/inspector node dist/index.js # interactive tool testing然后,通过检查器或 MCP 客户端:
list_probes→ 探针的序列号会出现。debug_connect { elfPath, device, interface: "swd", serial }→ 返回一个sessionId。breakpoint_set { sessionId, location: "main" }→ 返回一个断点编号。debug_run { sessionId }→ 以reason: "breakpoint-hit"暂停。register_read { sessionId, registers: ["pc","sp","lr","r0"] }。evaluate_expression { sessionId, expression: "<a known global>" }。read_fault_registers { sessionId }→ 复位后标志为良性/零值。debug_disconnect { sessionId }→ 确认没有孤儿进程:ps aux | grep -E 'ST-LINK_gdbserver|arm-none-eabi-gdb'。flash_standalone { file, reset: "hard", run: true },且没有打开的会话。负向测试:打开一个会话,然后在同一序列号上调用
flash_standalone→ 预期返回DEVICE_BUSY。
注意: debug_connect 会暂停目标 CPU。如果电路板正在主动驱动执行器/输出,且意外暂停可能不安全,请勿在未事先确认可行的情况下连接。
Maintenance
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
- AlicenseNot gradedqualityBmaintenanceA GDB/MI protocol server based on the MCP protocol, providing remote application debugging capabilities.68MIT
- AlicenseAqualityCmaintenanceStateful 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.4111MIT
- AlicenseNot gradedqualityCmaintenanceMCP 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.2MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides comprehensive debugging capabilities for J-Link debuggers, enabling memory, flash, register, and RTT operations through AI assistants.32MIT
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…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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