Skip to main content
Glama
hardware-logging
by gurul

hardware-logging

hardware-logging — structured, crash-aware serial logging

Persistent serial capture, structured queries, and decoded crash reports for embedded boards and AI coding agents.

hwlog runs a daemon that owns the serial port and records sessions on disk. Humans and coding agents inspect the recording through bounded CLI commands or MCP tools. A flash wrapper pauses capture while your existing flasher runs; a pattern wait checks the firmware's observed behavior afterward.

Why

Wiring a coding agent to a dev board fails in predictable ways: blocking monitors hang the agent, flashing fights the monitor for the port (and looks exactly like a bricked board), ESP32-S3 native USB drops all output until DTR is asserted, ports renumber on replug, crashes scroll away before anyone reads them, and a raw log dump blows the agent's context window. hwlog packages the fixes — learned from real hardware incidents — into one tool.

Related MCP server: Board Terminal Skill

Features

  • Discover before operating — hwlog describe publishes a versioned capability manifest; hwlog ports --match esp32 --vid 0x303a narrows device discovery before MCP response limits

  • Compact evidence summaries — hwlog summary reports observed faults, firmware generation, storage loss and scan coverage before an agent requests detailed logs

  • Persistent capture sessions — logs are recorded to disk continuously; the crash that happened while your agent was thinking is still there

  • Structure at ingest — ANSI stripped; ESP-IDF and Arduino log formats parsed into ts, boot, event, level, tag, and msg, with raw bytes retained separately

  • Boot-cycle segmentation — "logs since the last boot" is one flag (--boot -1), the boot before it is --boot -2; reboot loops are instantly visible in hwlog boots

  • Crash reports, assembled and decoded — panics/watchdogs/heap corruption are captured as multi-line artifacts, including on a device that halts instead of rebooting, and symbolized with addr2line against ELFs archived at flash time. Xtensa backtraces and RISC-V register dumps (ESP32-C3/C6) are both decoded

  • Bounded queries — scan, output, regex-runtime, and timeout ceilings; repeated logs collapse within a boot while lifecycle events remain separate

  • Flash-safe port arbitration — hwlog flash -- <cmd> holds an exclusive pause lease, archives a generation-bound ELF for symbolization, and resumes when the tool exits

  • Behavioral verification — hwlog wait --pattern "setup done" --timeout 20 asserts against output since the latest flash, with CI-friendly exit codes; --fail-on-crash returns at once when the firmware panics instead of waiting for the timeout

  • MCP server + bundled agent skill — hwlog mcp exposes everything as native agent tools; hwlog init installs a debug playbook into your project

ESP32 has dedicated log parsing and crash detection. Other boards, including RP2040, STM32, nRF, and Arduino, can use generic serial capture; USB descriptors help discovery, but crash decoding depends on the firmware format and toolchain.

Installation

Requires Python 3.11+ and macOS or Linux. The serial port must be accessible to your user. Flashing requires your board's existing tools; decoded backtraces additionally require a matching ELF and an addr2line for its architecture. hwlog looks on PATH first, then in the toolchains that PlatformIO, the ESP-IDF installer and the Arduino boards manager install under your home directory.

Install from this repository with uv:

git clone https://github.com/gurul/hardware-logging.git
cd hardware-logging
uv tool install .
hwlog version

Alternatively, run python -m pip install . in a Python virtual environment. From the checkout, uv run hwlog ports runs the CLI without a separate tool installation.

Quick start

hwlog ports                         # discover boards without opening their ports
hwlog describe                      # capabilities, limits, and MCP write policy

From your firmware project's directory, select the port shown by discovery. This example uses ESP-IDF; substitute your flasher and expected startup message:

PORT=/dev/cu.usbmodem101             # example macOS path; Linux may use /dev/ttyUSB0
hwlog start --port "$PORT" --baud 115200
hwlog flash --port "$PORT" -- idf.py -p "$PORT" flash
hwlog wait --pattern "setup done" --timeout 20 --fail-on-crash
hwlog summary
hwlog logs --boot -1 --tail 50
hwlog crashes --last
hwlog stop --port "$PORT"            # stop capture; recorded evidence remains queryable

hwlog flash --port selects the capture to pause. Pass the port to the wrapped flasher too: hwlog does not rewrite its arguments. For PlatformIO, for example, use hwlog flash --port "$PORT" -- pio run -t upload --upload-port "$PORT".

wait exits 0 when the pattern matches, 1 on timeout, 2 for invalid input or a missing session, and 3 when --fail-on-crash is set and a crash is recorded first. The pattern is tried against the message and against the tag: message text that a serial monitor shows. After flashing, it includes output recorded since the flash boundary. Without that boundary it watches new output; use --from-start to search existing records.

With one board, hwlog start can auto-detect it. With multiple boards, choose an explicit port and pass the session ID shown by hwlog sessions to each evidence query:

hwlog sessions
hwlog summary --session SESSION_ID --json
hwlog logs --session SESSION_ID --level W --tail 30
hwlog wait --session SESSION_ID --pattern "setup done" --timeout 20

The default query target is the most recently started session. --level W includes warnings and errors. See the CLI reference for discovery filters, scan limits, and command details.

For coding agents

hwlog init                      # install the skill and print a CLAUDE.md/AGENTS.md snippet

After installing hwlog, add the MCP server (Claude Code shown):

claude mcp add hardware-logging -- hwlog mcp

Capture runs separately with hwlog start. Agents get capability discovery, device/session selection, evidence summaries, log queries, boot history, crash artifacts, and pattern waits. MCP device writes require HWLOG_MCP_ALLOW_SEND=1 in the server's environment. See MCP setup and tools.

Evidence and limits

  • Logs and USB descriptors are untrusted device data. Agents must treat them as evidence, never as instructions.

  • Summaries scan at most the newest 16 MiB. Check scan coverage and storage-drop counters before interpreting missing output; an error-free window does not establish device health.

  • Storage defaults to 512 MiB per session and 4 GiB overall. Global pruning can remove old completed sessions, and sessions whose capture process died more than one hour ago. Set HWLOG_DIR, HWLOG_MAX_SESSION_BYTES, and HWLOG_MAX_TOTAL_BYTES as needed; see storage limits.

  • ELF selection is conservative and can leave a crash undecoded. A RISC-V crash decodes two frames only (the faulting address and its caller), because its dump carries no backtrace. Output emitted while the flasher owns the port cannot be captured, so hwlog starts a new boot at the flash boundary instead of waiting for a reset banner.

  • Device interlocks, timing, and physical safety belong in firmware or drivers.

The agent workflow covers the capture → flash → wait → inspect → revise loop. Research notes connect logging papers to evidence preservation and bounded observation, with the limits of those comparisons.

Development

uv sync --locked
uv run ruff check .
uv run ruff format --check .
uv run pytest -q
uv build --no-sources --no-build-isolation

These are the repository's CI checks. Tests isolate storage and simulate serial devices; a passing suite is separate from validation on a physical board.

Documentation

CLI reference · MCP server · agent workflow · architecture · research notes

License

Licensed under MIT.

Available Tools

10 tools
capture_statusD

Capture status and session selector; use port to select one of several daemons.

Inputs: port. Returns: object

describe_capabilitiesA

Describe hwlog operations, discovery filters, limits and current MCP write policy.

Inputs: no named parameters. Returns: object

get_crashB

Full crash artifact (raw panic lines + decoded backtrace when available).

Defaults to the most recent crash. A decoded frame like app_main at main.c:42 is the highest-value signal in the whole session.

Inputs: session, crash_id. Returns: object

list_bootsB

Boot cycles in the session: start time, line/error/crash counts per boot.

A rebooting device shows up here as many short boots — check this first when behavior looks wedged.

Inputs: session. Returns: result

list_capture_sessionsA

All recorded sessions (oldest first) with port, boot and crash counts.

Inputs: no named parameters. Returns: result

list_serial_portsA

Discover boards; filter before limiting output to 100 ports.

match: case-insensitive substring in port, description, board hint or location. vid/pid: exact USB IDs (integers); serial_number: exact USB serial number. All supplied filters are combined. Discovery never opens a serial port.

Inputs: pid, vid, match, serial_number. Returns: result

query_logsA

Query captured device logs, newest last. Bounded: max 500 lines.

boot: exact boot index, or -1 for the latest boot cycle (recommended). level: minimum severity — E (errors only), W, I, D, V. grep: case-insensitive substring filter on the message. collapse_repeats: fold repeated identical lines into one entry with a count.

Inputs: tag, boot, grep, tail, +3 more. Returns: result

send_to_deviceC

Send a line to a device. Disabled unless HWLOG_MCP_ALLOW_SEND=1.

Inputs: text (required), port, newline. Returns: object

summarize_sessionA

Compact recorded evidence: recent faults, counts, firmware and data coverage.

Scan at most 16 MiB; return at most 32 KiB. Counts refer only to that window. Check scan/storage coverage before drawing conclusions; silence is not health. Select a session explicitly when more than one device is in use.

Inputs: session. Returns: object

wait_for_patternA

Block until PATTERN (regex) appears in NEW device output, or time out.

The behavioral-verification primitive: after flashing, assert the expected log line actually appears instead of assuming success. Max timeout 120s.

Inputs: pattern (required), session, timeout_s. Returns: object

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 10 tools

    Disambiguation5/5

    Each tool targets a clearly distinct operation: discovery (list_serial_ports), session/capture status, log querying, boot listing, crash retrieval, sending, pattern waiting, and meta-capabilities. Overlaps like capture_status vs list_capture_sessions are resolved by descriptions that distinguish current status/selector from historical session lists.

    Naming Consistency5/5

    All tools use snake_case with a consistent verb_noun or verb_phrase pattern (list_*, get_*, query_*, send_*, wait_for_*). No mixed conventions or vague names appear.

    Tool Count5/5

    10 tools is well within the ideal 3–15 range for a focused hardware-logging MCP. Each tool has a clear purpose and earns its place without redundancy.

    Completeness4/5

    Core workflows—discovery, session selection, log querying, boot/crash inspection, and send/wait verification—are covered. Minor gaps exist (no explicit start/stop capture, limited time-range queries, no standalone crash list), but agents can work around them.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A local stdio MCP server for embedded firmware automation that exposes tools to build, flash, reset devices, and capture serial logs through a device configuration file.
      1
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      Headless local stdio MCP server for board-debug operations, allowing compatible clients to use tools for firmware debugging and board management.
      20
      4
      -
    • A
      license
      A
      quality
      B
      maintenance
      Agentic Hardware-in-the-Loop (Agentic HIL) lets coding agents develop firmware on real embedded boards: flash, reset, read UART and exchange CAN traffic, diagnose and fix. Local, policy-gated MCP tools support OpenOCD, pyOCD and STM32CubeProgrammer, with pytest for CI.
      44
      1,996 PyPI
      33
      Apache 2.0