
Modbus TCP/RTU Device
io.github.K-Dense-AI由 GitHub 账号 K-Dense-AI 发布v0.1.3更新于 Oct 24, 2026
MCP server for Modbus TCP/RTU devices with typed, scaled register maps and per-point limits.
概览
一个本地 MCP 服务器,让助手通过带类型、带缩放和逐点限值的寄存器映射读取并控制 Modbus TCP/RTU 设备。
- 可以做什么
- 读取按工程单位解码的命名点位,以及原始保持寄存器、输入寄存器、线圈和离散输入,并查看已加载的寄存器映射、连接信息和命令日志。写入设定值、模式、输出等命名点位,发送前按可写标志、min/max 或枚举校验,写入后再回读确认。对映射未描述的地址写入原始寄存器和线圈。执行映射中定义的安全状态序列,并在断电或换线后重新连接。
- 适用场景
- 当助手需要监视或调整实验室与工业 Modbus 设备(如温控器、冷水机、PLC、传感器、变频器或数据记录仪),且你能提供该设备的寄存器映射时使用。它更适合有人监督的设定值调整和安全状态恢复,而非无人值守控制。
- 运行要求
- 以 Python 包(uvx labmcp-modbus)通过 stdio 在本地运行。需要寄存器映射文件(YAML 或 JSON)和设备地址,可通过 LABMCP_ADDRESS 或地址参数提供,例如 TCP 主机与端口,或带波特率和校验位的串口。需要到设备的网络或串口访问;内置模拟器无需硬件。
安装
在 SourceWeft 中
- 打开 控制台中的 Modbus TCP/RTU Device,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Modbus TCP/RTU Device — MCP Server
Let an AI agent read and control Modbus devices over Ethernet (Modbus TCP) or RS-485/RS-232 (Modbus RTU/ASCII): PID temperature controllers, recirculating chillers, PLCs, process sensors, VFDs and data loggers. You describe the device once in a register map (YAML or JSON). The agent then works with named points in real units, such as process_temperature = 37.2 °C or setpoint, instead of raw registers. The server enforces the map's rules: only writable points can be written by name, every writable number must have a min and max, and out-of-range values are refused before anything is sent. The map can also define a safe state, a list of point writes (heater off, controller to standby) that a SAFETY tool runs on request.
What this server adds over a plain register-poking Modbus MCP:
- Typed register maps: int16/uint16/int32/uint32/float32/float64/bool, word and byte order,
scaleandoffset, units, enums (0 = standby, 1 = auto) and descriptions. - Per-point limits: writable points need
min/maxor an enum, and values are checked before sending. Raw writes to addresses that belong to a mapped point are refused, so the limits can't be bypassed. - Read-back: every
write_pointreads the value back and reports whether it matches. - Safe state: an
apply_safe_stateSAFETY tool, defined in the map, that works even in--read-onlymode. - Read-only mode (
--read-only), an audit log of every request and reply, and bounded request sizes.
Try it without hardware
The simulator is a generic single-loop PID temperature controller. Its layout is the bundled example register map. It is illustrative and not a copy of any vendor's map. A heater (3 °C/s at full power) heats a thermal mass that cools towards a 22 °C room (τ = 90 s). The PID loop has a ramping working setpoint and alarm bits. The simulator answers exception 02 for unimplemented addresses, 03 for values outside its own range (e.g. a 500 °C setpoint), and 0B for a wrong unit id. With --simulate --option register_map=my_map.yaml, points that are not in the example layout get zero-initialised storage, so you can test your own map.
Connect your device
- Device setup: in the device's communications menu, enable Modbus and note its settings.
- RTU (RS-485): set the unit (slave) address (1–247), baud rate, parity and stop bits. The server defaults to the Modbus serial default of 19200 baud, 8 data bits, even parity, 1 stop bit. Many devices ship with other settings (e.g. 9600 8N1); put your device's settings in the address. Wire the USB-RS485 adapter's A/B (D−/D+) lines to the device; vendors disagree on the A/B labels, so swap them if nothing answers. Connect the signal ground, and put 120 Ω termination at both ends of longer buses.
- TCP: set the IP address. The port is 502 unless changed. Many TCP devices ignore the unit id. If yours does not, it is usually 1; the TCP implementation guide recommends 255 for directly addressed devices.
- Write a register map for your device from its Modbus manual. Copy the example and see Register map below.
- Test the connection:
--checkconnects, reads the map's first point as a probe and printsprobe: ok: …or the error. More address parameters:stopbits=2,bytesize=7,framer=ascii(Modbus ASCII),timeout=1,retries=2.
Register map
The server validates the map when it starts. Unknown fields (e.g. a misspelt maximum) and repeated keys (a second max, or a point defined twice) are errors rather than being silently ignored, so a typo can't remove a limit. Two writable points may not share a register (writing one would bypass the other's limits); read-only views of a writable register are fine. If the map is invalid, list_points shows the error and the device tools refuse to run. The server fails closed.
Add to your MCP client
Claude Code
Claude Desktop / Cursor / Windsurf (claude_desktop_config.json, .cursor/mcp.json, …)
Useful flags:
--read-onlyallows reads only.apply_safe_statestays available.--option raw_writes=falseremoveswrite_register,write_registersandwrite_coil, so the agent can only write what the map allows. This is recommended once your map is complete.
Tools
get_connection_info, get_command_log and reconnect are built into every LabMCP server. apply_safe_state is listed only when the register map defines a safe_state.
Safety limits
This server has no global --limit values: a generic Modbus client can't know what a register means. The protections come from the register map and the server:
Example prompts
- "What's the chamber temperature and output power right now? Show every point with its unit."
- "Ramp the controller to 55 °C at 2 °C/min, switch it to auto, enable the heater, and tell me when it's within 0.5 °C of setpoint."
- "Set the high alarm to 70 °C, then check whether any alarm or sensor-fault bits are active."
- "Read holding registers 100–109 and decode them as float32 (try both word orders). I'm mapping a new chiller."
- "Something's wrong: put the controller in its safe state and confirm the heater is off."
Notes
- Addresses are 0-based on the wire. Manuals often use 1-based "Modicon" numbers (40001 = holding 0). If every read is off by one register, the map uses the wrong convention.
- Word order is not standardised for 32-bit values: the Modbus spec only defines byte order within a register. If a float or 32-bit value looks absurd, try
word_order: little.read_registerswithdecode_ashelps you find the right order. - A float point that reads NaN or infinity (many devices use NaN as "no value", e.g. a sensor fault) comes back with
value: nulland anerror;read_registerswithdecode_asshows it as"nan"/"inf". write_pointuses FC06 for single-register points, FC16 for multi-register points and FC05 for coils. A few devices accept only FC16 even for single registers. For those, map the value as part of a multi-register point or report it so we can add an option.- Some controllers save written parameters to non-volatile memory, which survives only a limited number of write cycles. Don't have the agent rewrite setpoints in a tight loop. Check whether the manual offers a RAM-only or remote setpoint register.
- Reading is normally side-effect free, but a few devices clear counters or alarms when they are read. Leave such registers out of the map or mark them in
description. - Modbus TCP devices often accept only a few simultaneous connections. Close other SCADA or logging clients if the connection is refused.
- Timeouts nearly always mean a wrong unit id, baud rate, parity or A/B wiring. Exception 02 means an address the device does not implement. Exception 03 means the device rejected the value by its own internal limits.
- Works with pymodbus 3.8 or newer (the unit keyword changed from
slave=todevice_id=in 3.10; both are handled). - The bundled map is an illustrative example. Contributions of real device maps are welcome: include the manual title and revision the addresses came from.
Hardware verification
来源:servers/protocols/modbus/README.md,提交 46545ea
工具
0版本历史
2- v0.1.3最新Sep 27, 2026
- v0.1.1Sep 26, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分