Metadata-Version: 2.4
Name: mcp-rs485
Version: 0.1.0
Summary: MCP server that exposes RS485 bus connectivity
Project-URL: Homepage, https://github.com/daedalus/mcp-rs485
Project-URL: Repository, https://github.com/daedalus/mcp-rs485
Project-URL: Issues, https://github.com/daedalus/mcp-rs485/issues
Author-email: Dario Clavijo <clavijodario@gmail.com>
License: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: pyserial>=3.0
Provides-Extra: all
Requires-Dist: hatch; extra == 'all'
Requires-Dist: hypothesis; extra == 'all'
Requires-Dist: mypy; extra == 'all'
Requires-Dist: pytest; extra == 'all'
Requires-Dist: pytest-asyncio; extra == 'all'
Requires-Dist: pytest-cov; extra == 'all'
Requires-Dist: pytest-mock; extra == 'all'
Requires-Dist: ruff; extra == 'all'
Provides-Extra: dev
Requires-Dist: hatch; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: lint
Requires-Dist: mypy; extra == 'lint'
Requires-Dist: ruff; extra == 'lint'
Provides-Extra: mcp
Requires-Dist: fastmcp; extra == 'mcp'
Provides-Extra: test
Requires-Dist: hypothesis; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-asyncio; extra == 'test'
Requires-Dist: pytest-cov; extra == 'test'
Requires-Dist: pytest-mock; extra == 'test'
Description-Content-Type: text/markdown

# mcp-rs485

> MCP server that exposes RS485 bus connectivity for reading and writing serial data.

mcp-name: io.github.daedalus/mcp-rs485

[![PyPI](https://img.shields.io/pypi/v/mcp-rs485.svg)](https://pypi.org/project/mcp-rs485/)
[![Python](https://img.shields.io/pypi/pyversions/mcp-rs485.svg)](https://pypi.org/project/mcp-rs485/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

## Install

```bash
pip install mcp-rs485
```

## Configuration

```json
{
  "mcpServers": {
    "mcp-rs485": {
      "command": "mcp-rs485",
      "env": {},
      "name": "io.github.daedalus/mcp-rs485"
    }
  }
}
```

## Usage

This MCP server exposes RS485 serial bus connectivity through the Model Context Protocol. It allows AI assistants to interact with RS485 devices.

### Tools

- `list_ports`: Lists all available serial ports on the system
- `connect_rs485`: Opens a connection to an RS485 device
- `disconnect_rs485`: Closes an RS485 connection
- `read_rs485`: Reads data from an open RS485 connection
- `write_rs485`: Writes data to an RS485 connection
- `get_connection_status`: Gets the status of an RS485 connection

### Example

```python
from mcp_rs485.server import connect_rs485, write_rs485, read_rs485

# Connect to a device
conn_id = connect_rs485("/dev/ttyUSB0", baudrate=9600)

# Write data (Modbus RTU example)
write_rs485(conn_id, "01 03 00 00 00 0A")

# Read response
response = read_rs485(conn_id)

# Cleanup
disconnect_rs485(conn_id)
```

## Development

```bash
git clone https://github.com/daedalus/mcp-rs485.git
cd mcp-rs485
pip install -e ".[test]"

# run tests
pytest

# format
ruff format src/ tests/

# lint
ruff check src/ tests/

# type check
mypy src/
```

## API

### list_ports()

Lists all available serial ports.

**Returns:** List of port dictionaries with `port`, `description`, and `hwid`.

### connect_rs485(port, baudrate=9600, parity="N", stopbits=1, bytesize=8, timeout=1.0)

Opens a connection to an RS485 device.

**Parameters:**
- `port`: Serial port path (e.g., "/dev/ttyUSB0")
- `baudrate`: Communication speed (default: 9600)
- `parity`: "N" (none), "E" (even), "O" (odd)
- `stopbits`: Number of stop bits
- `bytesize`: Data bits per frame
- `timeout`: Read timeout in seconds

**Returns:** Connection ID string.

### read_rs485(connection_id, length=1024)

Reads data from an open RS485 connection.

**Parameters:**
- `connection_id`: Connection ID from connect_rs485
- `length`: Maximum bytes to read

**Returns:** Hex string of received data.

### write_rs485(connection_id, data)

Writes data to an RS485 connection.

**Parameters:**
- `connection_id`: Connection ID from connect_rs485
- `data`: Hex string (e.g., "01 03 00 00 00 0A")

**Returns:** Number of bytes written.

### get_connection_status(connection_id)

Gets connection status and statistics.

**Returns:** Dictionary with connection state and statistics.
