J-Link MCP

v0.8.0
io.github.Klievan/jlink-mcp Checked 5 hours ago Published 1 month ago

Debug embedded firmware on real hardware: J-Link probes, Cortex-M faults, RTT logs, GDB.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

list_devices

Scan for connected PROBES — the debuggers plugged into this machine, not target chips. Despite the name it does not list target devices; use search_devices for those. Shows probe serial numbers and whether one is reachable.

check_setup

Check that everything needed to debug is in place: the probe software, a connected probe, a target device name, and the optional files that make output readable. Run this first when anything fails, or when starting on a machine for the first time.

set_svd_path

Point the server at a CMSIS-SVD file for the target at runtime, so peripheral reads come back with named fields and decoded values instead of raw hex. Mirrors set_device — you do not have to restart with SVD_PATH set.

ParameterTypeDescription
path *stringPath to a .svd or .svd.gz file for this exact part

set_rtt_address

Tell the server where the firmware's RTT control block is (its _SEGGER_RTT symbol), at runtime. Without it RTT cannot be recovered after a reset or flash, and a stopped stream is indistinguishable from a quiet device. Mirrors set_device.

ParameterTypeDescription
address *stringHex address of _SEGGER_RTT, e.g. '0x20002050'

search_devices

Search the device names this J-Link installation accepts, by part number, manufacturer, or core. Use this before set_device instead of guessing a part number — the name must match exactly, and a wrong one fails in a way that looks like broken hardware.

ParameterTypeDescription
query *stringSubstring of a part number, manufacturer, or core. E.g. 'stm32f407', 'nrf528', 'nordic', 'cortex-m33'
limitnumberMaximum results (default 40)

set_device

Set the target device name at runtime. Required before any debugging commands will work. The name must match J-Link's exactly — use search_devices to find it rather than guessing a part number. Examples: 'nRF52840_XXAA', 'nRF5340_xxAA_APP', 'STM32F407VG', 'STM32L476RG'.

ParameterTypeDescription
device *stringTarget device name (e.g., 'nRF52840_XXAA', 'STM32F407VG')

set_serial_number

Set the debug probe serial number at runtime. Required when multiple probes are connected to select which one to communicate with. Run list_devices to see connected serial numbers.

ParameterTypeDescription
serialNumber *stringProbe serial number from list_devices (e.g. '776287991'), or empty string to clear

start_debug_session

One-call setup: starts GDB server via SEGGER J-Link, connects RTT (if supported), waits for initial output. This is the recommended first tool to call. If no device is configured, use list_devices and set_device first.

snapshot

Capture complete device state: CPU registers (compact), fault status, recent RTT output, and stack dump.

ParameterTypeDescription
rttLinesnumberRTT lines to include (default 30)

diagnose_crash

Auto-read and decode ARM Cortex-M fault registers (CFSR, HFSR, MMFAR, BFAR), exception stack frame, and recent errors.

device_info

Halt the target and read its registers via SEGGER J-Link. Returns the probe name and a compact register summary. Leaves the target HALTED — call resume when you are done.

halt

Halt the target CPU

resume

Resume the target CPU

reset

Reset the target device. Halting leaves the core stopped at the reset vector, which is where you want it before flashing, or to watch startup run.

ParameterTypeDescription
haltbooleanHalt at the reset vector after reset (default: false)
strategynumberJ-Link reset type. Omit to let J-Link pick the right one for the device, which is what SEGGER recommends and is almost always correct. 0 = normal; 1 = core only, via VECTRESET, leaving peripherals run…

step

Step one CPU instruction

read_memory

Read memory from the target. Returns clean hex dump.

ParameterTypeDescription
address *stringHex address (e.g., '0x20000000')
length *numberBytes to read (max 4096)

write_memory

Write a 32-bit value to memory

ParameterTypeDescription
address *stringHex address
value *stringHex value (e.g., '0xDEADBEEF')

read_registers

Read all CPU registers (compact format, FP only if non-zero).

read_register

Read a specific CPU register by name

ParameterTypeDescription
register *stringRegister name (e.g., 'PC', 'SP', 'R0')

flash

Flash firmware to the target device

ParameterTypeDescription
filePath *stringPath to firmware file (.hex, .bin, .elf)
baseAddressstringBase address for .bin files (hex)

erase

Erase target flash memory

list_peripherals

List the target's peripherals and base addresses, from its CMSIS-SVD description. Requires an SVD file to be configured.

