# ๐Ÿš€ mcmqtt - FastMCP MQTT Server **The most powerful FastMCP MQTT integration server on the planet** ๐ŸŒ [![Version](https://img.shields.io/badge/version-2025.09.17-blue.svg)](https://pypi.org/project/mcmqtt/) [![Python](https://img.shields.io/badge/python-3.11+-green.svg)](https://python.org) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Tests](https://img.shields.io/badge/tests-70%20passing-brightgreen.svg)](#testing) [![Coverage](https://img.shields.io/badge/coverage-96%25+-brightgreen.svg)](#coverage) > **Enabling MQTT integration for MCP clients with embedded broker support and fractal agent orchestration** ## โœจ Key Features - ๐Ÿ”ฅ **FastMCP Integration**: Native Model Context Protocol server with MQTT tools - โšก **Embedded MQTT Brokers**: Spawn brokers on-demand with zero configuration - ๐Ÿ—๏ธ **Modular Architecture**: Clean, testable, maintainable codebase - ๐Ÿงช **Comprehensive Testing**: 70+ tests with 96%+ coverage on core modules - ๐ŸŒ **Cross-Platform**: Designed for Linux, macOS, and Windows (TODO: Test on additional platforms) - ๐Ÿ”ง **CLI & Programmatic**: Use via command line or integrate into your code - ๐Ÿ“ก **Real-time Coordination**: Perfect for agent swarms and distributed systems ## ๐Ÿš€ Quick Start ### Installation **Recommended: Use `uvx` for instant execution** (no installation needed): ```bash # Run directly with uvx (recommended) uvx mcmqtt --help # Start STDIO server for MCP clients uvx mcmqtt # HTTP mode for web integration uvx mcmqtt --transport http --port 8080 ``` **If you insist on traditional installation**: ```bash # Install with uv uv add mcmqtt # Or use pip pip install mcmqtt ``` ### Instant MQTT Magic ```bash # Start FastMCP MQTT server (default STDIO mode) - Just works! uvx mcmqtt # HTTP mode for web integration uvx mcmqtt --transport http --port 8080 # Connect to existing broker (optional) uvx mcmqtt --mqtt-host mqtt.example.com --mqtt-port 1883 ``` ### MCP Integration Add to your Claude Code MCP configuration: ```bash # Add mcmqtt as an MCP server (zero configuration!) claude mcp add task-buzz -- uvx mcmqtt # Test the connection claude mcp test task-buzz ``` ## โš™๏ธ Configuration Options **Primary Interface: MCP Tools** - mcmqtt is designed for MCP clients to manage connections and brokers dynamically via tool calls. ### Optional CLI & Environment Configuration For startup configuration (when MCP clients need default connectivity): **CLI Options:** ```bash uvx mcmqtt --transport stdio # Default: STDIO mode for MCP uvx mcmqtt --transport http # HTTP mode for web integration uvx mcmqtt --mqtt-host broker.local # Connect to existing broker uvx mcmqtt --auto-connect # Auto-connect on startup ``` **Environment Variables:** ```bash export MQTT_BROKER_HOST="mqtt.example.com" export MQTT_BROKER_PORT="1883" export MQTT_CLIENT_ID="mcmqtt-server" export MQTT_USERNAME="user" export MQTT_PASSWORD="pass" uvx mcmqtt # Uses environment config ``` **MCP clients control everything else** - broker spawning, connections, subscriptions, and message handling via tool calls. ## ๐Ÿ› ๏ธ Core Features ### ๐Ÿƒโ€โ™‚๏ธ FastMCP MQTT Tools - `mqtt_connect` - Connect to MQTT brokers - `mqtt_publish` - Publish messages with QoS support - `mqtt_subscribe` - Subscribe to topics with wildcards - `mqtt_get_messages` - Retrieve received messages - `mqtt_status` - Get connection and statistics - `mqtt_spawn_broker` - Create embedded brokers instantly - `mqtt_list_brokers` - Manage multiple brokers ### ๐Ÿ”ง Embedded Broker Management **MCP clients can spawn MQTT brokers on-demand using the `mqtt_spawn_broker` tool:** ```bash # MCP Tool Call Example { "tool": "mqtt_spawn_broker", "arguments": { "name": "agent-coordination-broker", "port": 1883, "host": "127.0.0.1", "max_connections": 100, "websocket_port": 9001 } } ``` **Response:** ```json { "broker_id": "agent-coordination-broker-1726567890", "host": "127.0.0.1", "port": 1883, "websocket_port": 9001, "status": "running", "mqtt_url": "mqtt://127.0.0.1:1883", "websocket_url": "ws://127.0.0.1:9001" } ``` **Instant broker spawning** - no Docker, no setup, just call the tool and get a running MQTT broker! ### ๐Ÿ“ก MQTT Client Integration **Connect to any MQTT broker using MCP tools:** ```bash # Connect to broker { "tool": "mqtt_connect", "arguments": { "broker_host": "mqtt.example.com", "broker_port": 1883, "client_id": "my-agent", "username": "user", "password": "pass" } } # Publish messages { "tool": "mqtt_publish", "arguments": { "topic": "sensors/temperature", "payload": "23.5", "qos": 1, "retain": false } } # Subscribe to topics { "tool": "mqtt_subscribe", "arguments": { "topic": "sensors/+", "qos": 1 } } # Get messages { "tool": "mqtt_get_messages", "arguments": { "topic": "sensors/temperature", "limit": 10 } } ``` **Zero coding required** - just call MCP tools and coordinate with any MQTT infrastructure! ## ๐Ÿ—๏ธ Architecture Excellence This isn't your typical monolithic MQTT library. mcmqtt features a **clean modular architecture**: ``` mcmqtt/ โ”œโ”€โ”€ cli/ # Command-line interface & argument parsing โ”œโ”€โ”€ config/ # Environment & configuration management โ”œโ”€โ”€ logging/ # Structured logging setup โ”œโ”€โ”€ server/ # STDIO & HTTP server runners โ”œโ”€โ”€ mqtt/ # Core MQTT client functionality โ”œโ”€โ”€ mcp/ # FastMCP server integration โ”œโ”€โ”€ broker/ # Embedded broker management โ””โ”€โ”€ middleware/ # Broker middleware & orchestration ``` ### ๐Ÿงช Testing Excellence - **70+ comprehensive tests** covering all modules - **96%+ code coverage** on refactored components - **Robust mocking** for reliable CI/CD - **Edge case coverage** for production reliability ## ๐ŸŒŸ Real-World Use Cases ### ๐Ÿค– AI Agent Orchestration & Swarm Coordination **Fractal Agent Architecture**: Build sophisticated agent swarms where parent agents delegate tasks to specialized subagents via MQTT messaging. ```bash # 1. Setup mcmqtt as MCP server for agent coordination claude mcp add task-buzz -- uvx mcmqtt # 2. Now parent Claude Code agents can coordinate with subagents ``` **Example: Multi-Agent Code Analysis Workflow** ```bash # Parent Agent (you) delegates analysis tasks via MQTT: # 1. Spawn embedded broker for coordination mqtt_spawn_broker --name "code-analysis" --port 1883 # 2. Create specialized subagents for different domains claude -p "You are a security-analysis-agent. Subscribe to 'tasks/security' topic and analyze code for vulnerabilities. Use mqtt_subscribe and mqtt_publish tools." claude -p "You are a performance-agent. Subscribe to 'tasks/performance' and optimize code. Report results to 'results/performance'." claude -p "You are a test-agent. Subscribe to 'tasks/testing' and write comprehensive tests. Publish coverage to 'results/testing'." # 3. Parent agent coordinates the workflow mqtt_publish --topic "tasks/security" --payload '{"file": "auth.py", "priority": "high"}' mqtt_publish --topic "tasks/performance" --payload '{"file": "database.py", "focus": "query_optimization"}' mqtt_publish --topic "tasks/testing" --payload '{"file": "api.py", "coverage_target": "95%"}' # 4. Monitor results from all agents mqtt_subscribe --topic "results/+" --callback aggregate_analysis_report ``` **Advanced Fractal Patterns:** - **Recursive Task Delegation**: Subagents can spawn their own sub-subagents for complex domains - **Dynamic Load Balancing**: Monitor agent workload via heartbeat topics, redistribute tasks automatically - **Cross-Agent Learning**: Agents share insights via `knowledge/domain` topics - **Fault Tolerance**: Dead agent detection via missed heartbeats, automatic task redistribution **Use Cases:** - **Large Codebase Analysis**: Break down monolith analysis across specialized agents (security, performance, testing, documentation) - **Multi-Language Projects**: Deploy language-specific agents (Python-agent, JavaScript-agent, Rust-agent) - **Distributed Code Review**: Parallel analysis of pull requests with different focuses - **CI/CD Integration**: Agents monitor git hooks, trigger builds, run tests, deploy services ### ๐Ÿ“Š Real-Time IoT & Sensor Data Processing **Zero-Config IoT Integration**: Perfect for collecting, processing, and routing sensor data without complex infrastructure. ```bash # Example: Temperature monitoring system # 1. Start mcmqtt server uvx mcmqtt # 2. Use MCP tools to: # - Subscribe to sensors/+/temperature # - Publish alerts to alerts/high-temp # - Forward to analytics/warehouse ``` **Use Cases:** - **Smart building automation**: Collect data from thermostats, motion sensors, lighting systems - **Industrial monitoring**: Equipment health, production metrics, safety alerts - **Environmental tracking**: Weather stations, air quality monitors, noise levels - **Agricultural IoT**: Soil moisture, crop monitoring, automated irrigation ### ๐Ÿ”„ Microservice Event Streaming **Service Mesh Communication**: Replace complex message queues with simple MQTT patterns for microservice coordination. ```bash # Start dedicated MQTT server for service mesh uvx mcmqtt --transport http --port 8080 # Services communicate via MQTT topics: # - orders/created, orders/fulfilled # - payments/processed, payments/failed # - inventory/updated, inventory/low-stock ``` **Use Cases:** - **Event sourcing**: Capture all state changes as MQTT events for audit trails - **Saga patterns**: Coordinate complex business transactions across multiple services - **Cache invalidation**: Notify services when shared data changes - **Health monitoring**: Services publish heartbeats and status updates ### ๐ŸŽฎ Real-Time Gaming & Live Applications **Low-Latency Messaging**: Build multiplayer games, live chat, and real-time collaboration tools. ```bash # Game server coordination claude mcp add game-events -- uvx mcmqtt --transport http ``` **Use Cases:** - **Multiplayer game state**: Player positions, actions, world updates - **Live chat systems**: Message broadcasting, user presence, typing indicators - **Collaborative editing**: Document changes, cursor positions, user selections - **Live streaming**: Chat messages, viewer counts, donations, moderation events ### ๐Ÿญ DevOps & Infrastructure Automation **Deployment Orchestration**: Coordinate deployments, monitoring, and incident response across infrastructure. ```bash # Infrastructure coordination uvx mcmqtt --mqtt-host production-mqtt.company.com ``` **Use Cases:** - **CI/CD pipelines**: Build status, deployment triggers, rollback coordination - **Container orchestration**: Service discovery, load balancer updates, scaling events - **Monitoring alerts**: Error spikes, performance degradation, security incidents - **Backup coordination**: Database snapshots, file synchronization, disaster recovery ### ๐Ÿ›๏ธ E-commerce & Business Process Automation **Order Processing Workflows**: Handle complex business processes with event-driven patterns. **Use Cases:** - **Order fulfillment**: Inventory checks โ†’ payment processing โ†’ shipping โ†’ delivery notifications - **Customer journey**: Cart abandonment โ†’ email campaigns โ†’ purchase โ†’ support follow-up - **Supply chain**: Supplier updates โ†’ inventory management โ†’ demand forecasting - **Fraud detection**: Transaction monitoring โ†’ risk scoring โ†’ manual review triggers ### ๐Ÿ“ฑ Mobile & Edge Computing **Offline-First Applications**: Handle intermittent connectivity and edge computing scenarios. **Use Cases:** - **Mobile app synchronization**: User data, settings, offline queue processing - **Edge device coordination**: Factory floor devices, retail kiosks, field equipment - **Bandwidth optimization**: Intelligent data batching, compression, prioritization - **Mesh networking**: Device-to-device communication, local data processing ### ๐Ÿง  Multi-Model AI Orchestration & MCP Server Coordination **The Ultimate AI Party**: Coordinate different AI models, MCP servers, and specialized tools through MQTT messaging for complex multi-step workflows. ```bash # Setup the coordination hub claude mcp add task-buzz -- uvx mcmqtt # Add your MCP server friends to the party claude mcp add web-search -- uvx mcp-server-fetch claude mcp add code-search -- uvx searchmcp claude mcp add file-ops -- uvx mcp-server-filesystem claude mcp add db-query -- uvx mcp-server-sqlite claude mcp add memory-store -- uvx mcp-server-memory claude mcp add brave-search -- uvx mcp-server-brave-search ``` **Example: Multi-Model Research & Analysis Pipeline** ```bash # 1. Coordinator agent orchestrates the entire workflow mqtt_publish --topic "workflow/start" --payload '{ "task": "analyze_ai_trends_2024", "models_needed": ["web_search", "code_analysis", "data_processing", "report_generation"] }' # 2. Web Search Agent (Claude + Brave Search MCP) claude -p "You are web-search-agent. Subscribe to 'tasks/web_search'. Use brave-search tools to find latest AI trends. Publish findings to 'data/web_results'." # 3. Code Analysis Agent (Claude + Code Search MCP) claude -p "You are code-agent. Subscribe to 'tasks/code_analysis'. Use searchmcp to find relevant code examples. Publish to 'data/code_results'." # 4. Data Processing Agent (Claude + SQLite MCP) claude -p "You are data-agent. Subscribe to 'data/+' topics. Use sqlite tools to store and analyze collected data. Publish insights to 'insights/processed'." # 5. Report Generation Agent (Claude + File System MCP) claude -p "You are report-agent. Subscribe to 'insights/+'. Use filesystem tools to generate comprehensive reports. Publish completion to 'workflow/complete'." # Coordinator orchestrates the flow mqtt_publish --topic "tasks/web_search" --payload '{"query": "AI trends 2024", "sources": 10}' mqtt_publish --topic "tasks/code_analysis" --payload '{"focus": "LLM implementation patterns"}' # Monitor progress across all agents mqtt_subscribe --topic "workflow/+" --callback track_pipeline_progress ``` **Advanced Multi-Model Patterns:** **๐Ÿ”„ Model Chaining & Handoffs:** ```bash # GPT-4 for initial analysis โ†’ Claude for code review โ†’ Local model for privacy-sensitive data mqtt_publish --topic "models/gpt4/analyze" --payload '{"data": "public_dataset.json"}' # GPT-4 publishes to models/claude/review โ†’ Claude publishes to models/local/sensitive ``` **๐ŸŽญ Specialized Model Routing:** ```bash # Route different task types to optimal models mqtt_publish --topic "routing/classify" --payload '{"task": "legal_document_analysis"}' # Router sends to models/legal_llm/ vs models/code_llm/ vs models/creative_llm/ ``` **๐Ÿงช A/B Testing & Model Comparison:** ```bash # Send same prompt to multiple models for comparison mqtt_publish --topic "models/compare" --payload '{ "prompt": "Explain quantum computing", "models": ["gpt4", "claude", "gemini", "local-llama"], "evaluation_criteria": ["accuracy", "clarity", "depth"] }' ``` **๐Ÿ”— MCP Server Coordination Examples:** **Database + Web + Memory Pipeline:** ```bash # 1. Brave Search finds information โ†’ SQLite stores โ†’ Memory recalls context mqtt_publish --topic "research/start" --payload '{"topic": "sustainable_energy"}' # Web agent searches and stores brave_search โ†’ mqtt_publish("data/raw") โ†’ sqlite_store โ†’ mqtt_publish("data/indexed") # Memory agent builds context memory_store โ†’ mqtt_publish("context/ready") โ†’ next_agents_process ``` **File System + Code Search + Web Integration:** ```bash # 1. File system agent monitors project changes filesystem_watch โ†’ mqtt_publish("code/changed") # 2. Code search agent analyzes patterns searchmcp_analyze โ†’ mqtt_publish("patterns/found") # 3. Web agent researches best practices web_fetch โ†’ mqtt_publish("best_practices/updated") # 4. Integration agent updates documentation filesystem_write_docs โ†’ mqtt_publish("docs/updated") ``` **Real-World Multi-Model Use Cases:** - **Research Pipeline**: Web search โ†’ document analysis โ†’ data extraction โ†’ report generation - **Code Intelligence**: Repository analysis โ†’ pattern detection โ†’ documentation generation โ†’ test creation - **Content Creation**: Research โ†’ outline โ†’ writing โ†’ fact-checking โ†’ editing โ†’ publishing - **Decision Support**: Data gathering โ†’ analysis โ†’ modeling โ†’ recommendation โ†’ validation - **Quality Assurance**: Multi-model review โ†’ consensus building โ†’ error detection โ†’ improvement suggestions **๐ŸŽช The MCP Server Party Benefits:** - **Specialized Expertise**: Each MCP server brings unique capabilities (web search, file ops, databases, memory) - **Fault Tolerance**: If one model/server fails, workflow continues with others - **Cost Optimization**: Route expensive tasks to premium models, routine tasks to efficient models - **Privacy Layers**: Sensitive data stays with local models, public data uses cloud models - **Scalability**: Add new models and MCP servers without changing existing workflows ## โšก MCP Server Superpowers: Background Automation via MQTT **Transform any MCP server into an event-driven powerhouse!** Instead of just responding to direct calls, existing MCP servers can gain "superpowers" through MQTT coordination: ### ๐Ÿ”„ Background Processing Examples **Google Drive Batch Downloader:** ```bash # MCP Client publishes download queue { "topic": "gdrive/download-queue", "payload": { "files": ["doc1.pdf", "spreadsheet.xlsx", "presentation.pptx"], "destination": "/local/backup/", "batch_id": "backup-2025-09-17" } } # Google Drive MCP server subscribes and processes in background # Publishes progress updates via MQTT { "topic": "gdrive/download-progress", "payload": { "batch_id": "backup-2025-09-17", "completed": 2, "total": 3, "current_file": "presentation.pptx", "status": "downloading" } } ``` **Database Backup Orchestration:** ```bash # Scheduler publishes backup trigger { "topic": "database/backup-trigger", "payload": { "databases": ["users", "orders", "analytics"], "backup_type": "incremental", "schedule_id": "daily-backup" } } # Multiple database MCP servers coordinate the backup # PostgreSQL MCP server handles users & orders # MongoDB MCP server handles analytics # S3 MCP server handles upload coordination ``` **Code Repository Analysis Pipeline:** ```bash # Git webhook triggers analysis { "topic": "code/analysis-request", "payload": { "repo": "github.com/user/project", "commit": "abc123", "analysis_types": ["security", "performance", "documentation"] } } # Specialized MCP servers process in parallel: # - Security scanner MCP server # - Performance analyzer MCP server # - Documentation generator MCP server # Each publishes results to "code/analysis-results/{type}" ``` ### ๐ŸŽฏ Event-Driven MCP Patterns **1. Subscription-Based Processing** - MCP servers subscribe to relevant MQTT topics - Process tasks asynchronously in background - Publish results/progress for other services **2. Workflow Orchestration** - Chain multiple MCP servers via MQTT topics - Each server triggers the next step in the pipeline - Build complex automation without tight coupling **3. Real-Time Coordination** - Multiple MCP servers collaborate on single tasks - Share progress updates via MQTT - Coordinate resource usage and scheduling **4. Event Sourcing & Audit** - All MCP server actions published as MQTT events - Build comprehensive audit trails - Enable replay and debugging capabilities ### ๐Ÿ’ก Existing MCP Servers + MQTT = Superpowers **Transform these common MCP servers:** | Original MCP Server | + MQTT Superpowers | |-------------------|--------------------| | File System MCP | โ†’ Background file sync, automated cleanup, distributed backup | | Database MCP | โ†’ Scheduled migrations, replication monitoring, auto-scaling | | GitHub MCP | โ†’ PR auto-review, CI/CD coordination, issue triaging | | Slack MCP | โ†’ Smart notifications, automated responses, team coordination | | Email MCP | โ†’ Automated campaigns, template processing, delivery tracking | | AWS MCP | โ†’ Infrastructure orchestration, cost optimization, auto-scaling | ### ๐Ÿค Agent "Gathering" Patterns **Multiple MCP clients can access the same MCP server resources via MQTT coordination:** **Example: File Processing Queue** ```bash # File server MCP publishes available files { "topic": "files/processing-queue", "payload": { "file_id": "document_123.pdf", "size": "2.5MB", "type": "pdf", "priority": "high" } } # Multiple agents "gather" and claim work: # - PDF analysis agent subscribes to files/processing-queue # - OCR agent subscribes to files/processing-queue # - Translation agent subscribes to files/processing-queue # First agent to respond gets the work item ``` **Distributed Resource Sharing:** - **Database connections**: Multiple agents share database MCP server via MQTT coordination - **File system access**: Agents coordinate file operations through filesystem MCP + MQTT - **API rate limits**: Share expensive API calls across many agents via API MCP + MQTT - **Computing resources**: Distribute heavy tasks across multiple MCP servers **Long-Running Task Coordination:** ```bash # Agent publishes long-running task request { "topic": "tasks/video-processing", "payload": { "video_url": "https://example.com/video.mp4", "operations": ["transcode", "thumbnail", "metadata"], "callback_topic": "results/video-123" } } # Video processing MCP server handles the work # Other agents subscribe to "results/video-123" for completion ``` **Key Benefits:** - **Resource Multiplexing**: Many MCP clients share expensive MCP server resources - **Distributed Processing**: Long-running tasks don't block individual agents - **Event-Driven Coordination**: Agents "gather" around shared resources via MQTT - **Scalable Architecture**: Add more agents without changing MCP server code - **Fault Tolerance**: If one agent fails, others continue processing - **Real-Time Updates**: Live progress tracking across all participants ## ๐ŸŒ Access the Entire MQTT Ecosystem **Your MCP crew now has access to MILLIONS of MQTT-enabled devices and services worldwide!** ### ๐Ÿญ Industrial & Enterprise Systems **Factory Automation:** ```bash # Monitor production line via industrial MQTT broker { "tool": "mqtt_subscribe", "arguments": { "topic": "factory/line-1/+", "qos": 2 } } # Control robotic assembly via MCP { "tool": "mqtt_publish", "arguments": { "topic": "factory/robot-arm/commands", "payload": { "action": "pick_and_place", "coordinates": [100, 200, 50], "speed": "medium" } } } ``` **Enterprise Message Brokers:** - **AWS IoT Core**: Connect to millions of IoT devices via AWS MQTT - **Azure IoT Hub**: Integrate with Microsoft's IoT ecosystem - **Google Cloud IoT**: Access Google's device management platform - **HiveMQ**: Enterprise-grade MQTT broker integration - **Eclipse Mosquitto**: Open-source MQTT broker networks ### ๐Ÿ  Smart Home & Consumer IoT **Home Automation:** ```bash # Control smart lights via Home Assistant MQTT { "topic": "homeassistant/light/living_room/set", "payload": { "state": "ON", "brightness": 180, "color": {"r": 255, "g": 200, "b": 100} } } # Monitor energy usage { "topic": "energy/+/consumption", "payload": "subscribe" } ``` **Consumer Devices:** - **Philips Hue**: Smart lighting control - **Tesla vehicles**: Vehicle data and control (via third-party bridges) - **Security cameras**: Motion detection, alerts - **Smart thermostats**: Climate control automation - **Garage doors, locks, sensors**: Complete home integration ### ๐Ÿ“ฑ Mobile & Web Applications **Real-Time Apps:** ```bash # Chat application integration { "topic": "chat/room-123/messages", "payload": { "user": "AI_Assistant", "message": "Analysis complete. Found 3 security issues.", "timestamp": "2025-09-17T10:30:00Z" } } # Live gaming coordination { "topic": "game/lobby-456/player-actions", "payload": { "player_id": "ai_coach", "action": "strategy_suggestion", "data": "Focus defenses on northwest quadrant" } } ``` ### ๐Ÿš— Transportation & Logistics **Fleet Management:** ```bash # Track delivery vehicles { "topic": "fleet/vehicle-789/location", "payload": "subscribe" } # Optimize routing based on real-time data { "topic": "logistics/route-optimization", "payload": { "vehicle_id": "truck-123", "new_route": ["depot", "customer-A", "customer-C", "customer-B"], "estimated_time": "2.5 hours" } } ``` ### ๐Ÿฅ Healthcare & Medical Devices **Patient Monitoring:** ```bash # Monitor vital signs from medical IoT devices { "topic": "hospital/room-204/vitals/+", "payload": "subscribe" } # Alert coordination { "topic": "alerts/critical/room-204", "payload": { "alert_type": "heart_rate_anomaly", "value": 140, "timestamp": "2025-09-17T14:22:15Z", "severity": "high" } } ``` ### ๐ŸŒพ Agriculture & Environmental **Smart Farming:** ```bash # Soil moisture sensors { "topic": "farm/field-A/sensors/soil_moisture", "payload": "subscribe" } # Automated irrigation control { "topic": "farm/irrigation/zone-3/control", "payload": { "action": "start_watering", "duration_minutes": 15, "flow_rate": "medium" } } ``` ### ๐Ÿข Building Management Systems **Smart Buildings:** ```bash # HVAC control via BACnet-to-MQTT bridges { "topic": "building/floor-5/hvac/set_temperature", "payload": { "zone": "conference_room_A", "temperature": 21.5, "mode": "cooling" } } # Energy optimization { "topic": "building/power/consumption/+", "payload": "subscribe" } ``` ### ๐Ÿ”— Protocol Bridges & Integrations **Your MCP crew can reach ANY protocol via MQTT bridges:** - **Modbus-to-MQTT**: Industrial equipment control - **BACnet-to-MQTT**: Building automation systems - **Zigbee-to-MQTT**: Smart home device networks - **LoRaWAN-to-MQTT**: Long-range IoT sensors - **OPC-UA-to-MQTT**: Industrial automation standards - **CoAP-to-MQTT**: Lightweight IoT device communication - **WebSocket-to-MQTT**: Browser-based real-time apps ### ๐ŸŽฏ The Power Multiplier Effect **Before mcmqtt**: Your MCP servers could only talk to each other **After mcmqtt**: Your MCP crew can coordinate with: - ๐Ÿญ **Billions of IoT devices** across industries - ๐Ÿข **Enterprise systems** and message brokers - ๐Ÿ“ฑ **Mobile applications** and web services - ๐Ÿ  **Consumer smart devices** and home automation - ๐Ÿš— **Vehicles, drones, and transportation systems** - ๐Ÿฅ **Medical devices and healthcare systems** - ๐ŸŒพ **Agricultural sensors and environmental monitoring** **Result**: Your AI agents become **universal coordinators** in the physical and digital world! ## ๐Ÿ” Common AI Model Challenges mcmqtt Solves ### "How can I coordinate multiple AI agents working on the same task?" **Solution**: Use mcmqtt's MQTT messaging to orchestrate agent workflows. Parent agents publish tasks to topic channels, specialized agents subscribe and process their domain, then publish results back for aggregation. ### "I need to distribute work across multiple language models efficiently" **Solution**: mcmqtt enables model routing and load balancing. Send tasks to `models/{model_name}/queue` topics and let each model process at their optimal rate. Monitor via `models/{model_name}/status` for health and performance. ### "How do I build event-driven AI workflows that react to real-time data?" **Solution**: Use mcmqtt's pub/sub pattern. Data sources publish to `events/{category}` topics, AI agents subscribe to relevant categories and process in real-time. Perfect for IoT sensors, user actions, system events. ### "I want to chain different AI models for complex multi-step processing" **Solution**: Create processing pipelines where each model publishes to the next stage's input topic. Example: `raw_data` โ†’ `model_a/process` โ†’ `model_b/refine` โ†’ `model_c/finalize` โ†’ `results/complete`. ### "How can I make my AI system fault-tolerant and handle model failures?" **Solution**: mcmqtt's message persistence and multiple subscriber patterns mean if one model instance fails, others can pick up the work. Use `dead_letter` topics for failed processing and retry logic. ### "I need to coordinate AI agents across different machines and networks" **Solution**: mcmqtt works over network connections. Deploy agents on different servers, all connecting to the same MQTT broker for seamless distributed coordination. ### "How do I implement real-time collaboration between AI models?" **Solution**: Use mcmqtt's instant messaging for models to share context, ask questions, and coordinate decisions. Models can publish to `collaboration/{session_id}` topics for real-time interaction. ### "I want to build an AI system that learns from multiple agents' experiences" **Solution**: Agents publish their learning insights to `knowledge/{domain}` topics. Other agents subscribe and incorporate shared knowledge, creating a collective intelligence system. ### "How can I monitor and debug complex AI agent interactions?" **Solution**: mcmqtt provides built-in message history, subscription tracking, and status monitoring. All agent communications are logged and can be analyzed for debugging and optimization. ### "I need to integrate AI models with existing enterprise systems and APIs" **Solution**: mcmqtt bridges AI and enterprise systems via MQTT. Legacy systems publish events, AI models process and respond, results integrate back into business workflows seamlessly. ## โš™๏ธ Configuration ### Environment Variables ```bash export MQTT_BROKER_HOST=localhost export MQTT_BROKER_PORT=1883 export MQTT_CLIENT_ID=my-client export MQTT_USERNAME=user export MQTT_PASSWORD=secret export MQTT_USE_TLS=true ``` ### Command Line Options ```bash mcmqtt --help Options: --transport [stdio|http] Server transport mode --mqtt-host TEXT MQTT broker hostname --mqtt-port INTEGER MQTT broker port --mqtt-client-id TEXT MQTT client identifier --auto-broker Spawn embedded broker --log-level [DEBUG|INFO|WARNING|ERROR] --log-file PATH Log to file ``` ## ๐Ÿšฆ Development ### Requirements - Python 3.11+ - UV package manager (recommended) - FastMCP framework - Paho MQTT client ### Setup ```bash # Clone the repository git clone https://git.supported.systems/MCP/mcmqtt.git cd mcmqtt # Install dependencies uv sync # Run tests uv run pytest # Build package uv build ``` ### Testing ```bash # Run all tests uv run pytest tests/ # Run with coverage uv run pytest --cov=src/mcmqtt --cov-report=html # Test specific modules uv run pytest tests/unit/test_cli_comprehensive.py -v ``` ## ๐Ÿ“ˆ Performance - **Lightweight**: Minimal memory footprint - **Fast**: Async/await throughout for maximum throughput - **Scalable**: Handle thousands of concurrent connections - **Reliable**: Comprehensive error handling and retry logic ## ๐Ÿค Contributing We love contributions! This project follows the "campground rule" - leave it better than you found it. 1. Fork the repository 2. Create a feature branch 3. Add tests for new functionality 4. Ensure all tests pass 5. Submit a pull request ## ๐Ÿ“„ License MIT License - see [LICENSE](LICENSE) for details. ## ๐Ÿ™ Credits Created with โค๏ธ by [Ryan Malloy](mailto:ryan@malloys.us) and Claude (Anthropic) Built on the shoulders of giants: - [FastMCP](https://github.com/jlowin/fastmcp) - Modern MCP framework - [Paho MQTT](https://github.com/eclipse/paho.mqtt.python) - Reliable MQTT client - [AMQTT](https://github.com/Yakifo/amqtt) - Pure Python MQTT broker --- **Ready to revolutionize your MQTT integration?** Install mcmqtt today! ๐Ÿš€ ```bash uvx mcmqtt --transport stdio --auto-broker ``` --- **Built with โค๏ธ for the AI developer community** *Powered by FastMCP โ€ข Distributed via uvx โ€ข Coordinated through MQTT*