Skip to main content

IoT MCP Server for sensor data reading and device task management

Project description

IoT MCP Server

License: CC BY-NC-SA 4.0

A comprehensive Model Context Protocol (MCP) server that provides Internet of Things (IoT) device integration for AI assistants like Claude Desktop and Cursor IDE. This server enables AI to read sensor data from IoT devices and dispatch data collection tasks to IoT devices through a unified interface.

Demo

[DEMO_URL]

IoT MCP Server demonstration showing sensor data reading, device task assignment, and real-time monitoring

Features

  • Sensor Data Reading: Read real-time data from various IoT sensors (temperature, humidity, pressure, motion, etc.)
  • Device Task Management: Dispatch data collection tasks to IoT devices with configurable intervals and parameters
  • Multi-Protocol Support: Connect to devices via MQTT, HTTP REST API, CoAP, and custom protocols
  • Real-time Monitoring: Stream live sensor data and device status updates
  • Device Discovery: Automatically discover and register IoT devices on the network
  • Data Filtering: Apply filters and transformations to sensor data before processing
  • Alert System: Configure alerts based on sensor thresholds and device status

Prerequisites

Before using this MCP server, you need to install the following components:

  1. Python 3.8+ The IoT MCP server is built with Python and requires Python 3.8 or higher. Check if Python is installed:
bashpython --version
# or
python3 --version

Installation:

Windows: Download from python.org macOS: Download from python.org or use Homebrew: brew install python Linux: Usually pre-installed, or install via package manager: sudo apt install python3 python3-pip

  1. uv (Python Package Manager) This project uses uv for fast and reliable Python package management. Installation: macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh

Windows:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Alternative Installation Methods:

# Using pip
pip install uv

# Using Homebrew (macOS)
brew install uv

# Using cargo (if you have Rust installed)
cargo install --git https://github.com/astral-sh/uv uv
Verify Installation:
bashuv --version

Installation

Clone the Repository

git clone [PLACEHOLDER_REPOSITORY_URL]
cd iot-mcp-server

That's it! The project uses uv for dependency management, which will automatically handle all Python dependencies when the server runs.

Configuration

1. Hardware Setup

Connect MCU and Sensors:

  • Properly connect your MCU (microcontroller) with the sensors according to your sensor's wiring diagram
  • Ensure stable power supply and correct pin connections

Network/Serial Connection:

  • Network Option: Ensure your MCU and your computer are on the same network (WiFi/Ethernet)
  • Serial Option: Connect MCU to your computer via USB/Serial cable

2. Sensor Configuration

Navigate to Sensor Directory:

# Example for MPU6050 sensor
cd sensors/MPU6050

Run Sensor Configuration:

python config.py

This will configure the sensor parameters and generate the necessary configuration files.

3. MCU Programming

Upload Main Script to MCU:

# Use mpremote to transfer main.py to your MCU
mpremote connect [PORT] cp main.py :

Replace [PORT] with your MCU's serial port (e.g., /dev/ttyUSB0 on Linux, COM3 on Windows, /dev/tty.usbserial-* on macOS).

Alternative upload methods:

# For ESP32/ESP8266
mpremote connect /dev/ttyUSB0 cp main.py :

# For Raspberry Pi Pico
mpremote connect /dev/ttyACM0 cp main.py :

4. MCP Server Setup

Initialize and Configure MCP Server:

# Initialize uv project (if not already done)
uv init .

# Add MCP dependencies
uv add "mcp[cli]"

This will set up the MCP server with all necessary dependencies.

Usage Examples

1. Reading Sensor Data

Ask Claude: "Read the current temperature and humidity from all sensors in the living room"

Expected Response:

  • Current temperature: 22.5°C
  • Current humidity: 45%
  • Timestamp: [CURRENT_TIMESTAMP]
  • Device status: Online

2. Dispatching Data Collection Tasks

Ask Claude: "Set up a task to collect temperature data every 5 minutes from sensor_001 for the next 2 hours"

Task Configuration:

  • Device: sensor_001
  • Data type: temperature
  • Interval: 5 minutes
  • Duration: 2 hours
  • Storage: Local buffer + cloud sync

3. Real-time Monitoring

Ask Claude: "Start monitoring all motion sensors and alert me if any detect movement"

Monitoring Setup:

  • Real-time data streaming
  • Threshold-based alerts
  • Device health monitoring

Common Issues

  1. MCP Server Not Detected:

    • Verify the absolute path in configuration
    • Check that Node.js is installed and accessible
    • Restart Claude Desktop/Cursor after configuration changes
  2. Device Connection Failures:

    • Verify device IP addresses and network connectivity
    • Check protocol-specific configuration (MQTT broker, HTTP endpoints)
    • Ensure device authentication credentials are correct
  3. MQTT Connection Issues:

    # Test MQTT connection manually
    mosquitto_pub -h localhost -t test/topic -m "test message"
    mosquitto_sub -h localhost -t test/topic
    
  4. Permission Errors:

    • Check file permissions for configuration files
    • Ensure network access permissions for device communication
    • Verify user permissions for required system resources
  5. Data Reading Timeouts:

    • Check device responsiveness
    • Verify network stability
    • Adjust timeout parameters in configuration

Debugging

  1. Check MCP Server Logs:

    • Claude Desktop: ~/Library/Logs/Claude/mcp*.log (macOS)
    • Cursor: Check the MCP settings panel for error messages
  2. Test Device Connectivity:

    # HTTP devices
    curl -X GET http://[DEVICE_IP]/status
    
    # MQTT devices
    mosquitto_sub -h [BROKER_IP] -t [DEVICE_TOPIC]
    
    # Ping test
    ping [DEVICE_IP]
    
  3. Verify Configuration:

    # Validate JSON configuration files
    node -e "console.log(JSON.parse(require('fs').readFileSync('config/devices.json')))"
    
  4. Check Environment Variables:

    echo $IOT_CONFIG_PATH
    echo $PATH
    

Supported Devices

Currently Supported Device Types

  • [ESP32 s3]

Security Considerations

  • Device Authentication: All device communications should use proper authentication
  • Network Security: Ensure IoT devices are on secure networks
  • Data Encryption: Use encrypted protocols where possible
  • Access Control: Implement proper access controls for device management
  • Regular Updates: Keep device firmware and server dependen

License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_duke_cei_center_iotmcp-0.1.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_duke_cei_center_iotmcp-0.1.3.tar.gz.

File metadata

  • Download URL: iflow_mcp_duke_cei_center_iotmcp-0.1.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_duke_cei_center_iotmcp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8e0aa377073d301cf9eccb5a47e5c0a05eafad587d8de2a5f20257166f6f544a
MD5 2dd3b638eeedb301e7f84c5e8d207b21
BLAKE2b-256 909a3d25884024f1e0fa3b083456fbe6b092c4085c843f9561474e92bf09f584

See more details on using hashes here.

File details

Details for the file iflow_mcp_duke_cei_center_iotmcp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_duke_cei_center_iotmcp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_duke_cei_center_iotmcp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 273cfd66b90ad85b775a2cbd807977a76e4e0c9737d6acabfa29e77c42e689e7
MD5 d979ccd27e4331e73aa468c8df130fb9
BLAKE2b-256 2670dc73ee9d404b4c12f33b40df9e3bcd0a8754ddc6c8cebcadb2bd70a0f842

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page