serial-mcp
# ๐ serial-mcp
MCP server for serial port communication. Provides tools to open, read, write, and manage serial ports through the Model Context Protocol.
*๐ค Written by and for AI.*
## โจ Features
- ๐ List available serial ports on the system
- โ๏ธ Open ports with configurable baud rate, parity, stop bits, and flow control
- ๐ Read data by byte count, terminator character, or duration
- โ๏ธ Write string or hex data
- ๐ฅ Send BREAK signals
- ๐ Monitor port status and control line states
## ๐ฆ Prerequisites
- Python 3.10+
- [uv](https://docs.astral.sh/uv/getting-started/installation/) package manager
## ๐ Installation
### Via PyPI
```bash
uvx serial-mcp@latest
```
### Local Clone
```bash
git clone https://github.com/davidalo/serial-mcp.git
cd serial-mcp
uvx --from "$(pwd)" serial-mcp
```
## ๐ Integration
### Via PyPI
```bash
# Claude Code
claude mcp add serial -- uvx serial-mcp@latest
# Codex CLI
codex mcp add serial -- uvx serial-mcp@latest
```
### Local Clone
```bash
git clone https://github.com/davidalo/serial-mcp.git
cd serial-mcp
# Claude Code
claude mcp add serial -- uvx --from "$(pwd)" serial-mcp
# Codex CLI
codex mcp add serial -- uvx --from "$(pwd)" serial-mcp
```
## ๐ ๏ธ Tools
| Tool | Description |
|------|-------------|
| `list_ports` | List available system serial ports |
| `open_port` | Open a serial port with configuration (baud rate, parity, stop bits, etc.) |
| `close_port` | Close an open port |
| `write_data` | Write string or hex data to a port |
| `read_bytes` | Read N bytes with timeout |
| `read_until` | Read until a terminator character |
| `read_for_duration` | Read continuously for N seconds |
| `send_break` | Send a BREAK signal |
| `get_port_status` | Get port status and control line states |
| `list_open_ports` | List all currently managed ports |
## ๐งช Testing with Virtual Ports
Use `socat` to create virtual serial port pairs for testing:
```bash
# Create virtual port pair
socat -d -d pty,raw,echo=0,link=/tmp/ttyV0 pty,raw,echo=0,link=/tmp/ttyV1
```
Then open `/tmp/ttyV0` with the MCP server and `/tmp/ttyV1` with another terminal program to test communication.
## ๐ License
MIT
TDQS
Scored across 10 tools
Each tool has a clearly distinct purpose. The three read functions (read_bytes, read_for_duration, read_until) are differentiated by reading mode, and all other tools serve unique roles in port management. No overlap.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., close_port, list_open_ports, send_break). The naming is predictable and easy to interpret.
10 tools is well-scoped for a serial port management server. The set covers opening, closing, reading (three variants), writing, status, port listing, and special signals without being excessive.
The tool set covers core serial operations (open/close, read/write, status, break signal). Minor gaps exist, such as buffer flushing or control line manipulation, but these are not critical for typical use.