On this page
Sommatic Docs
Open portal

MQTT Client

Publish to MQTT Broker.

View as Markdown
Open in
Input and output Partial io.mqtt Version 1.0.0 Execution: async

Connects to an MQTT broker, publishes one message to a topic and disconnects.

How it works

  1. Resolves the config. connection_id, topic, message and retain (default false) fall back to the same keys of the incoming payload; the first three are required.
  2. Resolves the credential: the broker URL is config.url, or mqtt://<config.host>:<config.port> (port default 1883); username and password come from the secret when present.
  3. Connects, publishes message to topic with the retain flag, and closes the connection.
  4. Returns { result: { published: true, topic } } through out; any failure leaves through error.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-publish-command",
  "label": "Publish line command",
  "operator_slug": "io.mqtt",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "topic": "plant/line-2/commands",
    "message": "{{ JSON.stringify($json.command) }}",
    "retain": false
  }
}

Configuration

connection_id string Required

Credential for the MQTT broker. Accepts credentials of type `basic-auth` (username + password + host + port), `connection-string` (mqtt:// / mqtts:// URI), or `object` (advanced MQTT config).

topic string Required
message string Required

Message payload

retain boolean Optional

Default: false

action string Optional

Default: publish

Allowed values: publish

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

connection_id
The broker address comes from the credential config (url, or host + port); username and password from an object secret (basic-auth, object). A connection-string secret is not parsed: put the URI in the credential config url. A value starting with mqtt://, mqtts://, ws:// or wss:// is used as the broker URL itself, without credentials.
action
Ignored: the node always publishes. Subscribing is not supported.
message
Sent as the raw payload. To publish JSON, build the string first, for example {{ JSON.stringify($json.command) }}.

Output ports

out default

The broker accepted the publish.

Data
{
  "result": {
    "published": true,
    "topic": "plant/line-2/commands"
  }
}
error

A required field is missing, the credential cannot be resolved, or the connection or publish failed.

Data
{
  "error": "connect ECONNREFUSED 203.0.113.10:1883"
}

In expressions

What a later node can read from this node's output with $("MQTT Client").item.json.<path> (write your node's label instead of MQTT Client). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through out, from the output shown in Ports.

ExpressionEditorWorker
$("MQTT Client").item.json.publishedbooleanThe worker does not return it: reads as undefinedPublish success —
$("MQTT Client").item.json.resultobjectNot suggested by the editor= {…}—
$("MQTT Client").item.json.result.publishedbooleanNot suggested by the editor= true—
$("MQTT Client").item.json.result.topicstringNot suggested by the editor= "plant/line-2/commands"—

— Editor: The editor suggests it, but the worker does not return it: it reads as undefined.

— Worker: The worker returns it but the editor does not suggest it: write it by hand. Keys inside objects can depend on your data or configuration (for example one key per label).

Errors

Message Port Cause and fix
connection_id is required error No broker credential selected.
topic is required error The topic is empty in the config and in the incoming payload.
message is required error The message is empty. An empty string also fails: publish at least one character.
Connection refused: Not authorized error The broker rejected the user or password in the credential.

Input contract

connection_id string Required
topic string Required
message string Required
retain boolean Optional
action string Optional

Output contract

published boolean Optional

Publish success

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "io.mqtt",
  "name": "MQTT Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Publish to MQTT Broker.",
  "capabilities": [
    "mqtt",
    "iot",
    "messaging"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "MQTT Broker Credential",
        "description": "Credential for the MQTT broker. Accepts credentials of type `basic-auth` (username + password + host + port), `connection-string` (mqtt:// / mqtts:// URI), or `object` (advanced MQTT config).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "basic-auth",
            "connection-string",
            "object"
          ],
          "types": [
            "mqtt"
          ]
        }
      },
      "topic": {
        "type": "string"
      },
      "message": {
        "type": "string",
        "description": "Message payload"
      },
      "retain": {
        "type": "boolean",
        "default": false
      },
      "action": {
        "type": "string",
        "enum": [
          "publish"
        ],
        "default": "publish"
      }
    },
    "required": [
      "connection_id",
      "topic",
      "message"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "topic": {
        "type": "string"
      },
      "message": {
        "type": "string"
      },
      "retain": {
        "type": "boolean"
      },
      "action": {
        "type": "string"
      }
    },
    "required": [
      "connection_id",
      "topic",
      "message"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "published": {
        "type": "boolean",
        "description": "Publish success"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Published",
      "description": "Message successfully published",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Publish failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "iot"
  ],
  "tags": [
    "iot",
    "messaging"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

Execution

Execution
async
Stateful
No
Credentials
Resolved on the server from connection_id; the secret never reaches the workflow.
Capabilities
mqttiotmessaging
Tags
iotmessaging

Notes and limits

  • Publishes with the client's default QoS 0; no QoS option is exposed. A new connection is opened and closed on every run.
  • The output contract declares published at the top level; the worker returns it inside result.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs