mcp-kr-controller
An MCP server for controlling KR-series relay controllers via serial, TCP, or UDP, featuring auto-discovery, relay control, and advanced PLC capabilities.
README
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.
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
- 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:8080 - Multi-NIC: auto-matches local NIC to the same subnet (255.255.255.0)
- Devices found are automatically registered with I/O config
- Auto-tries V4 TCP
- 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 |
|---|---|
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) 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
PLC 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
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:
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。