Ryan Malloy e8a6197b8c Address code review findings for file transfer protocols
Critical fixes:
- Add max_transfer_size (100MB default) to XMODEM receive
- Validate ZMODEM position values with optional max_valid bound

High priority:
- Extract shared utils to _utils.py (sanitize_filename, open_file_atomic)
- Document XMODEM padding behavior (protocol limitation)
- Add filesize bounds checking in YMODEM (clamp to 10GB)
- Increase ZMODEM subpacket limit from 8KB to 32KB

Medium priority:
- Add timeout parameter to YMODEM/ZMODEM send/receive methods
- Narrow exception handling (SerialException, OSError, ValueError)
- Make ZMODEM cancel more robust (3 retries with delays)
- Add length validation in _verify_block to prevent IndexError
2026-01-28 19:59:22 -07:00

MCP Serial Server

FastMCP server for serial port access via Model Context Protocol.

Features

  • Tools for serial port control (open, close, write, configure)
  • Dynamic Resources for reading data (serial://{port}/data)
  • Full pyserial support (baudrate, parity, stop bits, etc.)
  • Multiple concurrent port connections
  • Raw byte and text modes

Installation

# With uvx (recommended)
uvx mcserial

# Or install directly
uv pip install mcserial

Usage with Claude Code

# Add to Claude Code
claude mcp add mcserial "uvx mcserial"

Tools

Tool Description
list_serial_ports Discover available serial ports
open_serial_port Open a connection with config
close_serial_port Close a connection
write_serial Send text data
write_serial_bytes Send raw bytes
read_serial Read available data
read_serial_line Read until newline
configure_serial Change port settings
flush_serial Clear buffers
get_connection_status List open connections

Resources

URI Description
serial://ports List available ports
serial://{port}/data Read data from open port
serial://{port}/status Port configuration info
serial://{port}/raw Read as hex dump

Environment Variables

Variable Default Description
MCSERIAL_DEFAULT_BAUDRATE 9600 Default baud rate
MCSERIAL_DEFAULT_TIMEOUT 1.0 Read timeout (seconds)
MCSERIAL_MAX_CONNECTIONS 10 Max concurrent ports

Example Workflow

1. list_serial_ports → find /dev/ttyUSB0
2. open_serial_port(port="/dev/ttyUSB0", baudrate=115200)
3. write_serial(port="/dev/ttyUSB0", data="AT\r\n")
4. Read resource: serial:///dev/ttyUSB0/data
5. close_serial_port(port="/dev/ttyUSB0")

License

MIT

Description
MCP server for serial port communication — RS-232, RS-485, and file transfers
Readme 232 KiB
Languages
Python 100%