Skip to content

MCP Tools Reference

MCP Tools Reference

mcmqtt provides a comprehensive set of MCP (Model Context Protocol) tools for MQTT operations, broker management, and agent coordination. This reference documents all available tools with their parameters and usage examples.

Connection Management

mqtt_connect

Establish connection to an MQTT broker.

Parameters:

ParameterTypeRequiredDefaultDescription
hoststringYes-Broker hostname or IP address
portintegerNo1883Broker port number
client_idstringNoauto-generatedUnique client identifier
usernamestringNo-Authentication username
passwordstringNo-Authentication password
keepaliveintegerNo60Keep-alive interval in seconds
clean_sessionbooleanNotrueStart with clean session
tlsobjectNo-TLS configuration

Example:

mqtt_connect({
"host": "mqtt.example.com",
"port": 8883,
"client_id": "my-client",
"username": "user123",
"password": "secret",
"keepalive": 30,
"tls": {
"ca_cert": "/path/to/ca.pem",
"cert_file": "/path/to/client.pem",
"key_file": "/path/to/client.key",
"verify_hostname": true
}
})

mqtt_disconnect

Disconnect from the current MQTT broker.

Parameters:

ParameterTypeRequiredDefaultDescription
reason_codeintegerNo0Disconnect reason code
reason_stringstringNo-Human-readable disconnect reason

Example:

mqtt_disconnect({
"reason_code": 0,
"reason_string": "Normal disconnect"
})

mqtt_get_status

Get current connection status and statistics.

Parameters: None

Example:

mqtt_get_status()
# Returns:
{
"connected": true,
"broker": "mqtt.example.com:1883",
"client_id": "my-client",
"uptime": "01:23:45",
"messages_sent": 1247,
"messages_received": 3891,
"subscriptions": [
{"topic": "sensors/+/temp", "qos": 1},
{"topic": "alerts/#", "qos": 2}
],
"last_activity": "2024-01-15T10:30:00Z"
}

Messaging Operations

mqtt_publish

Publish a message to an MQTT topic.

Parameters:

ParameterTypeRequiredDefaultDescription
topicstringYes-Target topic for the message
payloadanyYes-Message payload (string, object, or binary)
qosintegerNo0Quality of Service level (0, 1, or 2)
retainbooleanNofalseWhether to retain the message
propertiesobjectNo-MQTT 5.0 properties

Example:

# Simple text message
mqtt_publish({
"topic": "devices/sensor1/temperature",
"payload": "23.5",
"qos": 1,
"retain": true
})
# JSON payload
mqtt_publish({
"topic": "events/user-action",
"payload": {
"user_id": "user123",
"action": "login",
"timestamp": "2024-01-15T10:30:00Z"
},
"qos": 2
})
# With MQTT 5.0 properties
mqtt_publish({
"topic": "data/stream",
"payload": {"value": 42},
"qos": 1,
"properties": {
"message_expiry_interval": 300,
"content_type": "application/json",
"user_properties": [
{"key": "source", "value": "sensor-network"},
{"key": "priority", "value": "high"}
]
}
})

mqtt_subscribe

Subscribe to one or more MQTT topics.

Parameters:

ParameterTypeRequiredDefaultDescription
topicstringYes-Topic pattern to subscribe to
qosintegerNo0Quality of Service level
no_localbooleanNofalseDon’t receive own messages (MQTT 5.0)
retain_as_publishedbooleanNofalseKeep original retain flag
retain_handlingintegerNo0Retain handling option (0, 1, or 2)

Example:

# Simple subscription
mqtt_subscribe({
"topic": "sensors/temperature",
"qos": 1
})
# Wildcard subscriptions
mqtt_subscribe({
"topic": "devices/+/status", # + matches one level
"qos": 2
})
mqtt_subscribe({
"topic": "events/#", # # matches multiple levels
"qos": 0
})
# MQTT 5.0 options
mqtt_subscribe({
"topic": "commands/device123",
"qos": 1,
"no_local": true,
"retain_handling": 1
})

mqtt_unsubscribe

Unsubscribe from MQTT topics.

Parameters:

ParameterTypeRequiredDefaultDescription
topicstring or arrayYes-Topic(s) to unsubscribe from

Example:

# Unsubscribe from single topic
mqtt_unsubscribe({
"topic": "sensors/temperature"
})
# Unsubscribe from multiple topics
mqtt_unsubscribe({
"topic": ["sensors/+/temp", "alerts/#", "commands/device123"]
})

Broker Management

spawn_mqtt_broker

Create and start a new MQTT broker instance.

Parameters:

ParameterTypeRequiredDefaultDescription
portintegerNo1883Port for the broker to listen on
hoststringNo”localhost”Host interface to bind to
configobjectNo{}Broker configuration options
persistencebooleanNofalseEnable message persistence
authobjectNo-Authentication configuration

Example:

# Basic broker
spawn_mqtt_broker({
"port": 1884,
"config": {
"allow_anonymous": true,
"max_connections": 100
}
})
# Advanced configuration
spawn_mqtt_broker({
"port": 8883,
"host": "0.0.0.0",
"config": {
"allow_anonymous": false,
"max_connections": 1000,
"max_inflight_messages": 20,
"message_size_limit": "1MB",
"keepalive_timeout": 60,
"session_expiry_interval": 3600
},
"persistence": true,
"auth": {
"username_password": {
"admin": "secure_password",
"client1": "client_password"
},
"acl": [
{"username": "admin", "topic": "#", "access": "readwrite"},
{"username": "client1", "topic": "devices/+", "access": "read"}
]
}
})

list_mqtt_brokers

List all managed MQTT broker instances.

Parameters: None

Example:

list_mqtt_brokers()
# Returns:
[
{
"id": "broker_001",
"host": "localhost",
"port": 1883,
"status": "running",
"uptime": "2h 34m 18s",
"connections": 23,
"messages_per_second": 145,
"memory_usage": "45MB"
},
{
"id": "broker_002",
"host": "0.0.0.0",
"port": 8883,
"status": "running",
"uptime": "5d 12h 7m",
"connections": 387,
"messages_per_second": 2847,
"memory_usage": "234MB"
}
]

stop_mqtt_broker

Stop a managed MQTT broker instance.

Parameters:

ParameterTypeRequiredDefaultDescription
broker_idstringYes-ID of the broker to stop
gracefulbooleanNotrueWhether to stop gracefully
timeoutintegerNo30Timeout for graceful shutdown

Example:

stop_mqtt_broker({
"broker_id": "broker_001",
"graceful": true,
"timeout": 10
})

Agent Coordination

swarm_deploy

Deploy a swarm of coordinated agents.

Parameters:

ParameterTypeRequiredDefaultDescription
namestringYes-Unique swarm identifier
agent_typestringYes-Type of agents to deploy
countintegerYes-Number of agents in the swarm
configobjectNo{}Agent configuration
resourcesobjectNo{}Resource limits per agent
coordinationobjectNo{}Coordination settings

Example:

swarm_deploy({
"name": "browser-test-swarm",
"agent_type": "browser-test",
"count": 10,
"config": {
"target": "https://my-app.com",
"browser": "chrome",
"headless": true,
"scenarios": ["login", "purchase", "search"]
},
"resources": {
"memory": "512MB",
"cpu": "0.5",
"disk": "1GB"
},
"coordination": {
"pattern": "worker-pool",
"load_balancing": "round-robin",
"health_check_interval": 30
}
})

swarm_status

Get status information for a deployed swarm.

Parameters:

ParameterTypeRequiredDefaultDescription
swarm_namestringYes-Name of the swarm to check

Example:

swarm_status({
"swarm_name": "browser-test-swarm"
})
# Returns:
{
"name": "browser-test-swarm",
"status": "running",
"agents": {
"total": 10,
"healthy": 9,
"unhealthy": 1,
"starting": 0
},
"tasks": {
"completed": 1247,
"in_progress": 15,
"failed": 23,
"queued": 8
},
"performance": {
"average_response_time": "245ms",
"success_rate": "98.2%",
"throughput": "42 tasks/min"
},
"resources": {
"memory_usage": "4.2GB/5.0GB",
"cpu_usage": "67%",
"network_io": "15MB/s"
}
}

swarm_scale

Scale a swarm up or down.

Parameters:

ParameterTypeRequiredDefaultDescription
swarm_namestringYes-Name of the swarm to scale
countintegerYes-New agent count
strategystringNo”gradual”Scaling strategy (“gradual” or “immediate”)

Example:

# Scale up gradually
swarm_scale({
"swarm_name": "browser-test-swarm",
"count": 15,
"strategy": "gradual"
})
# Scale down immediately
swarm_scale({
"swarm_name": "api-test-swarm",
"count": 5,
"strategy": "immediate"
})

swarm_stop

Stop and remove a swarm.

Parameters:

ParameterTypeRequiredDefaultDescription
swarm_namestringYes-Name of the swarm to stop
gracefulbooleanNotrueWhether to stop gracefully
timeoutintegerNo60Timeout for graceful shutdown

Example:

swarm_stop({
"swarm_name": "browser-test-swarm",
"graceful": true,
"timeout": 30
})

Monitoring and Diagnostics

mqtt_monitor_topics

Monitor activity on specific topics.

Parameters:

ParameterTypeRequiredDefaultDescription
topicsarrayYes-Topics to monitor
durationintegerNo60Monitoring duration in seconds
sample_ratenumberNo1.0Sampling rate (0.0 - 1.0)

Example:

mqtt_monitor_topics({
"topics": ["sensors/+/temp", "alerts/#"],
"duration": 300,
"sample_rate": 0.1 # Monitor 10% of messages
})

mqtt_get_metrics

Get detailed MQTT performance metrics.

Parameters:

ParameterTypeRequiredDefaultDescription
time_rangestringNo”1h”Time range for metrics
granularitystringNo”1m”Data point granularity

Example:

mqtt_get_metrics({
"time_range": "24h",
"granularity": "1h"
})
# Returns detailed performance metrics
{
"time_range": "24h",
"metrics": {
"messages_per_second": [...],
"connection_count": [...],
"latency_p95": [...],
"error_rate": [...]
}
}

Error Handling

All MCP tools return standardized error responses:

# Error response format
{
"error": {
"code": "MQTT_CONNECTION_FAILED",
"message": "Failed to connect to broker at mqtt.example.com:1883",
"details": {
"host": "mqtt.example.com",
"port": 1883,
"reason": "Connection refused"
},
"timestamp": "2024-01-15T10:30:00Z"
}
}

Common error codes:

  • MQTT_CONNECTION_FAILED - Broker connection issues
  • MQTT_AUTHENTICATION_FAILED - Invalid credentials
  • MQTT_SUBSCRIPTION_FAILED - Topic subscription issues
  • MQTT_PUBLISH_FAILED - Message publishing issues
  • BROKER_SPAWN_FAILED - Broker creation issues
  • SWARM_DEPLOYMENT_FAILED - Agent swarm deployment issues
  • INVALID_PARAMETERS - Invalid tool parameters

This reference covers all mcmqtt MCP tools. For more examples and advanced usage patterns, see the How-to Guides and Tutorials.