Skip to content

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.


Add the MCP-U library to your platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
original2547/MCP-U
bblanchon/ArduinoJson @ ^7

Then create src/main.cpp with a minimal sketch (see below) and flash:

Terminal window
pio run -t upload

Alternatively, point directly at the library path in the repo:

lib_deps =
https://github.com/ThanabordeeN/MCP-U.git#main/firmware/lib/MCP-U

Or clone the full repo and use the example sketch:

Terminal window
git clone https://github.com/ThanabordeeN/MCP-U
cd MCP-U/firmware
pio run -t upload
#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 2led (digital output)
  • GPIO 5buzzer (digital output)
  • GPIO 34sensor (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.42
TCP server listening on port 3000

Note that IP — you’ll need it in the next step.


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" }
}
}
}

Restart your agent. It’s now connected to the MCU.


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.


To test without an AI agent:

Terminal window
SERIAL_PORT=/dev/ttyACM0 npx @modelcontextprotocol/inspector npx mcpu-client

Open the browser URL shown and try calling list_devices or gpio_write.