Skip to main content
Glama

mcp-serial

ci

An MCP server that lets Claude, Cursor, or any MCP client work with your microcontroller the way you do at a serial console: list ports, open a session, send commands, read and filter the output, and flash firmware to STM32 or ESP32 boards. Flashing is gated behind an explicit confirm=true and an allow-listed firmware directory, so the assistant can't overwrite a board by accident.

you:    "Flash build/app.bin to the Nucleo, then tell me if the sensor init logs any errors."
claude: flash_stm32(firmware_path="build/app.bin", confirm=true)      -> flashed, reset
        open_port("/dev/cu.usbmodem1103", 115200)
        read_lines(port=..., grep="error|fail", wait_seconds=5)        -> 0 matches
        "Flashed and reset. 1,214 lines in 5 s, no errors; IMU and BMP280 both report OK."

Install

uv tool install mcp-serial          # or: pipx install mcp-serial

Claude Code:

claude mcp add mcp-serial -e MCP_SERIAL_ALLOWED_DIR=$PWD -- mcp-serial

Claude Desktop / other clients (claude_desktop_config.json):

{
  "mcpServers": {
    "mcp-serial": {
      "command": "mcp-serial",
      "env": { "MCP_SERIAL_ALLOWED_DIR": "/path/to/your/firmware/project" }
    }
  }
}

Flashing uses whatever you already have installed: st-flash/st-info (stlink) for STM32, esptool for ESP32.

Related MCP server: serial-mcp

Tools

Tool

What it does

list_ports()

Serial ports with description, hwid, VID/PID, and whether a session is open

open_port(port, baud=115200)

Open a port (or a pyserial URL like loop://) and capture lines in the background

close_port(port)

Stop capturing and release the port

write_line(port, text)

Send a command to the firmware's CLI

read_lines(port, max_lines, after_seq, grep, wait_seconds)

Page through captured output with sequence numbers, a regex filter, and an optional short wait for new data

clear_buffer(port)

Drop the capture buffer

flash_stm32(firmware_path, address="0x08000000", confirm)

st-flash --reset write

flash_esp32(firmware_path, port, address="0x10000", chip="auto", baud, confirm)

esptool write_flash; closes the port session first

reset_stm32()

st-flash reset

probe_stlink()

st-info --probe

Example session

mcp-serial example session over loop://

examples/session.py drives the server as a real MCP client over stdio, using pyserial's loop:// so it runs without hardware:

tools: list_ports, open_port, close_port, write_line, read_lines, clear_buffer, flash_stm32, flash_esp32, reset_stm32, probe_stlink

> open_port            {"port": "loop://", "baud": 115200, "already_open": false}
> write_line           {"port": "loop://", "bytes_written": 7}          # "status"
> write_line           {"port": "loop://", "bytes_written": 22}         # "ERR: imu init timeout"
> read_lines (grep=ERR)
  {"port": "loop://", "last_seq": 2, "count": 1,
   "lines": [{"seq": 2, "t": 1792127056.6, "text": "ERR: imu init timeout"}]}
> flash_stm32 without confirm
  {"flashed": false, "reason": "set confirm=true to flash; this overwrites the firmware on the board"}
> close_port           {"port": "loop://", "closed": true, "lines_captured": 2}

Safety model

  • Flash tools refuse unless confirm=true is passed, so the client has to state the intent explicitly.

  • Firmware paths must resolve inside MCP_SERIAL_ALLOWED_DIR (default: the server's working directory).

  • External tools run with argument lists, never through a shell; addresses and chip names are validated.

  • Output is captured in a bounded ring buffer (MCP_SERIAL_MAX_LINES, default 10,000) so a chatty board can't exhaust memory.

Environment

Variable

Default

Meaning

MCP_SERIAL_ALLOWED_DIR

cwd

Directory firmware files must live under

MCP_SERIAL_BAUD

115200

Default baud for open_port

MCP_SERIAL_MAX_LINES

10000

Capture buffer size per port

Development

uv venv && uv pip install -e ".[dev]" && pytest -q

The tests use pyserial's loop:// loopback, so they run without hardware.

License

MIT © Fady Youssef

Available Tools

10 tools
clear_bufferB

Drop all captured lines for a port; sequence numbers keep increasing.

Inputs: port (required). Returns: object

close_portA

Close a port opened with open_port and stop capturing.

Inputs: port (required). Returns: object

flash_esp32A

Flash a .bin to an ESP32-family chip with esptool; closes any open session on the port first. Requires confirm=true.

Inputs: port (required), firmware_path (required), baud, chip, +2 more. Returns: object

flash_stm32A

Flash a .bin to an STM32 over ST-Link with st-flash, then reset the target. Requires confirm=true.

Inputs: firmware_path (required), address, confirm. Returns: object

list_portsA

List serial ports with description, hardware id, VID/PID, and whether this server has them open.

Inputs: no named parameters. Returns: result

open_portB

Open a serial port (or a pyserial URL such as loop://) and start capturing lines in the background.

Inputs: port (required), baud. Returns: object

read_linesB

Return captured lines (oldest first, newest last) with sequence numbers.

Use after_seq to fetch only output newer than your last read, grep for a regex filter (e.g. "error|warn"), and wait_seconds to block briefly for fresh output after a command.

Inputs: port (required), grep, after_seq, max_lines, +1 more. Returns: object

reset_stm32B

Reset the connected STM32 target through ST-Link (st-flash reset).

Inputs: no named parameters. Returns: object

write_lineB

Send text plus a newline to an open port, e.g. a command for the firmware's CLI.

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

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 10 tools

    Disambiguation4/5

    Each tool maps to a distinct resource+action: port discovery (list_ports), ST-Link probing (probe_stlink), session control (open/close_port), I/O (write_line/read_lines/clear_buffer), and flashing/reset. The only minor overlap is reset_stm32 versus flash_stm32, which also resets the target, but descriptions keep them separable.

    Naming Consistency4/5

    All names are snake_case with a leading verb (list_ports, open_port, read_lines, flash_esp32, reset_stm32), a consistent verb_noun pattern. The nouns shift between resources (port, buffer) and platform targets (stlink, stm32, esp32), which is a slight deviation but still predictable.

    Tool Count5/5

    Ten tools is well within the ideal 3-15 range and each earns its place: discovery, session lifecycle, textual I/O, buffer management, and per-platform flashing/reset. No redundant or filler tools.

    Completeness4/5

    The surface covers the full serial workflow (list, open, read, write, clear, close) plus ST-Link/STM32/ESP32 flashing and STM32 probing/reset. Minor asymmetry: there is a flash_esp32 and reset_stm32 but no reset_esp32, and no way to send bytes without a newline.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      MCP server for serial ports — non-blocking reads, DTR/RTS, streaming subscriptions, port allowlist.
      21
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      MCP server for serial port communication. Provides tools to open, read, write, and manage serial ports through the Model Context Protocol.
      10
      -
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI agents to control serial port devices (modems, instruments, embedded boards) via MCP tools for listing ports, connecting, and sending/receiving commands.
      3
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables humans and AI agents to collaboratively control serial ports via MCP tools or Web UI, with real-time data sharing across all participants.
      MIT