MCPcopy Index your code
hub / github.com/LabOverWire/mqtt-lib

github.com/LabOverWire/mqtt-lib @v0.35.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.35.1 ↗ · + Follow
5,105 symbols 17,413 edges 371 files 609 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Complete MQTT Platform

Crates.io Documentation Rust CI License Ask DeepWiki

A production-ready MQTT v5.0 and v3.1.1 platform that ships a client library, a multi-transport broker, and a protocol crate for embedded systems — all from the same codebase. Whether you need a cloud-connected IoT client, a self-hosted broker with QUIC multistream, or a no_std packet parser for bare-metal firmware, this platform covers it.

Dual Architecture: Client + Broker

Component Use Case Key Features
MQTT Broker Run your own MQTT infrastructure TLS, WebSocket, QUIC, Authentication, Bridging, Monitoring
MQTT Client Connect to any MQTT broker Cloud compatible, QUIC multistream, Auto-reconnect, Mock testing
Protocol (no_std) Embedded IoT devices ARM Cortex-M, RISC-V, ESP32, bare-metal compatible

Installation

Library Crate

[dependencies]
mqtt5 = "0.31"

CLI Tool

cargo install mqttv5-cli

Crate Organization

The platform is organized into four crates:

  • mqtt5-protocol - Platform-agnostic MQTT v5.0 core (packets, types, Transport trait). Supports no_std for embedded targets.
  • mqtt5 - Native client and broker for Linux, macOS, Windows
  • mqtt5-wasm - WebAssembly client and broker for browsers
  • mqtt5-conformance - OASIS specification conformance test suite (183 automated tests, 247 normative statements)

Quick Start

Start an MQTT Broker

use mqtt5::broker::{BrokerConfig, MqttBroker};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut broker = MqttBroker::bind("0.0.0.0:1883").await?;

    println!("MQTT broker running on port 1883");

    broker.run().await?;
    Ok(())
}

Connect a Client

use mqtt5::{MqttClient, QoS};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = MqttClient::new("my-device-001");

    // Multiple transport options:
    client.connect("mqtt://localhost:1883").await?;        // TCP
    // client.connect("mqtts://localhost:8883").await?;    // TLS
    // client.connect("ws://localhost:8080/mqtt").await?;  // WebSocket
    // client.connect("quic://localhost:14567").await?;    // QUIC

    // Subscribe with callback
    client.subscribe("sensors/+/data", |msg| {
        println!("{}: {}", msg.topic, String::from_utf8_lossy(&msg.payload));
    }).await?;

    // Publish a message
    client.publish("sensors/temp/data", b"25.5°C").await?;

    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
    Ok(())
}

Command Line Interface (mqttv5)

Single binary with pub, sub, broker, bench, passwd, acl, and scram commands. Supports interactive prompts, input validation, and all transport types.

cargo install mqttv5-cli

mqttv5 broker --host 0.0.0.0:1883
mqttv5 pub --topic "sensors/temperature" --message "23.5"
mqttv5 sub --topic "sensors/+" --verbose

See the CLI Crate Reference and CLI Usage Guide for the full command reference.

Features at a Glance

Broker

The broker supports multiple transports (TCP, TLS, WebSocket, QUIC) in a single binary, built-in authentication (password, SCRAM, JWT, federated JWT), resource monitoring, change-only delivery, load balancer mode, broker-to-broker bridging with loop prevention, event hooks, and OpenTelemetry distributed tracing.

See the mqtt5 Crate Reference for detailed broker capabilities and configuration examples.

Client

The client supports automatic reconnection with exponential backoff, cloud MQTT broker compatibility (AWS IoT, Azure IoT Hub), QUIC multistream with connection migration, mockable client interface for unit testing, and callback-based message handling.

See the mqtt5 Crate Reference for detailed client capabilities, AWS IoT examples, and mock testing patterns.

QUIC Transport

MQTT over QUIC provides built-in TLS 1.3, multistream support with configurable strategies (ControlOnly, DataPerPublish, DataPerTopic), connection migration for mobile clients, and flow headers for session state recovery.

See the QUIC Transport Guide for stream strategies, configuration, and migration usage.

WASM Browser Support

WebAssembly builds for browser environments with three deployment modes: external broker (WebSocket), in-tab broker (MessagePort), and cross-tab communication (BroadcastChannel).

