
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 分