Provides comprehensive MQTT broker operations including publishing messages, subscribing to topics with wildcard support, and implementing request/response patterns with fine-grained topic permissions
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 Serversubscribe to sensors/+/temperature and show me the latest readings"
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 Server
An MCP (Model Context Protocol) server that provides MQTT operations to LLM agent pipelines through a discoverable interface. The server supports fine-grained topic permissions with wildcard matching and provides comprehensive MQTT functionality for MCP clients.
The MCP MQTT server allows operation in stdio mode as well as HTTP streamable remote operation via Unix domain sockets (recommended) or TCP/IP.
Installation
To run the remote HTTP/UDS server, install the optional FastAPI/uvicorn extras:
Related MCP server: Toolkit MCP Server
Configuration
Configuration File Structure
Create a configuration file at ~/.config/mcpmqtt/config.json or specify a custom path when launching the utility on the command line using the --config parameter:
Use mcpMQTT --genkey to populate the api_key_kdf block. The command prints the new API key exactly once to stdout so you can copy it into your secrets manager.
Configuration Sections
mqtt: MQTT broker connection settingstopics: Topic patterns with permissions and descriptionslogging: Application logging levelremote_server(optional when using stdio transport): Remote FastAPI settings, including the KDF protected API key (api_key_kdf) and the bind configuration. Leavingportasnullkeeps the Unix domain socket default (/var/run/mcpmqtt.sock). Setting a TCPportautomatically switches to TCP mode andhostdefaults to0.0.0.0if omitted. The legacy plaintextapi_keyfield still loads but should be replaced with the hashed format via--genkey.
Remote Server Settings
Authentication: The API key must accompany every MCP call via
Authorization: Bearer <key>,X-API-Key: <key>, or?api_key=<key>. The/statusendpoint intentionally skips authentication so external health probes can call it.Binding: Unix domain sockets are used by default (
/var/run/mcpmqtt.sock). Provide a TCPport(and optionallyhost) to listen on TCP instead; the host defaults to all interfaces.Mount path: The FastMCP Starlette application is mounted at
/mcpStatus endpoint:
GET /statusreturns{ "running": true, "mqtt_connected": <bool> }, exposing reachability and MQTT connectivity.Dependencies: Install FastAPI/uvicorn extras when using remote mode:
pip install "mcpMQTT[remote]".
Topic Patterns and Permissions
Wildcard Support:
+: Single-level wildcard (matches one topic level)#: Multi-level wildcard (matches multiple levels, must be last)
Permissions:
read: Can subscribe to topics and receive messageswrite: Can publish messages to topicsBoth permissions can be combined:
["read", "write"]
Examples:
sensors/+/temperaturematchessensors/room1/temperature,sensors/kitchen/temperatureactuators/#matchesactuators/lights,actuators/lights/room1/brightnessstatus/systemmatches exactlystatus/system
Usage
Running the MCP Server
Using the installed script:
Remote HTTP/UDS mode:
With custom configuration:
Generate a new remote API key (prints to STDOUT once):
MCP Tools
The MCP server provides three tools for MQTT operations:
mqtt_publish
Publish messages to MQTT topics.
mqtt_subscribe
Subscribe to topics and collect messages.
mqtt_read
Subscribe to a topic and wait for a single message.
mqtt_query
Request/response pattern for MQTT communication.
MCP Resources
mcpmqtt://topics/allowed
Get allowed topic patterns with permissions and descriptions.
mcpmqtt://topics/examples
Get examples of how to use topic patterns with wildcards.
Configuration Examples
For detailed configuration examples, see the examples/ folder:
example_config.json- Basic configuration with multiple topic patternsexample_with_logging.json- Configuration with file logging enabled
Examples
MCP Client Integration
This MCP server uses the stdio protocol. This means that it should be launched by your LLM orchestrator.
A typical configuration (mcp.json) may look like the following:
Security Considerations
Keep in mind that this MCP allows an agent to subscribe to and publish to all topics that are exposed to the user associated with him on the MQTT broker. You have to perform fine grained configuration on your MQTT broker to limit which features the MCP can actually access or manipulate.
License
See LICENSE.md