Skip to content

mcserial

Serial ports meet the Model Context Protocol. Discover, configure, read, write, and transfer files -- RS-232, RS-422, RS-485, and 7 URL schemes, all callable as MCP tools.

RS-232, RS-422, and RS-485

Full RS-232 modem line control — RTS, DTR, CTS, DSR, break signals, device reset pulses. RS-422 mode for full-duplex differential links over long distances. RS-485 mode for half-duplex bus communication with automatic TX/RX direction, device scanning, and Modbus transactions.

File Transfers

Send and receive files over serial using XMODEM (128B blocks), XMODEM-1K, YMODEM (batch mode), or ZMODEM (streaming with auto-resume). Batch transfers supported for YMODEM and ZMODEM.

Network and Virtual Ports

Connect to serial-over-ethernet bridges via socket://, configure remote ports with rfc2217://, test without hardware on loop://, or debug traffic with spy://. Seven URL schemes total.

Baud Rate Detection

Omit the baud rate when opening a port and mcserial will detect it automatically by analyzing data patterns, sync bytes, and byte distributions. Returns a confidence score and ranked candidates.

Install mcserial and register it with your MCP client:

Terminal window
# Add to Claude Code (one-time setup)
claude mcp add mcserial -- uvx mcserial

Then ask your assistant to work with serial ports. It calls the tools behind the scenes:

list_serial_ports() # find available ports
open_serial_port(port="loop://", baudrate=9600) # open (loop:// = no hardware needed)
write_serial(port="loop://", data="hello\n") # send data
read_serial(port="loop://") # read response
close_serial_port(port="loop://") # release the port

You interact in natural language — “list my serial ports,” “open the loopback port at 9600 baud,” “send hello.” See the Getting Started tutorial for the full walkthrough with example responses.

In addition to local device paths (/dev/ttyUSB0, COM3), open_serial_port accepts these URL schemes:

SchemeDescriptionExample
loop://In-memory loopback — writes echo back as readsloop://
socket://Raw TCP socket for serial-to-ethernet bridgessocket://192.168.1.100:4001
rfc2217://Telnet COM Port Control with remote baud/flow configrfc2217://192.168.1.100:2217
spy://Debug wrapper that logs all traffic to stderrspy:///dev/ttyUSB0
hwgrep://Open first port matching a hardware patternhwgrep://FTDI
cp2110://Silicon Labs HID-to-UART (requires [cp2110] extra)cp2110://
alt://Alternate port backendalt:///dev/ttyUSB0

mcserial is a FastMCP server wrapping pyserial into organized tool groups:

  • Common tools (18) — port discovery, open/close, read/write, configuration, baud detection
  • RS-232 tools (5) — modem line control, break signals, reset pulses
  • RS-422 tools (1) — hardware capability detection for differential links
  • RS-485 tools (4) — bus configuration, transactions, address scanning
  • File transfer tools (3) — X/Y/ZMODEM send, receive, batch send

Ports open in RS-232 mode by default. Use set_port_mode() or the mode parameter on open_serial_port() to switch to RS-422 for differential links or RS-485 for multi-drop buses. Common tools work in all three modes.