An MCP (Model Context Protocol) server that provides Modbus client and server (slave) functionality, enabling LLM applications to interact with Modbus RTU and TCP devices through a standardized interface. This server acts as a bridge between AI assistants and industrial automation systems, PLCs, sensors, and other Modbus-enabled devices.
Features
Modbus MCP server that exposes Modbus master functionality to be used with LLMs
Modbus RTU and TCP client support - Connect to serial and network Modbus devices
Modbus RTU and TCP server (slave) support - Run simulated Modbus devices that respond to client requests
Serial port discovery and management - Automatically detect available serial ports
Comprehensive read/write operations - Support for coils, discrete inputs, holding registers, and input registers
Server-side datastore management - Populate and read all 4 register types on server instances
Once configured, you can use Modbus functionality in VS Code:
Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
Type "MCP: " to see available MCP commands
Use the AI assistant with Modbus capabilities
Example conversation:
You: "List available serial ports on this system"
AI: [Uses list_serial_ports tool to show COM1, COM3, etc.]
You: "Connect to Modbus RTU device on COM3 with baud rate 9600 and slave ID 1"
AI: [Uses create_rtu_client tool to establish connection]
You: "Read holding registers 40001 to 40010 from the connected device"
AI: [Uses read_holding_registers tool to get values]
Kiro IDE
1. Configure MCP Server
In Kiro, add the Modbus MCP server to your MCP configuration. Create or edit .kiro/settings/mcp.json:
After configuration, restart Kiro or reconnect the MCP server. You can then:
Use natural language to interact with Modbus devices
Ask Kiro to discover serial ports, create connections, and read/write data
Leverage Kiro's context awareness for complex automation tasks
Example workflow:
You: "I need to monitor temperature sensors connected via Modbus RTU on COM1"
Kiro: [Discovers COM1, creates RTU client, sets up monitoring]
You: "Read the temperature values every 30 seconds and alert me if any exceed 75°C"
Kiro: [Sets up periodic reading with alerting logic]
Available MCP Tools
The server exposes the following tools through the MCP protocol:
Client Connection Management
list_serial_ports - Discover available serial ports
Note: Server-side write operations for discrete inputs and input registers allow the server owner to populate data that is normally read-only from the client perspective.
Configuration
Configuration File
Create a JSON configuration file for advanced settings:
# Through MCP, you can ask the AI assistant:
"Connect to the temperature controller on COM3 at 9600 baud, slave ID 1,
then read holding registers 40001-40004 to get the current temperatures
from all four zones."
Example 2: PLC Control System
# Control a PLC via Modbus TCP:
"Connect to PLC at 192.168.1.100 port 502, slave ID 1.
Read coils 1-16 to check current output states,
then set coil 5 to ON to start the conveyor motor."
Example 3: Multi-Device Monitoring
# Monitor multiple devices:
"List all available serial ports, then connect to devices on COM1 and COM3.
Read input registers from both devices every 10 seconds and compare the values."
Example 4: Simulating a Modbus Device
# Start a Modbus TCP server to simulate a temperature sensor:
"Create a TCP server on port 5020 with slave ID 1.
Set holding registers 0-3 to values [2500, 2650, 2700, 2550]
representing temperatures in tenths of degrees.
Then connect a client to verify the values can be read."
Example 5: Device Testing and Bridging
# Use server + client together for testing:
"Start a TCP server on 127.0.0.1:5020 with slave ID 1,
populate its input registers 0-9 with test sensor data,
then create a TCP client to connect to it and verify all values are correct."
Troubleshooting
Installation Issues
"No module named pip" Error
This is a common Windows issue. Try these solutions in order:
# Generate and use test configuration
modbus-mcp-server --generate-config test-config.json
modbus-mcp-server --config test-config.json --show-config
Development
Testing Status
✅ All MCP tools tested and verified (2026-02-12)
Client Tools
Tool
Status
Notes
list_serial_ports
✅ Pass
Successfully lists available serial ports
create_tcp_client
✅ Pass
Connects to TCP server at 127.0.0.1:5020
create_rtu_client
✅ Pass
Creates RTU client connections
read_holding_registers
✅ Pass
Read and verified values [100, 200, 300, 400, 500]
write_holding_registers
✅ Pass
Write operation confirmed with read-back
read_coils
✅ Pass
Successfully reads coil states
write_coils
✅ Pass
Write operation confirmed with read-back
read_discrete_inputs
✅ Pass
Successfully reads discrete input states
read_input_registers
✅ Pass
Successfully reads input register values
list_clients
✅ Pass
Lists active connections with details
close_client
✅ Pass
Properly closes and cleans up connections
Server (Slave) Tools
Tool
Status
Notes
create_tcp_server
✅ Pass
Starts TCP slave, works from within MCP event loop
create_rtu_server
✅ Pass
Starts RTU slave on serial port
stop_server
✅ Pass
Stops server and releases TCP/serial port
list_servers
✅ Pass
Lists active servers with connection details
server_read_coils
✅ Pass
Reads coil values from server datastore
server_write_coils
✅ Pass
Writes coils, verified via client read-back
server_read_discrete_inputs
✅ Pass
Reads discrete inputs from datastore
server_write_discrete_inputs
✅ Pass
Populates discrete inputs, verified via client
server_read_holding_registers
✅ Pass
Reads holding registers from datastore
server_write_holding_registers
✅ Pass
Writes registers, verified via client read-back
server_read_input_registers
✅ Pass
Reads input registers from datastore
server_write_input_registers
✅ Pass
Populates input registers, verified via client
End-to-End Tests
✅ Server create → populate datastore → client connect → client read → values match
✅ Server stop → port freed → new server on same port succeeds
✅ Server creation from inside running async event loop (MCP framework scenario)
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=src/modbus_mcp_server
# Run property-based tests with more examples
pytest -v tests/ -k "property"
Code Quality
# Format code
black src tests
isort src tests
# Type checking
mypy src
# Linting
flake8 src tests
Contributing
Fork the repository
Create a feature branch
Add tests for new functionality
Ensure all tests pass
Submit a pull request
Requirements
Python: 3.8 or higher
Dependencies:
fastMCP >= 0.2.0
pymodbus == 3.11.4
pyserial == 3.5
Operating System: Windows, macOS, Linux
Hardware: Serial ports (for RTU) or network access (for TCP)
Version History
v0.3.0 (2026-02-12)
Modbus Server (Slave) Support - 12 new MCP tools for running Modbus TCP and RTU servers
Create, stop, and list server instances
Read/write all 4 register types (coils, discrete inputs, holding registers, input registers) on server datastores
Server-side populate for read-only register types (discrete inputs, input registers)
Async-safe architecture - Each server runs in its own thread with a dedicated event loop, compatible with the MCP framework's async context
Port conflict tracking - Prevents binding the same TCP or serial port twice
End-to-end verified - Server + client communication tested for all register types
v0.2.0 (2026-02-05)
Updated to pymodbus 3.11.4 - Full compatibility with latest pymodbus release
API Changes:
Changed slave= parameter to device_id= in all Modbus operations
Updated method signatures to use keyword-only arguments for count parameter