ParameterTypeDescription
filterstringCase-insensitive substring, e.g. 'uart' or 'timer'

read_peripheral

Read every register of a peripheral from the target and decode each one's bit fields by name. This is read_memory plus the meaning of what was read.

ParameterTypeDescription
peripheral *stringPeripheral name, e.g. 'FICR', 'UARTE0'
registersarrayOnly these registers (default: all readable ones)

decode_register

Decode a value into named bit fields using the target's SVD. Reads from the device unless a value is supplied — useful for interpreting a number you already have.

ParameterTypeDescription
peripheral *stringPeripheral name, e.g. 'UARTE0'
register *stringRegister name, e.g. 'ENABLE' or 'INFO.PART'
valuestringHex value to decode instead of reading the device

set_breakpoint

Set a hardware breakpoint

ParameterTypeDescription
address *stringHex address

clear_breakpoints

Clear all breakpoints, including any left armed in the debug hardware by an earlier session

gdb_server_start

Start SEGGER J-Link GDB server

gdb_server_stop

Stop SEGGER J-Link GDB server and disconnect RTT

gdb_server_status

Get GDB server, RTT, and telnet proxy status

gdb_connect

Connect a GDB client to the running GDB server. Enables source-level debugging: backtraces, variable inspection, conditional breakpoints, stepping by source line. Optionally load an ELF file for symbol info.

ParameterTypeDescription
elfFilestringPath to .elf file with debug symbols (enables source-level debugging)
hoststringGDB server host (default: localhost)
portnumberGDB server port (default: 2331)

gdb_command

Send any GDB command and get the response. For execution commands (continue, step, next, finish, until), blocks until the target stops or times out. If the target doesn't stop, use gdb_wait to poll. Examples: 'bt' (backtrace), 'info threads', 'print myVar', 'break main', 'continue', 'next', 'step', 'finish', 'info registers', 'x/10xw 0x20000000'

ParameterTypeDescription
command *stringGDB command to execute
timeoutnumberTimeout in ms for run commands (default 15000)

gdb_wait

Poll for target stop after a continue/step that timed out. Returns the stop reason (breakpoint hit, signal, finished stepping, etc.) when the target halts.

ParameterTypeDescription
timeoutnumberHow long to wait in ms (default 30000)

gdb_load

Load an ELF file into GDB. By default loads symbols only (for source-level debugging: backtraces with file:line, variable names). Set flash=true to also program it onto the target.

ParameterTypeDescription
elfFile *stringPath to .elf file with debug symbols
flashbooleanAlso flash the ELF to the target (default: false, symbols only)

gdb_backtrace

Get a stack backtrace. With debug symbols loaded, shows function names, file paths, and line numbers.

ParameterTypeDescription
fullbooleanInclude local variables in each frame (default false)

gdb_disconnect

Disconnect the GDB client (does not stop the GDB server)

rtt_connect

Connect to RTT

rtt_disconnect

Disconnect from RTT

rtt_read

Read RTT log lines (clean, parsed Zephyr format). Non-destructive — reading does not consume the buffer. Returns the NEWEST lines by default; oldest:true returns the start of the buffer. Note the buffer spans reflashes: its oldest lines may be from firmware you have since replaced. rtt_clear drops them.

ParameterTypeDescription
countnumberHow many lines (default 50)
oldestbooleanReturn the OLDEST lines instead of the newest — use this to see boot output

rtt_send

Send data to device via RTT down-channel

ParameterTypeDescription
data *stringData to send

rtt_status

Read SEGGER's RTT control block on the target: is it initialised, how much has the firmware written, and how much has the probe collected. Use this when RTT is silent — it separates a quiet device from a probe that stopped collecting, which look identical from rtt_read.

ParameterTypeDescription
addressstringAddress of the control block (your _SEGGER_RTT symbol), e.g. '0x20002050'. Defaults to JLINK_RTT_ADDR if that is set.

rtt_clear

Clear RTT buffer

telnet_proxy_start

Start a TCP relay that re-serves the RTT stream on another port, so an external decoder (Trice, Pigweed, or your own) can consume it alongside this server. It relays bytes; it does not decode them.

telnet_proxy_stop

Stop telnet proxy

telnet_proxy_status

Get telnet proxy status

telnet_proxy_read

Read raw data from telnet proxy buffer

ParameterTypeDescription
linesnumberLines (default 100)

probe_command

Execute raw SEGGER J-Link commands

ParameterTypeDescription
commands *arrayCommands to execute

get_config

Get current probe and server configuration