hotel-iot-mcp
v1.4.0
Published
Hotel IOT MCP Server for Bailian Platform with separated scene query tool
Maintainers
Readme
Hotel IOT MCP Server
Hotel IOT MCP服务,可通过npx方式部署到百炼平台。
功能特性
- 设备控制(支持灯光、空调、窗帘、电视、门锁等设备)
- 设备状态查询(获取各类设备的当前状态)
- 设备参数设置
- 场景控制(支持预定义的复合操作场景)
- 场景配置(支持自定义场景参数)
- 场景查询(支持查询场景配置信息)
支持的设备类型
- 灯光 (light):控制开关、调节亮度
- 空调 (ac):控制开关、设置温度、调节模式
- 窗帘 (curtain):控制开关、设置位置
- 电视 (tv):控制开关、切换频道、调节音量
- 门锁 (door):控制上锁/解锁
支持的场景类型
- welcome_guest (欢迎客人):打开灯光、设置空调温度、打开电视
- sleep_mode (睡眠模式):调暗灯光、设置空调温度、关闭电视、关闭窗帘
- movie_time (观影时间):调暗灯光、打开电视、关闭窗帘
- meeting_mode (会议模式):打开灯光、设置空调温度
- cleaning_mode (清洁模式):打开灯光、打开窗帘、解锁门锁
- goodbye_guest (送别客人):关闭灯光、关闭电视、设置空调温度
支持的后端服务类型
- openDoor (打开房门)
- closeDoor (关闭房门)
- payService (支付服务)
- tempAdjust (温度调节)
- lightAdjust (灯光调节)
- tvControl (电视控制)
- lockControl (门锁控制)
- sendDrink (送饮品)
- sendMeal (送餐)
- clean (打扫)
- call (呼叫)
- serviceFacility (服务设施)
- timing (定时服务)
工作原理
当大模型调用设备控制工具时,MCP会立即返回mock数据给大模型,同时异步调用后端API来实际控制设备。这种设计确保了大模型能够快速得到响应,而设备控制操作在后台继续执行。
后端API调用格式示例:
POST /api/broadcast/message
{
"type": "tempAdjust",
"roomId": "302",
"value": 25
}安装依赖
npm install使用方式
本地运行
# 使用stdio传输(适用于本地测试)
npm start
# 使用HTTP传输(适用于百炼平台部署)
npm run dev通过npx运行
npx hotel-iot-mcp接口说明
1. 设备控制 (device_control)
控制各种Hotel IOT设备。
参数:
- deviceType (string): 设备类型 (light, ac, curtain, tv, door)
- action (string): 操作指令
- value (number|string, optional): 操作值
- roomId (string, optional): 房间号,用于多房间环境下的设备控制
- sessionId (string, optional): 会话ID,用于跟踪用户会话
- source (string, optional): 来源标识,用于标识请求来源
各设备类型支持的操作:
灯光 (light):
- turn_on (打开)
- turn_off (关闭)
- set_brightness (设置亮度):
{"deviceType": "light", "action": "set_brightness", "value": 80} - 示例:
{"deviceType": "light", "action": "turn_on"}
空调 (ac):
- turn_on (打开)
- turn_off (关闭)
- set_temperature (设置温度):
{"deviceType": "ac", "action": "set_temperature", "value": 25} - set_mode (设置模式):
{"deviceType": "ac", "action": "set_mode", "value": "cool"}
窗帘 (curtain):
- open (打开)
- close (关闭)
- 示例:
{"deviceType": "curtain", "action": "open"}
电视 (tv):
- turn_on (打开)
- turn_off (关闭)
- 示例:
{"deviceType": "tv", "action": "turn_on"}
门锁 (door):
- lock (上锁)
- unlock (解锁)
- 示例:
{"deviceType": "door", "action": "lock"}
示例:
{
"deviceType": "light",
"action": "turn_on"
}{
"deviceType": "light",
"action": "set_brightness",
"value": 80
}{
"deviceType": "ac",
"action": "set_temperature",
"value": 22,
"roomId": "101",
"sessionId": "sess-001",
"source": "hotel-app"
}2. 设备状态查询 (device_status)
查询Hotel IOT设备的当前状态。
参数:
- deviceType (string): 设备类型 (light, ac, curtain, tv, door)
- roomId (string, optional): 房间号
- sessionId (string, optional): 会话ID
示例:
{
"deviceType": "ac"
}{
"deviceType": "light",
"roomId": "101",
"sessionId": "sess-001"
}3. 设备参数设置 (device_config)
设置Hotel IOT设备的配置参数。
参数:
- deviceType (string): 设备类型 (light, ac, curtain, tv, door)
- config (object): 配置参数
- roomId (string, optional): 房间号
- sessionId (string, optional): 会话ID
各设备类型支持的配置示例:
灯光 (light):
{ "deviceType": "light", "config": { "maxBrightness": 100, "defaultBrightness": 50 }, "roomId": "101", "sessionId": "sess-001" }空调 (ac):
{ "deviceType": "ac", "config": { "defaultTemperature": 24, "minTemperature": 16, "maxTemperature": 30 }, "roomId": "101", "sessionId": "sess-001" }窗帘 (curtain):
{ "deviceType": "curtain", "config": { "autoCloseTime": "22:00", "autoOpenTime": "07:00" }, "roomId": "101", "sessionId": "sess-001" }电视 (tv):
{ "deviceType": "tv", "config": { "ip": "192.168.1.100", "port": 8080, "defaultVolume": 30 }, "roomId": "101", "sessionId": "sess-001" }门锁 (door):
{ "deviceType": "door", "config": { "autoLockTime": 30, "password": "123456" }, "roomId": "101", "sessionId": "sess-001" }
示例:
{
"deviceType": "tv",
"config": {
"ip": "192.168.1.100",
"port": 8080
}
}4. 场景控制 (scene_control)
执行预定义的场景控制,如欢迎客人、睡眠模式等。
参数:
- scene (string): 场景类型 (welcome_guest, sleep_mode, movie_time, meeting_mode, cleaning_mode, goodbye_guest)
- roomId (string, optional): 房间号
- sessionId (string, optional): 会话ID
示例:
{
"scene": "welcome_guest",
"roomId": "101"
}{
"scene": "sleep_mode",
"roomId": "101",
"sessionId": "sess-001"
}5. 场景配置 (scene_config)
管理场景配置,支持设置和恢复默认场景配置。
参数:
- operation (string): 操作类型 (set, delete)
- sceneName (string): 场景名称
- config (object): 场景配置
操作类型说明:
- set: 设置场景配置
- delete: 恢复默认场景配置(对于默认场景)或删除自定义场景
示例:
{
"operation": "set",
"sceneName": "sleep_mode",
"config": {
"name": "睡眠模式",
"devices": [
{"deviceType": "light", "action": "set_brightness", "value": 5},
{"deviceType": "ac", "action": "set_temperature", "value": 20},
{"deviceType": "tv", "action": "turn_off"},
{"deviceType": "curtain", "action": "close"}
]
}
}{
"operation": "delete",
"sceneName": "sleep_mode"
}注意:对于默认场景(如sleep_mode),delete操作会将其恢复为默认配置;对于自定义场景,delete操作会将其从配置中删除。
6. 场景查询 (scene_query)
查询场景配置信息。
参数:
- operation (string): 操作类型 (list, get)
- sceneName (string, optional): 场景名称
操作类型说明:
- list: 列出所有自定义场景
- get: 获取特定场景的配置
示例:
{
"operation": "list"
}{
"operation": "get",
"sceneName": "sleep_mode"
}场景配置文件
场景配置存储在scene-config.json文件中,支持自定义场景参数。默认场景配置如下:
{
"welcome_guest": {
"name": "欢迎客人",
"devices": [
{"deviceType": "light", "action": "turn_on", "value": 80},
{"deviceType": "ac", "action": "set_temperature", "value": 24},
{"deviceType": "tv", "action": "turn_on"}
]
},
"sleep_mode": {
"name": "睡眠模式",
"devices": [
{"deviceType": "light", "action": "set_brightness", "value": 10},
{"deviceType": "ac", "action": "set_temperature", "value": 22},
{"deviceType": "tv", "action": "turn_off"},
{"deviceType": "curtain", "action": "close"}
]
}
}配置验证
场景配置会进行以下验证:
- 空调温度范围:16-30度
- 灯光亮度范围:0-100%
百炼平台部署
在百炼平台部署时,使用以下配置:
服务器配置
{
"mcpServers": {
"hotel-iot-mcp": {
"command": "npx",
"args": ["-y", "hotel-iot-mcp", "${port}"],
"env": {
"NODE_ENV": "production"
},
"cwd": ".",
"description": "Hotel IOT MCP服务"
}
}
}重要说明:百炼平台需要MCP服务支持HTTP传输方式,因此参数中必须包含 ${port} 变量,服务会根据该端口启动HTTP服务器。