See the mqtt5-wasm Crate Reference and WASM Usage Guide for API reference and framework integration.

Embedded Support (no_std)

The mqtt5-protocol crate supports no_std environments for embedded systems including ARM Cortex-M, RISC-V, and ESP32 targets with configurable time provider for hardware timers.

See the mqtt5-protocol Crate Reference for embedded usage and time provider setup.

Authentication & Security

Four authentication methods (Password, SCRAM-SHA-256, JWT, Federated JWT), role-based access control with topic-level permissions, composite auth provider chaining, session-to-user binding, and comprehensive transport security.

See the Authentication & Authorization Guide for configuration details and security hardening.

Conformance Testing

The conformance test suite validates any MQTT v5.0 broker against the OASIS specification. Create a TOML descriptor for your broker and run the CLI runner:

cargo build --release -p mqtt5-conformance-cli
./target/release/mqtt5-conformance --sut your-broker.toml --report report.json

See the Conformance Test Suite for test organization and architecture, and the CLI Reference for the full SUT descriptor schema and report format.

Publications

  • Evaluating Stream Mapping Strategies for MQTT over QUIC — Computer Networks (Elsevier), 2026. Defines three stream mapping strategies (control-only, per-topic, per-publish) and evaluates them across five experiments on GCP infrastructure. Experiment data archived at Zenodo. See the paper directory on GitHub for the paper, experiment scripts, and reproduction guide.

License

This project is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Documentation

Extension points exported contracts — how you extend this code

MqttPacket (Interface)
Trait for MQTT packets [11 implementers]
crates/mqtt5-protocol/src/packet.rs
AuthProvider (Interface)
Authentication provider trait [16 implementers]
crates/mqtt5/src/broker/auth/mod.rs
Transport (Interface)
A byte-oriented transport that speaks raw MQTT packets. Implementations must be `Send + Unpin` so tests can move them a [1 …
crates/mqtt5-conformance/src/transport.rs
WasmPayloadCodec (Interface)
(no doc) [2 implementers]
crates/mqtt5-wasm/src/codec/mod.rs
Transport (Interface)
(no doc) [11 implementers]
crates/mqtt5-protocol/src/transport.rs
TestPacketBuilder (Interface)
Helper trait for building test packets [5 implementers]
crates/mqtt5/src/test_utils.rs
ReadExact (Interface)
(no doc) [1 implementers]
crates/mqtt5-wasm/src/decoder.rs
TopicValidator (Interface)
Trait for pluggable topic validation This trait allows customization of topic validation rules beyond the standard MQTT [3 …
crates/mqtt5-protocol/src/validation/mod.rs

Core symbols most depended-on inside this repo

clone
called by 683
crates/mqtt5/src/transport/tls.rs
disconnect
called by 314
crates/mqtt5/src/client/mod.rs
connect
called by 274
crates/mqtt5/src/client/mod.rs
len
called by 240
crates/mqtt5/src/session/quic_flow.rs
send_raw
called by 236
crates/mqtt5-conformance/src/raw_client.rs
len
called by 225
crates/mqtt5-protocol/src/session/queue.rs
subscribe
called by 195
crates/mqtt5/src/client/mod.rs
clone
called by 185
crates/mqtt5-wasm/src/config.rs

Shape

Method 2,407
Function 2,231
Class 352
Enum 96
Interface 19

Languages

Rust96%
Python3%
TypeScript1%

Modules by API surface

crates/mqtt5-conformance/src/raw_client.rs113 symbols
crates/mqtt5/src/session/state.rs95 symbols
crates/mqtt5-wasm/src/config.rs89 symbols
crates/mqtt5/src/broker/acl/mod.rs76 symbols
crates/mqtt5-wasm/src/broker.rs73 symbols
crates/mqttv5-cli/src/commands/bench_cmd.rs72 symbols
crates/mqtt5/src/broker/router.rs65 symbols
crates/mqtt5/src/client/direct/mod.rs59 symbols
crates/mqtt5/src/broker/storage/mod.rs58 symbols
crates/mqtt5/src/session/quic_flow.rs54 symbols
crates/mqtt5/src/transport/websocket.rs51 symbols
crates/mqtt5/src/broker/server.rs50 symbols

For agents

$ claude mcp add mqtt-lib \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact