esp32.diy

ESP32MCPServer: Connect AI Agents to Real-World Sensors

Oct 13, 2026 · 6 min read

Intermediate 62 stars 17 forks C++ MIT Updated 2026-03-08

Architecture diagram showing an AI agent connecting over WebSocket to the ESP32 MCP server, which reads I2C sensors, parses NMEA 0183 and NMEA 2000 bus data, decodes OBD-II frames, and stores history in LittleFS.

TL;DR ESP32MCPServer turns an ESP32 into a Model Context Protocol server so AI assistants can query live sensor readings, marine bus data, and vehicle diagnostics over WebSocket with no cloud required. Wire up your sensors, flash the firmware with PlatformIO, and any MCP-compatible AI agent can read the physical world directly.
What you need
  • ESP32-S3-DevKitC-1
  • ESP32-DevKitC V4
  • ESP32-C3-DevKitM-1
  • Adafruit HUZZAH32
  • M5Stack Core ESP32
  • Nordic nRF52840-DK
  • Adafruit Feather nRF52840
  • BME280 breakout
  • MPU6050 breakout
  • TJA1050 CAN transceiver
  • SN65HVD230 CAN transceiver
  • GPS module (3.3 V UART)
  • 4.7 kΩ resistors
BoardESP32-S3-DevKitC-1 (recommended)
LanguageC++
FrameworkPlatformIO
ProtocolJSON-RPC 2.0 over WebSocket
LicenseMIT
DifficultyIntermediate

What You Will Build

This project puts a Model Context Protocol (MCP) server directly on an ESP32. MCP is the open standard that AI assistants use to call external tools and read live data — the same mechanism that lets a chatbot search the web or query a database. Here, the "database" is your physical hardware.

Once flashed, your ESP32 advertises itself on your WiFi network and listens on WebSocket port 9000 for JSON-RPC 2.0 requests. Any MCP-compatible AI agent can then call methods to scan I2C sensors, read temperature and humidity, parse NMEA 0183 GPS sentences from a chart plotter or GPS module, decode NMEA 2000 marine CAN bus frames (position, heading, depth, wind, water temperature), or pull live OBD-II diagnostics from a vehicle's CAN bus — all without any cloud service in the middle.

Practical uses range from asking an AI assistant what the engine RPM is, to letting an agent log marine conditions at anchor, to building a smart home sensor hub that an AI automation pipeline can interrogate on demand.

What You Need

Hardware (from the project's bill of materials):

Part Purpose
ESP32-S3-DevKitC-1 Main MCU — recommended for full feature support
BME280 breakout Temperature, humidity, pressure
MPU6050 breakout 6-axis IMU (optional)
TJA1050 or SN65HVD230 CAN bus transceiver — needed for NMEA 2000 or OBD-II (optional)
GPS module (3.3 V UART) NMEA 0183 position and time (optional)
2 × 4.7 kΩ resistors I2C pull-ups
Breadboard and jumpers —

Other supported ESP32 boards (ESP32-DevKitC V4, ESP32-C3-DevKitM-1, Adafruit HUZZAH32, M5Stack Core) work for WiFi and I2C use cases, though the M5Stack does not support CAN. Nordic nRF52840-DK and Adafruit Feather nRF52840 boards run in sensor-only mode (no WiFi, no MCP server).

Software prerequisites:

Install PlatformIO with:

pip install platformio

Typical use cases

Marine AI Assistant

Connect the ESP32 to an NMEA 2000 backbone and let an AI agent answer questions about vessel position, depth, wind, and water temperature in natural language.

Vehicle Diagnostics

Wire a CAN transceiver to an OBD-II port and give an AI agent access to engine RPM, vehicle speed, and over 60 decoded OBD-II PIDs for real-time monitoring.

Smart Sensor Hub

Auto-scan up to six I2C sensor types — temperature, humidity, pressure, IMU, light, and current — and expose them all through a single MCP endpoint for any AI automation pipeline.

Local AI Tool Server

Run the MCP server on your LAN with mDNS discovery so any MCP-compatible AI agent on the same network can find and query your hardware sensors without cloud dependencies.

How It Works

The firmware runs several cooperating subsystems inside the ESP32:

An AI agent connects once with initialize, calls resources/list to discover what is available, then issues sensors/read or bus/history/read calls as needed. Subscriptions are also supported for push-based updates.

Wiring and Build

Pin assignments for the ESP32-S3-DevKitC-1:

GPIO Function Connect to
IO8 I2C SDA All I2C sensors
IO9 I2C SCL All I2C sensors
IO16 UART1 RX GPS / chart plotter TX
IO17 UART1 TX GPS / chart plotter RX (optional)
IO4 CAN RX TJA1050 / SN65HVD230 CRXD
IO5 CAN TX TJA1050 / SN65HVD230 CTXD

All I2C sensors share one bus. Add 4.7 kΩ pull-up resistors from SDA and SCL to 3.3 V. If your GPS or chart plotter outputs RS-232 levels instead of 3.3 V TTL, use a MAX3232 level shifter — never connect RS-232 directly to ESP32 GPIO. NMEA 2000 runs at 250 kbps; OBD-II runs at 500 kbps — set the correct baud rate in your CANBusReader configuration.

Clone, build, and flash:

# 1. Clone the repository
git clone https://github.com/navado/ESP32MCPServer.git
cd ESP32MCPServer

# 2. Install library dependencies
pio pkg install

# 3. Upload web assets to LittleFS (optional but recommended)
pio run -t uploadfs -e esp32-s3-devkitc-1

# 4. Build firmware
pio run -e esp32-s3-devkitc-1

# 5. Flash
pio run -t upload -e esp32-s3-devkitc-1

# 6. Monitor serial output
pio device monitor --baud 115200

For nRF52840 sensor-only targets:

pio run -e nrf52840-dk
pio run -t upload -e nrf52840-dk

Replace esp32-s3-devkitc-1 with any supported PlatformIO environment name from the board table (esp32-devkitc, esp32-c3-devkitm-1, adafruit-huzzah32, m5stack-core) to target a different board.

First Connection and Testing

After flashing:

  1. Power on the board. It broadcasts a WiFi access point named ESP32_XXXXXX where the last six characters are the MAC address suffix.
  2. Connect your computer or phone to that AP and open http://192.168.4.1 in a browser.
  3. Enter your WiFi credentials and click Save. The board reboots into station mode and prints its assigned IP address on the serial monitor.
  4. Point an MCP client at ws://<IP>:9000.

The web dashboard at http://<IP>/app gives you four tabs without needing an AI agent: Sensors (scan the I2C bus and see live readings), Metrics (heap, uptime, RSSI), Logs, and MCP Console (an interactive JSON-RPC console with preset requests).

To test the MCP interface directly, send an I2C scan request:

{"jsonrpc":"2.0","method":"sensors/i2c/scan","id":1}

The server responds with detected devices and their supported parameters. Then read a specific sensor:

{"jsonrpc":"2.0","method":"sensors/read","id":2,"params":{"sensorId":"bme280_0x76"}}

For bus history, query recent CAN frames or decoded NMEA 2000 messages:

{"jsonrpc":"2.0","method":"bus/history/read","id":3,"params":{"type":"nmea2000"}}

All responses follow JSON-RPC 2.0 and include units, timestamps, and validity flags.

Ideas to Extend It and Known Limitations

Ways to go further:

Limitations to be aware of:

Verdict

ESP32MCPServer is a well-executed bridge between AI tooling and physical hardware, covering an unusually wide range of protocols — I2C, NMEA 0183, NMEA 2000, and OBD-II — under one consistent MCP interface. The PlatformIO build system, detailed wiring diagrams, and interactive web dashboard make it approachable for makers who are comfortable with embedded development. If you want AI agents to reason about the real world without a cloud intermediary, this is a solid foundation to build on.

Sources

github.comnavado/ESP32MCPServer — repository & README

Facts in this article come from the project's public README and GitHub metadata at the time of writing. Images belong to their respective owners and link back to the original source.