MCP MQTT Light Controller

MCP MQTT Light Controller

Enables control of smart lights through MQTT messaging protocol, supporting operations like turning lights on/off and adjusting brightness levels from 0-100.

Category
Visit Server

README

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](file:///e:/LLM/mcp-mqtt-light/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/off
  • adjust_brightness(brightness: int):亮度 0-100

测试

本项目使用标准库 unittest 做基础测试:

python -m unittest discover -s tests -v

也可以做一次基础语法/导入检查:

python -m compileall .

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured