mqtt-mcp

mqtt-mcp

MCP server that bridges MQTT sensor data to MCP, allowing clients to query cached sensor readings and send commands via tools like list_topics, read_topic, and publish.

Category
Visit Server

README

mqtt-mcp

An MQTT to MCP bridge. Devices publish sensor readings to a Mosquitto broker; this server subscribes in the background, caches the last message per topic, and exposes that cache as MCP tools over streamable HTTP. Any MCP client (n8n's MCP Client Tool, Claude Code, the MCP Inspector) can then ask questions like "what is the CO2 in the office?" or send commands back to devices.

ESP32s --publish--> Mosquitto <--subscribe/publish-- mqtt-mcp (this server)
                                                          ^ streamable HTTP :8000/mcp
                                             n8n AI Agent / Claude Code

Tools

Tool What it does
list_topics(prefix="") Topics seen since start, with last payload, age, and count
read_topic(topic) Last message on an exact topic
publish(topic, payload) Send a command; restricted to topics under cmd/
bridge_status() Broker connection state, for telling outages apart from silent devices

The cache is in memory only. After a restart it refills as devices publish (retained messages arrive immediately on reconnect).

Topic conventions

  • sensors/aircube/<metric> for the aircube readings (temperature, co2, humidity)
  • sensors/espcam/<metric> reserved for the FireBeetle + ESP32-CAM vision project
  • cmd/<device>/<action> for commands; only this prefix is writable through MCP

Server setup (Docker host)

  1. Clone, then create broker credentials (writes mosquitto/config/passwd):

    docker compose run --rm mosquitto mosquitto_passwd -c -b /mosquitto/config/passwd mqtt <password>
    
  2. Copy .env.example to .env and fill in the same username and password.

  3. docker compose up -d --build

Mosquitto listens on 1883 (devices connect there), the MCP endpoint is http://<host>:8000/mcp. Neither has TLS and the MCP endpoint has no auth, so keep both LAN-only.

If 8000 or 1883 is already taken on the host, set MCP_HOST_PORT and/or MQTT_HOST_PORT in .env (e.g. MCP_HOST_PORT=8090, MQTT_HOST_PORT=1884) instead of editing docker-compose.yml. The containers still listen on 8000 and 1883 internally; only the LAN-facing published ports change, so devices then connect to the broker at <host>:<MQTT_HOST_PORT>.

If ufw is enabled on the host, open both ports (use the published ports you actually set):

sudo ufw allow 1883/tcp comment 'mosquitto mqtt'
sudo ufw allow 8000/tcp comment 'mqtt-mcp streamable http'
sudo ufw status

Local development (Mac)

MQTT_HOST=<broker-ip> MQTT_USERNAME=mqtt MQTT_PASSWORD=<password> uv run server.py

In a second terminal, generate traffic:

MQTT_HOST=<broker-ip> MQTT_USERNAME=mqtt MQTT_PASSWORD=<password> uv run scripts/fake_sensor.py

Then poke at the tools with the MCP Inspector:

npx @modelcontextprotocol/inspector
# transport: Streamable HTTP, URL: http://localhost:8000/mcp

Connecting from n8n

Add an AI Agent node and attach an MCP Client Tool pointed at http://<host>:8000/mcp (or your published MCP_HOST_PORT).

Set the transport to "HTTP Streamable". This server speaks streamable HTTP only, not SSE. If the node is left on the SSE transport (the default in some versions), the connection fails with SSE error: Non-200 status code (404) because there is no /sse endpoint. Switching the transport to HTTP Streamable fixes it. Verified on n8n 2.28.6.

Note that n8n and this bridge usually run as separate Docker stacks on the same host, so n8n reaches the bridge over the host, not by container name: use the host's LAN IP (e.g. http://192.168.1.50:8075/mcp), not http://mqtt-mcp:8000.

A ready-to-import example workflow (Chat Trigger, AI Agent, Ollama model, MCP client) is in examples/n8n-aircube-agent.json. Import it, then set two things: the MCP endpoint URL (your host LAN IP + port) and the Ollama model — which must support tool calling (e.g. llama3.1, qwen2.5), or the agent will chat without ever invoking the tools.

Configuration

All via environment variables, read in server.py:

Variable Default Purpose
MQTT_HOST localhost Broker hostname
MQTT_PORT 1883 Broker port
MQTT_USERNAME / MQTT_PASSWORD unset Broker credentials
CMD_PREFIX cmd/ Only prefix the publish tool may write to
MCP_HOST 0.0.0.0 MCP listen address
MCP_PORT 8000 MCP listen port

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured