Model Context Protocol (MCP) server for Industrial IoT, Edge Computing and Automation
This server transforms industrial infrastructure into an AI-orchestrable system, exposing 11 powerful tools for complete IoT/SCADA/PLC control via HTTP endpoints. Perfect for AI-driven industrial automation, predictive maintenance, and smart factory operations.
-
π Multi-Protocol Support - Unified interface for industrial systems:
- MQTT for wireless IoT sensors and actuators
- Modbus TCP/RTU for PLC and industrial devices
- Time-series data with InfluxDB integration
- Real-time caching with Redis
- Simulated mode for testing without hardware
-
π Complete Sensor Management - Monitor and analyze industrial data:
- Real-time sensor readings (temperature, pressure, flow, etc.)
- Historical data with aggregations (mean, max, min)
- Multi-sensor batch operations
- Quality indicators and signal monitoring
-
β‘ Actuator Control - Command industrial equipment:
- Valve control (open/close)
- Motor management (start/stop/speed)
- Pump operations
- PLC register manipulation
-
π¨ Alarm System - Enterprise-grade monitoring:
- Multi-priority alarms (LOW, MEDIUM, HIGH, CRITICAL)
- Automatic threshold monitoring
- Alarm acknowledgment tracking
- Real-time notifications
-
π Production Features - Enterprise-ready:
- Rate limiting for command safety
- Comprehensive error handling
- Connection pooling and auto-reconnect
- Full audit logging
- Thread-safe operations
# Clone the repository
git clone https://github.com/llm-use/iot-mcp-server.git
cd iot-mcp-server
# Install dependencies
pip install -r requirements.txt
# For testing without hardware, use simulation mode
pip install -r requirements-sim.txtOption 1: Simulation Mode (No Hardware Required)
python IoT_mcp_sim.pyOption 2: Production Mode (Real Hardware)
# Configure your devices in iot_config.yaml
# Start required services (MQTT, InfluxDB, Redis)
docker-compose up -d
# Start the server
python IoT_mcp.pyServer will start on http://localhost:8000
This MCP server is designed to work seamlessly with PolyMCP - a powerful framework for orchestrating MCP servers with AI agents.
#!/usr/bin/env python3
import asyncio
from polymcp.polyagent import UnifiedPolyAgent, OllamaProvider
async def main():
# Initialize your LLM provider
llm = OllamaProvider(model="gpt-oss:120b-cloud", temperature=0.1)
# Connect to IoT MCP server
agent = UnifiedPolyAgent(
llm_provider=llm,
mcp_servers=["http://localhost:8000/mcp"],
verbose=True
)
async with agent:
print("β
IoT MCP Server connected!\n")
# Chat with your AI to control the industrial system
while True:
user_input = input("\nπ You: ")
if user_input.lower() in ['exit', 'quit']:
break
result = await agent.run_async(user_input, max_steps=5)
print(f"\nπ€ System: {result}")
if __name__ == "__main__":
asyncio.run(main())Once connected, you can ask the AI agent to:
- "Check the status of all temperature sensors and report any anomalies"
- "What's the average pressure in tank 1 over the last 6 hours?"
- "Open the main valve and start pump 1"
- "Show me all critical alarms that haven't been acknowledged"
- "If temperature exceeds 50Β°C, activate cooling system"
- "Generate an end-of-shift report with key metrics"
- "Monitor vibration sensor and alert if it exceeds normal range"
- "Optimize energy consumption by analyzing motor usage patterns"
That's it! PolyMCP handles all the complexity of:
- Tool discovery and selection
- Multi-step industrial process automation
- Real-time monitoring and alerting
- Complex decision logic implementation
Once the server is running, you can access:
- API Documentation:
http://localhost:8000/docs - List All Tools:
http://localhost:8000/mcp/list_tools - Invoke Tool:
POST http://localhost:8000/mcp/invoke/{tool_name}
View all available tools (11 tools)
read_sensor- Read current value from a single sensorread_multiple_sensors- Batch read multiple sensorsget_sensor_history- Retrieve historical data with optional aggregation
execute_actuator_command- Send commands to actuators (valves, motors, pumps)
get_device_topology- View complete system architecturelist_devices- List all registered devices with statusget_system_status- Overall system health and statistics
get_active_alarms- View active alarms by priorityacknowledge_alarm- Confirm alarm acknowledgment
read_modbus_registers- Read PLC registers via Modbuswrite_modbus_register- Write values to PLC registers
mqtt:
broker: "localhost"
port: 1883
username: "iot_user"
password: "secure_password"
modbus:
devices:
- device_id: "plc_01"
name: "Main PLC"
type: "tcp"
host: "192.168.1.100"
port: 502
influxdb:
url: "http://localhost:8086"
token: "your-token"
org: "iot"
bucket: "sensors"
redis:
host: "localhost"
port: 6379export MQTT_BROKER="broker.hivemq.com"
export INFLUX_TOKEN="your-token"
export REDIS_HOST="localhost"For Production Mode:
- Python 3.8+
- MQTT Broker (Mosquitto, EMQX, HiveMQ, or any MQTT 3.1.1/5.0 broker)
- InfluxDB 2.0+ (for time-series data)
- Redis (for caching)
- Industrial devices (PLCs with Modbus, IoT sensors)
For Simulation Mode:
- Python 3.8+
- No external dependencies!
Can't connect to MQTT?
- Check broker is running:
mosquitto_sub -h localhost -t '#' - Verify credentials in config
- Check firewall settings
Modbus connection failed?
- Ensure PLC is accessible:
ping <plc_ip> - Verify Modbus is enabled on device
- Check port (usually 502 for TCP)
No sensor data?
- Check MQTT topics match configuration
- Verify sensor is publishing data
- Look at Redis cache:
redis-cli get sensor:*
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β IoT Sensors ββββββΆβ MQTT ββββββΆβ β
βββββββββββββββ β Broker β β β
βββββββββββββββ β IoT MCP β βββββββββββββββ
βββββββββββββββ βββββββββββββββ β Server ββββββΆβ PolyMCP β
β PLCs ββββββΆβ Modbus ββββββΆβ β β AI Agent β
βββββββββββββββ βββββββββββββββ β β βββββββββββββββ
β β
βββββββββββββββ β β βββββββββββββββ
β InfluxDB βββββββββββββββββββββββββββ ββββββΆβ Redis β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
Contributions are welcome! This project demonstrates industrial IoT integration with MCP protocol.
# Clone repo
git clone https://github.com/llm-use/iot-mcp-server.git
# Create virtual environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
# Install dev dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/MIT License - See LICENSE file for details
- PolyMCP - Simple and efficient way to interact with MCP servers using custom agents
- Model Context Protocol - Open protocol for tool integration with LLMs
- MQTT Protocol - Lightweight messaging protocol for IoT
- Modbus Protocol - Industrial communication protocol
- Mqttcpp - A lightweight and fast C++ library for building MQTT clients and brokers
This MCP server bridges the gap between Industrial IoT and AI agents. With PolyMCP, you can:
- Natural Language Control - "Check all pressure sensors and alert if any are abnormal"
- Complex Automation - AI can orchestrate multi-step industrial processes
- Predictive Maintenance - AI analyzes trends and predicts failures
- Energy Optimization - AI optimizes equipment usage for efficiency
- Incident Response - AI handles alarms and executes emergency procedures
No complex industrial protocols to learn - PolyMCP and AI handle everything!
- Smart Factory - AI-driven production line optimization
- Building Automation - Intelligent HVAC and lighting control
- Energy Management - Real-time consumption optimization
- Predictive Maintenance - Equipment failure prediction
- Quality Control - Automated anomaly detection
- Emergency Response - AI-managed incident handling
Designed for PolyMCP
Star β this repo if you find it useful!
