Sign inSign up

allexd2010/modbus-server-sim

By allexd2010

Updated 3 months ago

Image
0

1.2K

allexd2010/modbus-server-sim repository overview

Modbus TCP Server Simulation

Version 2.2.0 — lightweight Modbus TCP simulator with a single in-memory store, a modern Web UI, REST API, Swagger, MCP over HTTP, JavaScript simulation scripts, and a named address map.

Built with Rust (Rocket, tokio-modbus, QuickJS, rmcp).

Features

  • Modbus TCP — holding & input registers, coils, discrete inputs (zero-based addressing)
  • Web UI at /ui/ — register matrix, UInt16/Int32/float/double, bit masks, auto-refresh; EN/RU; installable PWA
  • Address map — named variables (conf/var-map.json), including bit fields in register words
  • Simulation scripts — QuickJS rules in /app/script: modbus.onWrite, modbus.setInterval, typed I/O, map.* API
  • REST API/api/v1/ (same data as Modbus TCP)
  • Swagger/api/v1/swagger/
  • MCP — Streamable HTTP at /mcp (Modbus tools, var-map, scripts, combined export/import)
  • Structured loggingRUST_LOG (default info)

Quick start

docker pull allexd2010/modbus-server-sim:2.2.0

docker run -d --name modbus-sim \
  -p 9090:9090 \
  -p 502:502 \
  -e RUST_LOG=info \
  allexd2010/modbus-server-sim:2.2.0
PortService
9090Web UI, REST, Swagger, MCP (/mcp)
502Modbus TCP

Open http://localhost:9090/ui/ after start.

Persistent configuration (volumes)

docker run -d --name modbus-sim \
  -p 9090:9090 -p 502:502 \
  -v /path/to/scripts:/app/script \
  -v /path/to/conf:/app/conf \
  allexd2010/modbus-server-sim:2.2.0
  • /app/script — simulation *.js files
  • /app/confvar-map.json (named Modbus variables)

Environment variables

VariableDefaultDescription
WEB_SERVER_PORT9090HTTP (UI, REST, Swagger, MCP)
MB_SERVER_PORT502Modbus TCP listen port
MCP_SERVER_PORT1Set 0 to disable MCP
MB_MAX_ADDRESS65535Max protocol address (HTTP API / UI)
MB_MAX_READ_COUNT65535Max words/bits per HTTP read/write batch
SIM_SCRIPTS_DIR/app/scriptSimulation scripts directory
SIM_SCRIPTS_DISABLE(unset)1 or true disables QuickJS engine
VAR_MAP_PATH/app/conf/var-map.jsonAddress map file
RUST_LOGinfoLog level (tracing)

Modbus addressing

Protocol and API use zero-based offsets (first holding register = 0).
Modicon-style: 40001 → offset 0, 40021 → offset 20.

MCP example (mcp.json)

{
  "mcpServers": {
    "modbus-tcp-sim": {
      "url": "http://127.0.0.1:9090/mcp"
    }
  }
}

Tags

  • 2.2.0 — current release (address map, simulation scripts, structured logging)
  • latest — latest stable release
  • test — CI builds from main

Release tags are published for linux/amd64 and linux/arm64.

Tag summary

Content type

Image

Digest

sha256:cf2254478

Size

35 MB

Last updated

3 months ago

docker pull allexd2010/modbus-server-sim