MCP MQTT Light Controller
Provides tools for controlling smart lights via MQTT, including turning lights on/off and adjusting brightness levels (0-100) by publishing control messages to MQTT topics.
Click on "Install 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 MQTT Light Controllerturn on the living room lights"
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-mqtt-light
一个基于 MCP 的 MQTT 智能灯控制示例项目,包含:
mqtt_light_controller.py:提供 MCP 工具(开关灯、调亮度),通过 MQTT 发布控制消息mcp_pipe.py:把 MCP 的 stdio 与远端 WebSocket 端点进行双向转发,并支持按配置启动多个 MCP server
环境要求
Python 3.10+(建议)
安装
python -m pip install -r requirements.txt配置
1) MCP Pipe 连接端点
mcp_pipe.py 通过环境变量 MCP_ENDPOINT 连接到 WebSocket 端点:
Linux/macOS:
export MCP_ENDPOINT="ws://localhost:8765"Windows PowerShell:
$env:MCP_ENDPOINT = "ws://localhost:8765"2) MQTT 连接参数(可选)
mqtt_light_controller.py 支持以下环境变量(也可在 .env 中设置):
MQTT_BROKER:MQTT Broker 地址(默认:b11f17c5.ala.cn-hangzhou.emqxsl.cn)MQTT_PORT:端口(默认:8883,TLS)MQTT_CONTROL_TOPIC:控制主题(默认:smartlight/control)MQTT_STATUS_TOPIC:状态主题(默认:smartlight/status)MQTT_CLIENT_ID:客户端 ID(默认:mcp-light-controller)MQTT_USER/MQTT_PASSWORD:认证信息(默认空)
注意:当前 TLS 配置处于“忽略证书验证”的模式,适合本地/测试环境;生产环境建议启用证书校验。
运行
使用配置启动 MCP Server(推荐)
仓库内置 mcp_config.json 示例配置。
启动所有启用的 server:
python mcp_pipe.py只启动某一个 server(配置名或脚本路径均可):
python mcp_pipe.py mqtt-light-controller或:
python mcp_pipe.py mqtt_light_controller.py直接启动 mqtt_light_controller(调试用)
python mqtt_light_controller.py该进程会启动 MCP stdio server,并在首次运行时连接 MQTT Broker。
只想验证 MQTT 订阅能否收到消息(不启动 MCP stdio):
python mqtt_light_controller.py --mqtt-only提供的工具
mqtt_light_controller.py 暴露的 MCP 工具:
control_light(light_state: str):on/offadjust_brightness(brightness: int):亮度0-100
测试
本项目使用标准库 unittest 做基础测试:
python -m unittest discover -s tests -v也可以做一次基础语法/导入检查:
python -m compileall .This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/dshenaf/mcp-mqtt-light'
If you have feedback or need assistance with the MCP directory API, please join our Discord server