mcp-kr-controller
The mcp-kr-controller server provides an AI-driven, conversational interface to connect, discover, and control KR-series industrial relay controllers over Serial (RS-485), TCP, or UDP — with no configuration files required.
Connection Management — Establish, list, and remove serial, TCP, or UDP connections to relay controllers.
Device Discovery — Auto-scan networks and serial ports to find and register controllers (supports default V4 TCP/V5 UDP addresses, multi-NIC subnet matching); manually list registered devices with I/O channel counts and transport info.
Status & Query — Read the current state of all digital inputs (DI) and relay outputs; query function modules (storage, RTC) and I/O configuration.
Basic Relay Control — Connect/energize or disconnect/de-energize a single relay; set all relays via a 16-bit bitmask; turn all relays on or off at once.
Advanced (PLC-Style) Control — Momentary pulse actions (single or multi-channel via mask: ON→OFF or OFF→ON with configurable duration); blink relays (single or multi-channel); group connect, disconnect, or toggle by bitmask without affecting other relays.
Animation — Ping-pong bouncing-light animation across configurable start/end channels with adjustable speed and repeat count.
Event-Driven Automation — Wait for a DI channel rising-edge trigger, then automatically execute an action (ping-pong animation, all relays on, or all relays off) with configurable timeout and polling interval.
Fire-and-Forget — Control commands return instantly; hardware state is confirmed via status reads.
Persistence — Device connections and registrations are saved to
state.jsonand auto-restored on server restart.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-kr-controller Turn on channel 3 of device 1"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-kr-controller
MCP (Model Context Protocol) server for KR-series relay controllers. Connect your hardware controllers to AI through serial/UART, TCP, or UDP — zero configuration, conversational discovery.
Features
Conversational Architecture — No config file needed. Tell the AI your connection type, it handles the rest.
Multi-Transport — Serial (UART 9600 8N1), TCP, UDP with unified transport abstraction.
Auto Discovery — Broadcast scan finds all connected devices, queries I/O channels and function modules, registers automatically.
State Persistence — Device connections and registrations saved to
state.json, auto-restored on restart.23 MCP Tools — Auto discovery, device scanning, status query, relay control, PLC advanced control, animations, DI trigger automation.
Fire-and-Forget — Control commands return instantly without waiting for hardware response.
Related MCP server: rosclaw-ur-rtde-mcp
Quick Start
Install
npm install -g mcp-kr-controller
# or use directly without install
npx mcp-kr-controllerConfigure in your MCP client
Add to your MCP client config (e.g. Claude Desktop claude_desktop_config.json, WorkBuddy mcp.json):
{
"mcpServers": {
"kr-controller": {
"command": "npx",
"args": ["mcp-kr-controller"],
"type": "stdio"
}
}
}Or if installed globally:
{
"mcpServers": {
"kr-controller": {
"command": "mcp-kr-controller",
"type": "stdio"
}
}
}Usage Flow
Confirm connection type — Tell the AI: "Search for devices"
AI will ask: "串口还是网络?" (Serial or Network?)
Network — AI calls
auto_discover(connection_type="network")Auto-tries V4 TCP
192.168.16.254:8080and V5 UDP broadcast192.168.1.255:8080Multi-NIC: auto-matches local NIC to the same subnet (255.255.255.0)
Devices found are automatically registered with I/O config
Serial — AI asks for COM port, then calls
auto_discover(connection_type="serial", path="COM3")Connects via RS-485 at 9600 baud, scans and registers devices
Control — Say "Turn on channel 3 of device 1" — AI handles the rest
If default addresses don't match your network, use setup_connection with manual config.
Multi-NIC Note: The V5 UDP discovery automatically selects the local NIC matching the target subnet (255.255.255.0). If you have multiple network cards, make sure the controller is on the same subnet as one of them.
Hardware Support
Two hardware versions, three transport modes — all share the same control protocol.
Version | Transport | Product Line |
V5 | TCP / UDP (network) | 8DI, 8DI+8DO, 12DI+8DO, 2DI+9DO, 16DI, 16DO |
V4 | RS-485 serial, TCP/UDP transparent | Various I/O configurations |
Tested configurations (as of 2026-07-30):
Device | Ver | I/O | Transport | Status |
#1 | V5 | 12DI+8DO | UDP broadcast | Verified |
#1 | V4 | 16DO | TCP transparent | Verified |
#21 | V4 | 8DI+8DO | RS-485 COM3 | Verified |
Environment Variables (optional)
Variable | Description |
| Serial port path (e.g. |
| TCP host |
| TCP port (default 8080) |
| UDP host |
| UDP port (default 8080) |
Protocol
KR-series controllers use an 8-byte fixed-length frame protocol over UART (9600 bps, 8N1):
| Header | Address | Command | Data0 | Data1 | Data2 | Data3 | Checksum |
| 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte |Header:
0x55(request) /0x22(response)Address:
0x00/0xFF(broadcast) or0x01–0xFE(device address 1-254)Checksum:
sum(byte[0..6]) & 0xFF
Supported Commands
Code | Function |
0x21 | Find devices (broadcast) |
0x2D | Query device properties (I/O count, modules) |
0x10 | Read status (DI + relay) |
0x11 | Disconnect one relay |
0x12 | Connect one relay |
0x13 | Set relays by bitmask |
0x06/0x08 | Momentary on/off (by mask) |
0x09/0x18 | Momentary on/off (single channel) |
0x07/0x17 | Blink (single/multi) |
0x14/0x15/0x16 | Group disconnect/connect/toggle |
MCP Tools
Connection Management
setup_connection— Establish serial/TCP/UDP connectionlist_connections— List active connectionsremove_connection— Remove a connection
Device Discovery
scan_devices— Broadcast scan + auto-register deviceslist_devices— Show registered devices
Status & Query
read_status— Read DI inputs + relay outputsget_function_modules— Query function module bitmask
Basic Control
connect_relay— Connect (energize) one relaydisconnect_relay— Disconnect (de-energize) one relayset_relays_by_mask— Set all relays by bitmaskall_relays_on/all_relays_off— All relays on/off
Advanced Control
momentary_on_off_single/momentary_off_on_single— Momentary action (single channel)momentary_on_off_multi/momentary_off_on_multi— Momentary action (by mask)blink_single/blink_multi— Blink relay(s)group_connect/group_disconnect/group_toggle— Group operations
Animation Test
ping_pong— Ping-pong bounce animation with configurable delay
Event Trigger
wait_di_trigger— Monitor DI channel, execute action on rising edge
Development
# Clone
git clone https://github.com/kinbeg/mcp-kr-controller.git
cd mcp-kr-controller
# Install dependencies
npm install
# Build
npm run build
# Run in dev mode
npm run devPurchase
KR-series controllers are available at the official store:
License
MIT
Available Tools
24 toolsall_relays_offA
一键断开全部继电器。发完即走不等应答,直接读状态确认。内部使用 SET_RELAY_MASK 单指令执行,比逐路操作快 N 倍。对应自然语言:全关、关闭所有开关、全部断开、all off。
Inputs: address.
all_relays_onA
一键吸合全部继电器。发完即走不等应答,直接读状态确认。内部使用 SET_RELAY_MASK 单指令执行,比逐路操作快 N 倍。对应自然语言:全开、打开所有开关、全部吸合、all on。
Inputs: address.
auto_discoverA
设备搜索与添加(需先确认连接方式)。用户说「搜索设备」时,AI 必须先问清楚连接方式(串口/网络),再调用本工具。connection_type='network':自动尝试 V4 TCP 192.168.16.254:8080 和 V5 UDP 广播 192.168.1.255:8080, 多网卡环境自动匹配同网段本地网卡(如 255.255.255.0 子网)。connection_type='serial':需提供 path(如 COM3),可选 baudRate(默认 9600)。建立连接 → 广播搜索 → 查询 IO/模块 → 注册设备,全自动完成。如果默认地址连不上,会明确告知,届时请用户确认实际地址后用 setup_connection 手动指定。
Inputs: connection_type (required), path, baudRate.
blink_multiA
多路闪烁(按位):指定的多路继电器按设定时间周期性通断。
Inputs: mask (required), time (required), group (required), address.
blink_singleB
单路闪烁:指定继电器按设定时间周期性通断。
Inputs: time (required), channel (required), address.
connect_relayB
吸合指定设备指定一路继电器(ON)。参数:address=机器地址, channel=回路号。
Inputs: channel (required), address.
disconnect_relayB
断开指定设备指定一路继电器(OFF)。参数:address=机器地址, channel=回路号。
Inputs: channel (required), address.
get_function_modulesB
查询指定设备的功能模块(存储模块、RTC时钟)是否存在。
Inputs: address.
group_connectA
组吸合:按掩码吸合指定继电器,其余通道保持原状态不变。
Inputs: mask (required), address.
group_disconnectA
组断开:按掩码断开指定继电器,其余通道保持原状态不变。
Inputs: mask (required), address.
group_toggleA
组翻转:按掩码翻转指定继电器状态(断开→吸合, 吸合→断开),其余通道保持不变。
Inputs: mask (required), address.
list_connectionsA
列出当前所有通讯连接及其状态。用于确认已添加的连接。
Inputs: no named parameters.
list_devicesA
列出所有已注册设备。显示每台设备的地址、IO通道数(DI/DO)、功能模块(存储/RTC)、连接方式。控制设备时用此工具确认设备地址和可用回路数。
Inputs: no named parameters.
momentary_off_on_multiA
多路点动 OFF→ON(按位):指定的多路继电器吸合指定时间后自动断开恢复。
Inputs: mask (required), time (required), group (required), address.
momentary_off_on_singleA
单路点动 OFF→ON:断开的继电器吸合指定时间后自动断开恢复。相当于按钮按下效果。参数:address, channel=回路号, time=持续时间。
Inputs: time (required), channel (required), address.
momentary_on_off_multiA
多路点动 ON→OFF(按位):指定的多路继电器在指定时间后自动断开。
Inputs: mask (required), time (required), group (required), address.
momentary_on_off_singleA
单路点动 ON→OFF:吸合的继电器在指定时间后自动断开。相当于延时关闭。参数:address, channel=回路号, time=延时时间。
Inputs: time (required), channel (required), address.
ping_pongA
单灯 ping-pong 弹跳动画:从起始回路到终止回路的单个灯来回跑动效果。每次只亮一路,像乒乓球一样弹跳。内部连续发送多条 SET_RELAY_MASK 指令(fire-and-forget),一次调用完成全部动画。起始和结束自动全部断开,适配 TCP 透传设备(含 V4/V5)。最后自动读取状态确认终点位置。参数:address=设备地址, start=起始回路(默认1), end=终止回路(默认8), count=来回次数(默认1), delay=帧间隔秒数(默认0.1)。对应自然语言:跑马灯、ping-pong、来回弹跳、弹弹球。
Inputs: end, count, delay, start, +1 more.
read_statusA
读取指定设备的全部输入和继电器当前状态。返回 16 路输入通断 + 16 路继电器通断。每次控制操作后也可查看状态变化。
Inputs: address.
remove_connectionA
移除一个通讯连接。同时会移除该连接上注册的所有设备。
Inputs: id (required).
scan_devicesA
扫描所有连接上的在线设备并自动注册。执行流程:1)广播查找命令发现设备 2)对每台设备查询 IO 通道数和功能模块 3)将设备信息注册到注册表并持久化。扫描完成后设备即可通过地址+回路号控制。首次使用时必须先调用此工具。
Inputs: no named parameters.
set_relays_by_maskC
按 16 位掩码批量设置继电器状态。掩码中 1=吸合, 0=断开,一次性设置所有回路。例如 mask=0x000F = 吸合第1-4路、断开第5-16路。
Inputs: mask (required), address.
setup_connectionA
添加通讯连接。用户通过对话告知通讯方式后调用此工具。支持三种类型:serial(串口,需提供 path 如 COM3)、tcp(TCP透传,需提供 host 和 port)、udp(UDP透传,需提供 host 和 port)。添加后自动连接,可用于后续设备扫描。
Inputs: type (required), host, path, port, +1 more.
wait_di_triggerA
监听指定 DI 通道的上升沿触发(无输入→有输入),触发后自动执行指定动作。轮询 READ_STATUS 检测状态变化,检测到触发后执行动作并返回结果。参数:address=设备地址, channel=监听的DI通道号(默认1), timeout=超时毫秒(默认60000), poll_interval=轮询间隔毫秒(默认200), action=触发后执行的动作(默认ping_pong, 可选all_relays_on/all_relays_off), start/end/count/delay=ping_pong动作参数。对应自然语言:检测到输入触发时执行、当DI1有信号时跑马灯、输入触发动画。
Inputs: end, count, delay, start, +5 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 24 tools
Several tools have overlapping purposes, especially auto_discover and scan_devices which both handle device discovery and registration, and various relay control tools (all_relays_off, group_disconnect, set_relays_by_mask) that can achieve similar outcomes with different scopes. This makes it difficult for an agent to reliably choose the correct tool.
Naming patterns are inconsistent: some use verb_noun (setup_connection, scan_devices), others use noun_verb (group_disconnect, all_relays_off), and several are compound or non-standard (momentary_off_on_single, ping_pong). The verb placement and naming style vary considerably.
With 24 tools, the count falls in the heavy 16-25 range. While many tools cover distinct relay control features, some convenience wrappers (e.g., all_relays_off, group_disconnect) could likely be consolidated without losing functionality.
The tool surface covers connection management, device discovery, status reading, and a broad range of relay operations (single, group, all, mask, momentary, blink, animation, DI-trigger). Minor gaps exist, such as no dedicated device removal or connection update, but core workflows are well covered.
Maintenance
Related MCP Connectors
MCP server for Klever blockchain smart contract development.
MCP server with quote and live cryptocurrency price tools, local and cloud-deployed transports.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceMCP server that provides computer control capabilities including mouse movements, keyboard actions, screenshot capture with OCR, and window management through a unified API.927 PyPI174MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for controlling Universal Robots arms and Robotiq grippers via RTDE protocol, enabling motion, force, I/O, and gripper operations.1MIT
- AlicenseAqualityDmaintenanceMCP server for controlling Homey Pro smart home systems, offering 60+ tools for device control, flow authoring, automation, monitoring, and network diagnostics.601MIT
- AlicenseAqualityDmaintenanceMCP server for controlling B&K Precision and Manson bench power supplies, enabling voltage/current setting, output switching, and power cycling.83MIT