FastMCP server for serial port access via Model Context Protocol: - 10 tools: list, open, close, read, write, configure, flush, status - 4 dynamic resources: ports list, data, status, raw hex - USB device filtering (hides phantom ttyS ports by default) - Full pyserial support with configurable baudrate/parity/etc
75 lines
1.9 KiB
Markdown
75 lines
1.9 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
# With uvx (recommended)
|
|
uvx mcserial
|
|
|
|
# Or install directly
|
|
uv pip install mcserial
|
|
```
|
|
|
|
## Usage with Claude Code
|
|
|
|
```bash
|
|
# 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
|