Quick Start
This tutorial walks you through connecting your first ESP32 to an AI agent via MCP/U. By the end, Claude (or any MCP agent) will be able to read sensors and control outputs on your MCU.
Prerequisites
Section titled “Prerequisites”- ESP32 board (or any Arduino-compatible MCU)
- PlatformIO or Arduino IDE
- Node.js 18+
- USB cable (for Serial) or WiFi credentials (for TCP)
- An MCP-compatible agent (Claude Desktop, Claude Code, Gemini CLI, or OpenCode)
Step 1 — Flash the Firmware
Section titled “Step 1 — Flash the Firmware”Add the MCP-U library to your platformio.ini:
[env:esp32dev]platform = espressif32board = esp32devframework = arduinolib_deps = original2547/MCP-U bblanchon/ArduinoJson @ ^7Then create src/main.cpp with a minimal sketch (see below) and flash:
pio run -t uploadAlternatively, point directly at the library path in the repo:
lib_deps = https://github.com/ThanabordeeN/MCP-U.git#main/firmware/lib/MCP-UOr clone the full repo and use the example sketch:
git clone https://github.com/ThanabordeeN/MCP-Ucd MCP-U/firmwarepio run -t uploadInstall the library via Library Manager — search for “MCP-U”.
Then open File > Examples > MCP-U > BasicExample and click Upload.
Minimal Sketch
Section titled “Minimal Sketch”#include <MCP-U.h>
McpDevice mcp("my-device", "1.0.0");
void setup() { mcp.add_pin(2, "led", MCP_DIGITAL_OUTPUT, "Onboard LED"); mcp.add_pin(5, "buzzer", MCP_DIGITAL_OUTPUT, "Buzzer"); mcp.add_pin(34, "sensor", MCP_ADC_INPUT, "Analog Sensor"); mcp.begin(Serial, 115200);}
void loop() { mcp.loop(); }The default sketch exposes:
- GPIO 2 —
led(digital output) - GPIO 5 —
buzzer(digital output) - GPIO 34 —
sensor(ADC input)
If using WiFi TCP, add WiFi + TCP server setup before mcp.begin() and edit your credentials:
#include <WiFi.h>
const char* WIFI_SSID = "YOUR_SSID";const char* WIFI_PASSWORD = "YOUR_PASSWORD";WiFiServer server(3000);
void setup() { WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) delay(500); server.begin(); // ... add pins ... WiFiClient client = server.accept(); // after a client connects mcp.begin(client);}After uploading, open the Serial Monitor (115200 baud). For WiFi TCP, the ESP32 prints its IP:
Connecting to WiFi....IP: 192.168.1.42TCP server listening on port 3000Note that IP — you’ll need it in the next step.
Step 2 — Connect Your AI Agent
Section titled “Step 2 — Connect Your AI Agent”MCP/U ships as an npm package — no local clone needed for the client.
Serial — Linux / macOS (~/.config/claude/claude_desktop_config.json):
{ "mcpServers": { "mcpu": { "command": "npx", "args": ["mcpu-client"], "env": { "SERIAL_PORT": "/dev/ttyACM0" } } }}WiFi TCP (use the IP from Step 1):
{ "mcpServers": { "mcpu": { "command": "npx", "args": ["mcpu-client"], "env": { "DEVICES": "mydevice:192.168.1.42:3000:tcp" } } }}# Serialclaude mcp add mcpu -e SERIAL_PORT=/dev/ttyACM0 -- npx mcpu-client
# WiFi TCPclaude mcp add mcpu -e DEVICES=mydevice:192.168.1.42:3000:tcp -- npx mcpu-clientVerify: claude mcp list
# Serialgemini mcp add -e SERIAL_PORT=/dev/ttyACM0 mcpu npx mcpu-client
# WiFi TCPgemini mcp add -e DEVICES=mydevice:192.168.1.42:3000:tcp mcpu npx mcpu-clientVerify: gemini mcp list
Edit opencode.json:
{ "$schema": "https://opencode.ai/config.json", "mcp": { "mcpu": { "type": "local", "command": ["npx", "mcpu-client"], "enabled": true, "environment": { "SERIAL_PORT": "/dev/ttyACM0" } } }}For WiFi TCP, use "DEVICES": "mydevice:192.168.1.42:3000:tcp" instead.
Verify: opencode mcp list
Restart your agent. It’s now connected to the MCU.
Step 3 — Try It
Section titled “Step 3 — Try It”Open your AI agent and try these commands:
Turn on the LED on pin 2
Read the sensor on pin 34
What devices are connected?
The agent will call the appropriate MCP tools automatically. Behind the scenes, the client discovers all available tools from the firmware at startup — no hardcoded names.
Verify with MCP Inspector
Section titled “Verify with MCP Inspector”To test without an AI agent:
SERIAL_PORT=/dev/ttyACM0 npx @modelcontextprotocol/inspector npx mcpu-clientOpen the browser URL shown and try calling list_devices or gpio_write.
Next Steps
Section titled “Next Steps”- Add a custom sensor — wrap BME280, MPU6050, or any sensor library
- Connect multiple devices — manage a fleet of MCUs
- Debug connection issues — common errors and fixes
- Firmware API Reference — the complete
McpDeviceAPI