Mosquitto CLI
$ mosquitto_pub Foundation Low Riskmosquitto_pub is the reference C command-line MQTT 3.1/3.1.1/5.0 publisher from Eclipse Mosquitto (paired with mosquitto_sub for subscribing). Supports QoS levels (-q 0|1|2), retained messages (-r), TLS certs (--cafile), and single-shot publish-and-exit execution.
brew install mosquitto mosquitto_pub executes sub-10ms single-shot MQTT publishes with -m or -s (stdin) and has no MCP equivalent.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Single-shot mosquitto_pub exits cleanly with clear exit codes, though it has no JSON diagnostic wrapper and companion mosquitto_sub hangs unless -C/-W are passed.
- Non-interactive single-shot publish via
-mor-s - No JSON output envelope
Supports TLS mTLS flags (--cafile, --cert, --key) and explicit -r retain flag, though -P on CLI can leak in process lists and no --dry-run exists.
- Full TLS/mTLS support; lacks
--dry-run
Tiny native C binary available in virtually every Linux distro repo (apt, apk), Homebrew, and Windows installers.
- Ubiquitous package availability via
brew install mosquittoand OS repos
Focused single-purpose MQTT publisher; needs companion mosquitto_sub for reading and lacks benchmarking or payload formatting.
- Publish-only binary (
mosquitto_subis separate)
Maintained by the Eclipse Foundation (eclipse-mosquitto/mosquitto) under EPL-2.0 / EDL-1.0.
- Official Eclipse Foundation project
Classic Unix manpage (mosquitto_pub(1)) covers every flag accurately, though terse for quick examples.
- Official manpage at mosquitto.org/man/mosquitto_pub-1.html
Security, Auth & Guardrails
Reads defaults from ~/.config/mosquitto_pub (if configured) or receives -u/-P credentials and --cafile/--cert/--key TLS flags per invocation.
Dual-licensed EPL-2.0 / EDL-1.0 open-source by the Eclipse Foundation; free to use.
# Mosquitto CLI Agent Rules - Always bound companion `mosquitto_sub` calls with `-C <count>` and `-W <timeout_sec>` so reads exit cleanly. - Never pass `-r` (retained) or `-n` (clear retained) on shared topics without explicit user approval.
Agent-Ready Command Recipes
Safe Read-Only Queries
mosquitto_sub -h localhost -t 'sensors/+/temp' -C 1 -W 5 -v
Uses companion mosquitto_sub with -C 1 and -W 5 timeout to safely read at most 1 message without hanging.
Controlled Writes & Previews
mosquitto_pub -h localhost -t 'sensors/room1/cmd' -q 1 -m '{"state":"ping"}' Publishes a single message with QoS 1 delivery acknowledgment and exits.
Strengths for Agents
- + Instant startup C binary available on nearly every OS and container image.
- + Clean single-shot publish semantics (
-h,-t,-m,-q) with MQTT 5.0 support (-V 5). - + Supports stdin piping (
-s) and TLS mutual authentication.
Caveats & Pitfalls
- ! Publish-only binary—reading messages requires companion
mosquitto_subwith-C/-Wbounds. - ! Passing
-P <password>on the command line exposes credentials inpsoutput.