esp32-mcp
Provides tools for controlling an ESP32 board (Espressif) over the LAN, enabling AI agents to read board health, uptime, free heap and the relay table, read chip temperature and analog sensor channels, switch relays on or off, and read or write allowed GPIO pins (level and mode, including input pullup) through a JSON HTTP API on the device.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@esp32-mcp Turn on relay 1 and check the sensor readings."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
esp32-mcp
An MCP server that gives an AI agent control of an ESP32: relays, GPIO pins and analog sensors. The Python side has no dependencies and implements the MCP stdio protocol by hand. The board runs a single Arduino sketch and speaks JSON over HTTP.
AI agent <-- stdio, JSON-RPC 2.0 --> esp32-mcp <-- HTTP, JSON --> ESP32 firmwareI built this because most "AI controls hardware" demos hide a cloud service in the middle. Here the agent talks to a process on your machine, that process talks to a board on your LAN, and nothing leaves the network.
Status
v0.1.0. The whole path works end to end against a simulated board: handshake, tool discovery, relay switching, sensor reads and GPIO reads and writes. The test suite runs without hardware. The sketch compiles for esp32:esp32:esp32 with arduino-cli 1.4.1 and ESP32 core 3.3.12 (74% flash, 15% RAM). CI does not compile the sketch yet, see Deferred.
Related MCP server: ESP32 MCP Server
What is in the box
Path | What it is |
| MCP server, JSON-RPC framing, HTTP device client, tool registry |
| Simulated ESP32 used by the tests and the demo |
| Complete Arduino sketch, pin map at the top |
| Spawns the server, runs the handshake and calls real tools |
| Pin tables, wiring diagram, power and safety notes |
| pytest suite, no hardware required |
Install
git clone https://github.com/StefanYasin/esp32-mcp.git
cd esp32-mcp
python -m pip install -e .Python 3.9 or newer. There are no runtime dependencies.
Try it without hardware
python scripts/demo.py --fakeThat starts the built in simulator, spawns esp32-mcp as a real subprocess and prints the full JSON-RPC exchange: initialize, tools/list, then calls to esp32_health, esp32_read_sensors, esp32_set_relay, esp32_gpio_write and esp32_gpio_read.
Flash the firmware
Install the ESP32 board package in the Arduino IDE (
Boards Manager->esp32 by Espressif).Open
firmware/esp32_mcp/esp32_mcp.ino.Edit the CONFIG block at the top: WiFi credentials,
API_TOKEN, the relay table, the analog sensor table and the GPIO allow list.Select
ESP32 Dev Module, upload, then open the serial monitor at 115200 baud.Note the IP address it prints, or use the mDNS name
http://esp32-mcp.local.
curl http://esp32-mcp.local/health
curl -X POST http://esp32-mcp.local/relay/1/on
curl "http://esp32-mcp.local/gpio?pin=2&value=1"The same thing from the command line, which is the path I used to check the sketch:
arduino-cli core install esp32:esp32
arduino-cli compile --fqbn esp32:esp32:esp32 firmware/esp32_mcp
arduino-cli upload --fqbn esp32:esp32:esp32 -p COM5 firmware/esp32_mcpSwap COM5 for your port. Wiring, pin tables and the safety notes are in docs/wiring.md.
Connect an MCP client
Point the client at the esp32-mcp executable and give it the board URL. This is the Claude Desktop shape; other clients use the same command and env fields.
{
"mcpServers": {
"esp32": {
"command": "esp32-mcp",
"env": {
"ESP32_MCP_URL": "http://192.168.1.42",
"ESP32_MCP_TOKEN": ""
}
}
}
}If you installed into a virtualenv, use the absolute path to the esp32-mcp executable in that venv.
Environment variables:
Variable | Default | Meaning |
|
| Base URL of the board |
| empty | Sent as |
|
| HTTP timeout in seconds |
Flags --url, --token, --timeout and --verbose override the environment. Logs go to stderr so they never corrupt the protocol stream.
Tools
Tool | Arguments | What it does |
| none | Firmware version, IP, uptime, free heap and the relay table |
| none | Chip temperature plus every configured analog channel |
|
| Switches one relay, idempotent |
|
| Reads pin mode and digital level |
|
| Changes a pin mode and optionally drives it |
Agents call esp32_health first to learn which relays and pins exist. Bad arguments come back as a tool result with isError: true and a message that says what to fix. An unknown tool name is a JSON-RPC -32602 error, which is what the MCP spec asks for.
Only pins in the firmware allow list can be touched. The default list leaves out the flash pins and the strapping pins.
HTTP API on the board
The server and the firmware share this contract. It is small on purpose so the sketch stays readable.
Method | Path | Response |
GET |
|
|
GET |
|
|
GET or POST |
|
|
GET or POST |
|
|
GET |
|
|
POST |
| Same shape, sets the level |
POST |
| Same shape, sets the mode |
Errors use the HTTP status plus {"ok":false,"error":"..."}: 400 for bad parameters, 401 for a bad token, 403 for a pin outside the allow list, 404 for an unknown relay or route, 405 for the wrong method.
Protocol details
The MCP stdio transport is newline delimited JSON-RPC 2.0, one message per line, UTF-8. This server implements:
initializewith protocol version2024-11-05,toolscapability and server instructionsnotifications/initializedpingtools/listtools/call
Anything else returns -32601 Method not found. Malformed JSON returns -32700 and the stream stays open. Notifications never get a response.
Tests
python -m pytest88 tests covering the JSON-RPC layer, tool schemas and dispatch, the HTTP client, the simulator contract and the real subprocess stdio transport. No hardware and no network access required; the simulator binds to 127.0.0.1 on a random port.
There is also a compatibility check against the official MCP Python SDK, which is a separate optional install:
python -m pip install mcp
python scripts/interop_check.pyIt starts the simulator, spawns the server through the SDK stdio client and checks the handshake, the tool list, a successful relay call and a rejected pin. I ran it against mcp 2.3.0 and it passes. It is not part of CI because the SDK would be a heavy dev dependency.
Security
The board API is plain HTTP with an optional shared token. That is fine on a trusted LAN and wrong on the public internet. Do not port forward the ESP32, and do not put this behind a public reverse proxy without TLS and real authentication.
Relays can switch mains voltage. Use an opto-isolated relay module, keep the mains side away from the logic side, and read docs/wiring.md before connecting anything.
Deferred
TLS and per client credentials
PWM and analog writes, servo control
Sensor drivers (DHT22, DS18B20, I2C) beyond the internal temperature and raw ADC channels
OTA firmware updates
A sketch compile job in CI. The ESP32 core is about a 1 GB download, so for now the check is a local compile
Newer MCP protocol revisions, the server pins
2024-11-05for nowAn interop job in CI against the official MCP SDK, the check currently runs by hand
License
MIT. See LICENSE.
Built by Stefan Yasin (https://stefanyasin.github.io/)
Available Tools
5 toolsesp32_gpio_readA
Read the mode and digital level of one GPIO pin. Only pins in the firmware allow list can be read.
Inputs: pin (required).
esp32_gpio_writeA
Set a GPIO pin mode (output, input, input_pullup) and optionally drive it high or low. Pass value only, mode only, or both. Only pins in the firmware allow list can be changed.
Inputs: pin (required), mode, value.
esp32_healthA
Read board health: firmware version, IP address, hostname, uptime, free heap and the relay table (index, name, pin, state). Call this first to learn what the board exposes.
Inputs: no named parameters.
esp32_read_sensorsA
Read every sensor configured in the firmware: the internal chip temperature and each analog channel, with raw ADC counts, millivolts and a scaled value.
Inputs: no named parameters.
esp32_set_relayA
Switch one relay on or off. Relay indexes are 1 based and are listed by esp32_health. The call is idempotent.
Inputs: relay (required), state (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a distinct action: health (board identity/diagnostics), read_sensors (sensor values), set_relay (relay control), gpio_read, gpio_write. The only mild overlap is that esp32_health also reports the relay table and health metrics while esp32_read_sensors reports chip temperature, but the descriptions make the boundary clear enough.
All tools share the esp32_ prefix and a consistent snake_case form. Minor deviation: read_sensors/set_relay use verb_noun ordering while gpio_read/gpio_write use noun_verb, though the gpio pair is internally consistent and readable.
Five tools is a tight, well-scoped surface for a microcontroller: one discovery, one sensor read, one relay control, and a GPIO read/write pair. Nothing feels redundant or padded.
Core lifecycle is covered: discovery, sensor reading, relay actuation, and GPIO read/write. Gaps exist for reset/reboot, OTA/firmware update, and analog/PWM output, but these are minor and can be worked around for typical use.
Maintenance
Related MCP Connectors
Connect your AI to your own devices, 3D printers, factory tools and a shared agent task pool.
AI electronics blueprint generator — BOM, wiring, firmware, renders for Arduino/ESP32/RPi.
Memory, reflection and safety for AI agents. Hosted or local, no vector database.
Free social platform for AI agents — boards with tool-call receipts; MCP server + REST API.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables registration, monitoring, and control of IoT devices via AI agents, with local storage and no cloud API key required.9MIT
- AlicenseNot gradedqualityDmaintenanceBridges the Model Context Protocol (MCP) with ESP32 devices running Tasmota firmware, enabling LLMs to send structured commands like toggling relays or reading sensors via HTTP.1ISC
- AlicenseNot gradedqualityBmaintenanceESP32-based Streamable HTTP MCP server with embedded Lua scripting engine. Bridges Claude AI to physical devices — telescopes (INDI protocol), sensors, BLE peripherals, and TCP devices. Flash-and-run binary distribution, no build required.13MIT
- AlicenseAqualityDmaintenanceMCP server that gives AI agents direct access to IoT devices via the jettyd platform, enabling control and monitoring of ESP32 devices through natural language.542 npmMIT