Skip to main content
Glama
stm32-stlink-mcp

stm32-stlink-mcp

by phryniszak

{"type": "text"}

stm32-stlink-mcp

STM32マイクロコントローラをST-LINK経由でデバッグするためのMCPサーバーで、STMicroelectronics純正のSTM32CubeCLTツールセット(ST-LINK_gdbserver、STM32_Programmer_CLI、arm-none-eabi-gdb(GDB/MI2経由で駆動))を基に構築されています。OpenOCD、J-Link、probe-rsは使用しません。

Architecture

デバッグセッションは、STが公式に文書化したワークフロー(UM2576、「STM32CubeIDE ST-LINK GDB server」)を正確にミラーリングした、2つの子プロセスのペアです:

 arm-none-eabi-gdb  --interpreter=mi2  --(TCP, target extended-remote)-->  ST-LINK_gdbserver  --(USB)-->  ST-LINK  --(SWD)-->  STM32

arm-none-eabi-gdbはMI2モードで駆動されるため、サーバーはGDB Remote Serial Protocolを手動で実装する代わりに、ソースレベルステップ、シンボリックブレークポイント、シンボル対応の式評価を無料で利用できます。ST-LINK_gdbserverはセッションの存続期間中、プローブへのUSBハンドルを保持します。gdbのload(MI: -target-download)によるフラッシュは、サーバーによってSTM32CubeProgrammerに透過的に委任されるため、再フラッシュのためにセッションを終了する必要はありません。スタンドアロンのワンショットフラッシュ(flash_standalone、セッション不要)はSTM32_Programmer_CLIを直接呼び出すため、同じプローブ上の既存セッションと競合します — ツールの説明を参照してください。

Related MCP server: dbgprobe-mcp-server

Setup

npm install
npm run build

STM32CubeCLTがインストールされ、そのbin/ディレクトリにアクセス可能である必要があります — すでにPATH上にあるか(CLTインストーラーがデフォルトでこれを行います)、またはSTMCP_CUBECLT_PATH/ツールごとのオーバーライドを介して。確認するにはnpm run doctorを実行してください。

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)

変数

デフォルト

目的

STMCP_GDBSERVER_PATH / STMCP_PROGRAMMER_CLI_PATH / STMCP_ARM_GDB_PATH

—

バイナリごとのオーバーライド(最優先)

STMCP_CUBECLT_PATH

—

CubeCLTインストールルート; サブパスはSTM32CubeCLT_metadata.sh -jで解決

STMCP_STLINK_SERIAL

—

デフォルトのプローブシリアル(省略時、接続されているプローブが1つだけなら自動選択)

STMCP_DEFAULT_DEVICE

STM32G431CBTx

デフォルトのMCUデバイス文字列

STMCP_DEFAULT_INTERFACE

swd

swdまたはjtag

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がフラッシュアドレスウィンドウを対象にすることを許可します(通常はブロックされています — 代わりにフラッシュツールを使用してください)

STMCP_ALLOWED_FILE_PATHS

(unrestricted)

ELF/binファイル引数用のカンマ区切りの許可リストルート

STMCP_MAX_FILE_SIZE_BYTES

16777216

ファイル引数の最大サイズ

STMCP_FLASH_RANGE_START / STMCP_FLASH_RANGE_END

0x08000000 / 0x08020000

書き込みガード用のフラッシュアドレスウィンドウ(デフォルト: 128KB、STM32G431CB)

Tools

ドメイン

ツール

目的

Probe

list_probes

接続されているST-LINKプローブを一覧表示

Session

debug_connect

gdbserver+gdbを起動し、ELFシンボルを読み込み、接続

Session

debug_disconnect

セッションのクリーンな終了

Session

debug_session_status

セッション情報(1つ、またはすべて)

Flash

flash_standalone

STM32_Programmer_CLIによるワンショットフラッシュ、セッション不要

Flash

flash_load_in_session

開いているセッション内でgdb loadによる再フラッシュ

Execution

debug_run

再開/続行

Execution

debug_halt

割り込み

Execution

debug_reset

リセット(monitor reset [halt])

Execution

debug_step

ステップオーバー/イン/アウト

Breakpoints

breakpoint_set / breakpoint_clear / breakpoint_list

ファイル:行、シンボル、または*addrによる

Memory

memory_read / memory_write

生メモリアクセス(書き込みはガードされています)

Registers

register_read / register_write

名前付きコアレジスタ

Registers

read_fault_registers

ワンコールのCortex-M SCBフォールトレジスタダンプ(CFSR/HFSR/... デコード済み)

Expressions

evaluate_expression

gdb MIによるシンボル対応の評価

Deferred to v2

SVDペリフェラルレジスタツール(memory_read/write + evaluate_expressionはすでにアドレスですべてにアクセス可能)、ライブ/ストリーミングメモリポーリング、プラグインシステム、チップごとのメモリ領域許可リスト、任意のgdb monitorパススルー、およびオプションバイト/RDPツール(ブリック可能、意図的にスコープ外)

RTT

RTT(SEGGER Real Time Transfer — ライブで非停止のコンソール/変数トレース)は、このサーバーでは意図的に実装されていません。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>" }
    }
  }
}

strtt_startをtcp: trueで開始すると、USBデバイスを直接要求する代わりに共有ST-LINKサーバーを介して接続します — これにより、GdbServerProcessが常に-t/--sharedをST-LINK_gdbserverに渡すため、ここで開いているdebug_connectセッションと並行して実行できます。tcp: trueがない場合、strttと開いているデバッグセッションは同じプローブをめぐって競合します。

Hardware verification runbook

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を停止させます。予期しない停止が安全でない方法でアクチュエータ/出力を積極的に駆動しているボードには、事前に確認せずに接続しないでください。

Available Tools

19 tools
breakpoint_clearClear a breakpointA

Deletes a previously set breakpoint by its number.

Inputs: sessionId (required), breakpointNumber (required).

breakpoint_listList breakpointsA

Lists breakpoints currently tracked on a session (those set via breakpoint_set).

Inputs: sessionId (required).

breakpoint_setSet a breakpointB

Sets a breakpoint by file:line (e.g. main.c:42), symbol name (e.g. main), or address (e.g. *0x08000200).

Inputs: location (required), sessionId (required), condition, temporary.

debug_connectConnect a debug sessionA

Starts a debug session: spawns ST-LINK_gdbserver and arm-none-eabi-gdb (MI2), loads ELF symbols, and connects via target extended-remote.

Inputs: elfPath (required), apId, device, serial, +3 more.

debug_disconnectDisconnect a debug sessionA

Cleanly tears down a debug session's gdb and ST-LINK_gdbserver child processes.

Inputs: sessionId (required).

debug_haltHalt executionB

Interrupts the running target.

Inputs: sessionId (required).

debug_resetReset the targetA

Resets the target via ST-LINK_gdbserver's monitor reset command, optionally resuming afterward.

Inputs: sessionId (required), halt.

debug_runResume executionA

Resumes (continues) the target and waits for it to stop again (e.g. a breakpoint), up to a timeout.

Inputs: sessionId (required), waitForStopMs.

debug_session_statusDebug session statusA

Reports the status of one debug session (by id), or lists all active sessions if id is omitted.

Inputs: sessionId.

debug_stepSingle-stepB

Steps the target: 'over' (next line, step over calls), 'into' (step into calls), or 'out' (finish the current function).

Inputs: sessionId (required), mode, waitForStopMs.

evaluate_expressionEvaluate an expressionB

Symbol-aware expression evaluation in the current frame via gdb's -data-evaluate-expression — reads globals/locals by name, struct/array member access, pointer dereference, arithmetic, etc.

Inputs: sessionId (required), expression (required).

flash_load_in_sessionReflash firmware within a debug sessionA

Reflashes the currently loaded ELF via gdb's load (MI: -target-download) inside an already-open debug session. No USB conflict — ST-LINK_gdbserver retains ownership of the probe throughout.

Inputs: sessionId (required), runToMain, resetAfter.

flash_standaloneFlash firmware (standalone)A

One-shot flash via STM32_Programmer_CLI — no debug session required. Fails with DEVICE_BUSY if a debug session is already open on the same probe (it holds exclusive USB access); disconnect first, or use flash_load_in_session instead.

Inputs: file (required), run, reset, serial, +3 more.

list_probesList ST-LINK probesA

Lists connected ST-LINK probes via STM32_Programmer_CLI. Returns an empty list (not an error) if none are attached.

Inputs: no named parameters.

memory_readRead memoryA

Reads raw bytes from target memory at an address or symbol-address expression (e.g. '&my_global').

Inputs: length (required), address (required), sessionId (required).

memory_writeWrite memoryA

Writes raw bytes to target RAM/registers at an address. Blocked for addresses inside the flash window (use flash_standalone / flash_load_in_session for flash) unless STMCP_ALLOW_FLASH_ADDRESS_WRITE is set.

Inputs: address (required), bytesHex (required), sessionId (required).

read_fault_registersRead Cortex-M fault registersA

One-call dump of Cortex-M SCB fault registers (CFSR/HFSR/MMFAR/BFAR/SHCSR/CPUID/ICSR) plus PC/SP/LR, with CFSR/HFSR bits decoded to flag names. Raw evidence only — no root-cause interpretation.

Inputs: sessionId (required).

register_readRead core registersA

Reads named core registers (default: all general-purpose + sp/lr/pc/xpsr) via gdb MI.

Inputs: sessionId (required), registers.

register_writeWrite a core registerB

Writes a value to a named core register via gdb's -gdb-set $<register>=<value>.

Inputs: value (required), register (required), sessionId (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 19 tools

    Disambiguation5/5

    Each tool targets a distinct action: session lifecycle, run control, breakpoints, register/memory access, and flashing are clearly separated. The only similar pair, flash_standalone and flash_load_in_session, is explicitly differentiated by requiring or not requiring an active debug session.

    Naming Consistency4/5

    All tool names are lowercase snake_case and mostly follow a predictable domain-prefixed verb pattern such as breakpoint_set, memory_read, and debug_run. Minor exceptions like debug_session_status and flash_standalone break the strict verb_noun pattern but remain easy to anticipate.

    Tool Count4/5

    19 tools is on the heavier side, but the embedded debug workflow legitimately spans session management, execution control, breakpoints, register/memory inspection, fault diagnosis, and flashing. Each tool has a justifiable role, so the count feels slightly over ideal rather than bloated.

    Completeness4/5

    The toolset covers the full core debug loop: connect/disconnect, run/halt/reset/step, breakpoint management, register and memory access, expression evaluation, fault register dumps, and both standalone and in-session flashing. Missing conveniences like stack backtraces or watchpoints are minor gaps, not workflow-breaking omissions.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      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
      23 PyPI
      11
      MIT
    • A
      license
      Not graded
      quality
      D
      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
      D
      maintenance
      An MCP server that provides comprehensive debugging capabilities for J-Link debuggers, enabling memory, flash, register, and RTT operations through AI assistants.
      43
      MIT