Uses environment variables specified in a .env file for configuration of Modbus connection parameters.
Modbus MCP Server
An MCP server that standardizes and contextualizes Modbus data, enabling seamless integration of AI agents with industrial IoT systems.
Features
Modbus Tools:
Read/write holding registers (
read_register
,write_register
).Read/write coils (
read_coils
,write_coil
).Read input registers (
read_input_registers
).Read multiple holding registers (
read_multiple_holding_registers
).
Prompt: Analyze Modbus register values with a customizable prompt (
analyze_register
).Flexible Connections: Supports Modbus over TCP, UDP, or serial, configured via environment variables.
Requirements
Python: 3.10
uv for dependency and virtual environment management.
Installation
Install :
curl -LsSf https://astral.sh/uv/install.sh | shClone the Repository:
git clone https://github.com/kukapay/modbus-mcp.git cd modbus-mcpInstall Dependencies:
uv sync
Configuration
The server connects to a Modbus device using parameters specified via environment variables. Set these variables in a .env
file or your shell environment.
Environment Variables
Variable | Description | Default | Required |
| Connection type:
,
, or
|
| Yes |
| Host address for TCP/UDP |
| For TCP/UDP |
| Port for TCP/UDP |
| For TCP/UDP |
| Slave ID |
| For TCP/UDP |
| Serial port (e.g.,
,
) |
| For serial |
| Serial baud rate |
| For serial |
| Serial parity:
(none),
(even),
(odd) |
| For serial |
| Serial stop bits |
| For serial |
| Serial byte size |
| For serial |
| Serial timeout (seconds) |
| For serial |
Example .env
File
For TCP:
For Serial:
Usage
Installing for Claude Desktop
The configuration file:
Using Tools
Note: Natural language support depends on the client’s ability to parse and map prompts to tools. The MCP Inspector requires structured JSON, but the examples below show how conversational inputs translate.
Read a Holding Register:
Prompt:
Please read the value of Modbus holding register 0.MCP Inspector JSON:
{ "tool": "read_register", "parameters": {"address": 0, "slave_id": 1} }Expected Output:
Value: <register_value>
Write to a Holding Register:
Prompt:
Set Modbus holding register 10 to the value 100.MCP Inspector JSON:
{ "tool": "write_register", "parameters": {"address": 10, "value": 100, "slave_id": 1} }Expected Output:
Successfully wrote 100 to register 10
Read Coils:
Prompt:
Check the status of the first 5 Modbus coils starting at address 0.MCP Inspector JSON:
{ "tool": "read_coils", "parameters": {"address": 0, "count": 5, "slave_id": 1} }Expected Output:
Coils 0 to 4: [False, False, False, False, False]
Write to a Coil:
Prompt:
Turn on Modbus coil 5.MCP Inspector JSON:
{ "tool": "write_coil", "parameters": {"address": 5, "value": true, "slave_id": 1} }Expected Output:
Successfully wrote True to coil 5
Read Input Registers:
Prompt:
Read the values of 3 Modbus input registers starting from address 2.MCP Inspector JSON:
{ "tool": "read_input_registers", "parameters": {"address": 2, "count": 3, "slave_id": 1} }Expected Output:
Input Registers 2 to 4: [<value1>, <value2>, <value3>]
Read Multiple Holding Registers:
Prompt:
Get the values of Modbus holding registers 0 through 2.MCP Inspector JSON:
{ "tool": "read_multiple_holding_registers", "parameters": {"address": 0, "count": 3, "slave_id": 1} }Expected Output:
Holding Registers 0 to 2: [<value1>, <value2>, <value3>]
License
This project is licensed under the MIT License. See LICENSE for details.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
modbus-mcp
Related MCP Servers
- MIT License