modbus-mcp
modbus-mcp
README
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).
- Read/write 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
uv:curl -LsSf https://astral.sh/uv/install.sh | sh -
Clone the Repository:
git clone https://github.com/kukapay/modbus-mcp.git cd modbus-mcp -
Install 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 |
|---|---|---|---|
MODBUS_TYPE |
Connection type: tcp, udp, or serial |
tcp |
Yes |
MODBUS_HOST |
Host address for TCP/UDP | 127.0.0.1 |
For TCP/UDP |
MODBUS_PORT |
Port for TCP/UDP | 502 |
For TCP/UDP |
MODBUS_SERIAL_PORT |
Serial port (e.g., /dev/ttyUSB0, COM1) |
/dev/ttyUSB0 |
For serial |
MODBUS_BAUDRATE |
Serial baud rate | 9600 |
For serial |
MODBUS_PARITY |
Serial parity: N (none), E (even), O (odd) |
N |
For serial |
MODBUS_STOPBITS |
Serial stop bits | 1 |
For serial |
MODBUS_BYTESIZE |
Serial byte size | 8 |
For serial |
MODBUS_TIMEOUT |
Serial timeout (seconds) | 1 |
For serial |
Example .env File
For TCP:
MODBUS_TYPE=tcp
MODBUS_HOST=192.168.1.100
MODBUS_PORT=502
For Serial:
MODBUS_TYPE=serial
MODBUS_SERIAL_PORT=/dev/ttyUSB0
MODBUS_BAUDRATE=9600
MODBUS_PARITY=N
MODBUS_STOPBITS=1
MODBUS_BYTESIZE=8
MODBUS_TIMEOUT=1
Usage
Installing for Claude Desktop
The configuration file:
{
"mcpServers": {
"Modbus MCP Server": {
"command": "uv",
"args": [ "--directory", "/path/to/modbus-mcp", "run", "modbus-mcp" ],
"env": { "MODBUS_TYPE": "tcp", "MODBUS_HOST": "127.0.0.1", "MODBUS_PORT": 502 },
}
}
}
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} } - Expected Output:
Value: <register_value>
- Prompt:
-
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} } - Expected Output:
Successfully wrote 100 to register 10
- Prompt:
-
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} } - Expected Output:
Coils 0 to 4: [False, False, False, False, False]
- Prompt:
-
Write to a Coil:
- Prompt:
Turn on Modbus coil 5. - MCP Inspector JSON:
{ "tool": "write_coil", "parameters": {"address": 5, "value": true} } - Expected Output:
Successfully wrote True to coil 5
- Prompt:
-
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} } - Expected Output:
Input Registers 2 to 4: [<value1>, <value2>, <value3>]
- Prompt:
-
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} } - Expected Output:
Holding Registers 0 to 2: [<value1>, <value2>, <value3>]
- Prompt:
License
This project is licensed under the MIT License. See LICENSE for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。