Provides comprehensive MQTT broker operations including publishing messages, subscribing to topics with wildcard support, and implementing request/response patterns with fine-grained topic permissions
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.
Features
- MCP Server Interface: MCP server implementation for MQTT operations
- Topic Permissions: Fine-grained read/write permissions with MQTT wildcard support (
+
and#
) - Authentication: MQTT broker authentication support
- Discoverable: MCP resources for topic discovery and examples
- Configurable: JSON-based configuration with schema validation
- Async Support: Full async/await support for non-blocking operations
Architecture
Installation
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:
Configuration Sections
mqtt
: MQTT broker connection settingstopics
: Topic patterns with permissions and descriptionslogging
: Application logging level
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 topics- Both permissions can be combined:
["read", "write"]
Examples:
sensors/+/temperature
matchessensors/room1/temperature
,sensors/kitchen/temperature
actuators/#
matchesactuators/lights
,actuators/lights/room1/brightness
status/system
matches exactlystatus/system
Usage
Running the MCP Server
Using the installed script:
Or using the module directly:
With custom configuration:
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.
Development
Project Structure
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
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables LLM agents to interact with MQTT brokers through publish, subscribe, and query operations. Provides fine-grained topic permissions with wildcard support for secure IoT device communication and sensor data access.
Related MCP Servers
- AsecurityAlicenseAqualityLinks IoT devices to AI large models using the MCP and MQTT protocols, enabling natural language control, real-time AI responses, and complex instruction execution for interconnected IoT devices.Last updated -3272PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that provides LLM Agents with a comprehensive toolset for IP geolocation, network diagnostics, system monitoring, cryptographic operations, and QR code generation.Last updated -1667711TypeScriptApache 2.0
- -securityAlicense-qualityA Model Context Protocol server that enables LLM agents to manage GitHub repositories, issues, pull requests, branches, files, and releases through a standardized interface.Last updated -4639TypeScriptApache 2.0
- -securityFlicense-qualityEnables communication and coordination between different LLM agents across multiple systems, allowing specialized agents to collaborate on tasks, share context, and coordinate work through a unified platform.Last updated -6TypeScript