Skip to main content
Glama
mcp-kr-controller

mcp-kr-controller

by kinbeg

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-controller

Configure 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

  1. Confirm connection type — Tell the AI: "Search for devices"

    • AI will ask: "串口还是网络?" (Serial or Network?)

  2. Network — AI calls auto_discover(connection_type="network")

    • Auto-tries V4 TCP 192.168.16.254:8080 and V5 UDP broadcast 192.168.1.255:8080

    • Multi-NIC: auto-matches local NIC to the same subnet (255.255.255.0)

    • Devices found are automatically registered with I/O config

  3. 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

  4. 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

KR_SERIAL_PATH

Serial port path (e.g. COM3, /dev/ttyUSB0)

KR_TCP_HOST

TCP host

KR_TCP_PORT

TCP port (default 8080)

KR_UDP_HOST

UDP host

KR_UDP_PORT

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) or 0x01–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 connection

  • list_connections — List active connections

  • remove_connection — Remove a connection

Device Discovery

  • scan_devices — Broadcast scan + auto-register devices

  • list_devices — Show registered devices

Status & Query

  • read_status — Read DI inputs + relay outputs

  • get_function_modules — Query function module bitmask

Basic Control

  • connect_relay — Connect (energize) one relay

  • disconnect_relay — Disconnect (de-energize) one relay

  • set_relays_by_mask — Set all relays by bitmask

  • all_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 dev

Purchase

KR-series controllers are available at the official store:

kinbeg.taobao.com

License

MIT

Available Tools

24 tools
all_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.

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

    B3.2/5.0

    Scored across 24 tools

    Disambiguation2/5

    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 Consistency2/5

    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.

    Tool Count3/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      MCP server that provides computer control capabilities including mouse movements, keyboard actions, screenshot capture with OCR, and window management through a unified API.
      927 PyPI
      174
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      MCP server for controlling B&K Precision and Manson bench power supplies, enabling voltage/current setting, output switching, and power cycling.
      8
      3
      MIT