navado/ESP32MCPServer
소개
Allow AI models connect to ESP32 and read connected sensors NMEA2k, ODB/ODBII, NMEA0183. AI generated MCP server.
AI 및 머신러닝What you can do
- MCP Protocol - JSON-RPC 2.0 over WebSocket, resource discovery & subscriptions
- I2C Sensors - Auto-scan + drivers for BME280, MPU6050, ADS1115, SHT31, AHT20, BH1750, INA219
- NMEA 0183 - GGA, RMC, VTG, GSV, MWV, DBT, DPT, HDG, HDT with XOR checksum validation
- NMEA 2000 / CAN - 29-bit PGNs: position, heading, speed, depth, wind, attitude, water temp
측정된 스타 증가
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +2
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalESP32 MCP Server
A Model Context Protocol (MCP) server running on ESP32 (and Nordic nRF52840 in sensor-only mode), exposing real-world sensor data and bus protocols to AI assistants and automation tooling over WebSocket / JSON-RPC 2.0.
Connect an AI agent directly to your hardware: query I2C sensors, parse NMEA 0183 GPS/marine data, decode NMEA 2000 and OBD-II CAN frames, replay bus history — all through a standard MCP interface.

Features
| Capability | Details |
|---|---|
| MCP Protocol | JSON-RPC 2.0 over WebSocket, resource discovery & subscriptions |
| I2C Sensors | Auto-scan + drivers for BME280, MPU6050, ADS1115, SHT31, AHT20, BH1750, INA219 |
| NMEA 0183 | GGA, RMC, VTG, GSV, MWV, DBT, DPT, HDG, HDT with XOR checksum validation |
| NMEA 2000 / CAN | 29-bit PGNs: position, heading, speed, depth, wind, attitude, water temp |
| OBD-II / CAN | Standard 11-bit OBD-II service 01/09 PID decoding (60+ PIDs) |
| Bus History | Persistent ring buffers for CAN, NMEA, NMEA 2000, OBD-II — queryable via MCP |
| Bus Readers | Time-bounded serial and CAN reads, raw or parsed mode, JSON output |
| Bluetooth (BLE) | BLE central over MCP (ESP32-S3): non-blocking advertising scanner with raw payload history and capture filters, GATT client (connect to public and random addresses, enumerate services, read values, capture notifications) — see Bluetooth (BLE) |
| WiFi | AP setup UI + STA mode; credentials stored in NVS |
| Discovery | mDNS (_mcp._tcp) + UDP capability broadcast |
| Metrics | Heap, uptime, RSSI, histogram stats with boot persistence |
| Multi-board | ESP32-S3, ESP32-C3, ESP32, Adafruit HUZZAH32, M5Stack, Nordic nRF52840-DK, Adafruit Feather nRF52840 |
| Testing | Native unit tests (Unity), mock I2C / CAN / Serial / LittleFS |
Supported Boards
ESP32 Boards — Full MCP Server (WiFi + WebSocket + CAN)
| Board | PlatformIO env | MCU | Flash | RAM | WiFi | BLE | CAN | RGB LED |
|---|---|---|---|---|---|---|---|---|
| ESP32-S3-DevKitC-1 | esp32-s3-devkitc-1 |
Xtensa LX7 × 2 @ 240 MHz | 8 MB | 512 KB (PSRAM not used²) | ✓ | 5.0 | ✓ | GPIO48 |
| ESP32-S3-DevKitC-1 N16R8 / N8R8 | esp32-s3-devkitc-1-n16r8 |
Xtensa LX7 × 2 @ 240 MHz | 8–16 MB | 512 KB + 8 MB octal PSRAM | ✓ | 5.0 | ✓ | GPIO48 |
| ESP32-DevKitC V4 | esp32-devkitc |
Xtensa LX6 × 2 @ 240 MHz | 4 MB | 520 KB | ✓ | ✗¹ | ✓ | — |
| ESP32-C3-DevKitM-1 | esp32-c3-devkitm-1 |
RISC-V @ 160 MHz | 4 MB | 400 KB | ✓ | ✗¹ | ✓ | GPIO8 |
| Adafruit HUZZAH32 | adafruit-huzzah32 |
Xtensa LX6 × 2 @ 240 MHz | 4 MB | 520 KB | ✓ | ✗¹ | ✓ | — |
| M5Stack Core ESP32 | m5stack-core |
Xtensa LX6 × 2 @ 240 MHz | 16 MB | 520 KB | ✓ | ✗¹ | ✗ | — |
¹ 4 MB-flash boards: the BLE stack + the MCP WebSocket server + OTA cannot all fit the 1.25 MB OTA app slot, so BLE is compiled out (the hardware still supports it). BLE is available on the ESP32-S3 (8 MB flash). esp32-devkitc, esp32-c3-devkitm-1, adafruit-huzzah32 and m5stack-core also use a larger-app partition table (partitions_4mb_ota.csv): upgrading an existing board requires one USB flash and re-uploading the filesystem — see the board pages in docs/boards/ and the CHANGELOG.
² PSRAM mode (octal vs quad) is fixed at build time, so modules with 8 MB octal PSRAM (N8R8/N16R8; esptool.py chip_id reports "Embedded PSRAM 8MB") need the -n16r8 env. Do not flash that env on DevKitC-1 variants without PSRAM or with quad PSRAM (N8R2).
Boot-time memory plan. At startup the firmware checks for PSRAM and divides memory between bus history and BLE capture accordingly (include/MemoryPlan.h; logged as [mem] plan=… on the serial console):
| Detected at boot | Bus history | BLE capture |
|---|---|---|
| PSRAM | budgeted from PSRAM (min of 1 MB and ¼ of free PSRAM) | 64 devices / 48 KB |
| No PSRAM, BLE enabled | internal heap, capped at 96 KB | 24 devices / 16 KB |
| No PSRAM, BLE disabled | internal heap, board cap (BOARD_BUS_HISTORY_HEAP_CAP) |
— |
An explicit ramBudgetBytes in the bus-history config still takes precedence.
nRF52840 Boards — Sensor Only (I2C + Serial, no WiFi)
| Board | PlatformIO env | MCU | Flash | RAM | BLE |
|---|---|---|---|---|---|
| Nordic nRF52840-DK | nrf52840-dk |
Cortex-M4F @ 64 MHz | 1 MB | 256 KB | 5.0 + 802.15.4 |
| Adafruit Feather nRF52840 | nrf52840-feather |
Cortex-M4F @ 64 MHz | 1 MB | 256 KB | 5.0 |
nRF52840 targets run a separate
main_nrf.cppentry point: sensors + I2C + Serial output only. No WiFi, no MCP WebSocket, no LittleFS, no bus history. For full MCP-over-WiFi, bridge via an ESP32-C3 in AT-command mode connected to UART1.
Board Feature Matrix
| Feature | ESP32-S3 | ESP32 V4 | ESP32-C3 | HUZZAH32 | M5Stack | nRF52840-DK | nRF52840-Feather |
|---|---|---|---|---|---|---|---|
| WiFi | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
BLE via MCP (ble/*) |
✓ | ✗¹ | ✗¹ | ✗¹ | ✗¹ | ✗³ | ✗³ |
| CAN / TWAI | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ |
| I2C | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| UART (ext) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| LittleFS | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
| MCP Server | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
| Bus History | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
| mDNS / UDP discovery | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
³ The nRF52840 has a BLE radio, but the nRF52 firmware (main_nrf.cpp) does not use it; there is no MCP server on those targets.
Architecture
flowchart TD
Client[AI Agent / MCP Client] -->|WebSocket :9000 JSON-RPC 2.0| MCPServer
subgraph ESP32
MCPServer -->|resources/list| Resources
MCPServer -->|sensors/i2c/scan| SensorMgr
MCPServer -->|sensors/read| SensorMgr
MCPServer -->|buses/serial/read| BusReader
MCPServer -->|buses/can/read| BusReader
MCPServer -->|bus/history/read| BusHistory
MCPServer -->|bus/history/config/*| BusHistory
SensorMgr -->|Wire I2C| I2CSensors[BME280 · MPU6050 · ADS1115\nSHT31 · BH1750 · INA219]
BusReader -->|UART| NMEAParser[NMEA 0183 Parser]
BusReader -->|CAN TWAI| CANParser[NMEA 2000 / OBD-II Parser]
BusReader -->|feed| BusHistory[Bus History\nRing Buffers]
BusHistory --> LittleFS
NetworkMgr[Network Manager] --> WiFi
NetworkMgr --> WebSetup[Setup UI :80]
DiscoveryMgr[Discovery Manager] -->|mDNS + UDP| Network
Metrics[Metrics System] --> LittleFS
uLogger --> LittleFS
end
MCPServer --> Metrics
MCPServer --> uLogger
Hardware
Pin Assignments (ESP32-S3-DevKitC-1)
| GPIO | Function | Connected 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 |
nRF52840-DK Pin Assignments
| Pin | Function |
|---|---|
| P0.26 / D6 | I2C SDA |
| P0.27 / D7 | I2C SCL |
| P0.06 / TX | UART1 TX |
| P0.08 / RX | UART1 RX |
Bill of Materials
| # | Part | Purpose |
|---|---|---|
| 1 | ESP32-S3-DevKitC-1 | Main MCU |
| 1 | BME280 breakout | Temperature / Humidity / Pressure |
| 1 | MPU6050 breakout | 6-axis IMU (optional) |
| 1 | TJA1050 or SN65HVD230 | CAN bus transceiver (optional) |
| 1 | GPS module (3.3 V UART) | NMEA 0183 position/time (optional) |
| 2 | 4.7 kΩ resistors | I2C pull-ups |
| — | Breadboard + jumpers |
ESP32-S3-DevKitC-1 Wiring
┌──────────────────────────────────────┐
│ ESP32-S3-DevKitC-1 │
│ │
3V3 ───┤ 3V3 GND ├─── GND
GND ───┤ GND IO0 ├
│ │
I2C SDA ── IO8 ───┤ IO8 ┌──────────┐ IO17 ├─── UART1 TX → GPS
I2C SCL ── IO9 ───┤ IO9 │ ESP32 │ IO16 ├─── UART1 RX ← GPS
│ IO10 │ S3 │ IO15 ├
│ IO11 └──────────┘ IO14 ├
│ IO12 IO13 ├
│ IO3 IO4 ├─── CAN RX ← TJA1050
│ IO46 IO5 ├─── CAN TX → TJA1050
│ │
│ USB (flash / serial log) │
└───────────────────────────────┘
I2C Sensor Wiring
All sensors share one bus. Add 4.7 kΩ pull-ups from SDA and SCL to 3V3.
ESP32-S3 BME280 MPU6050 ADS1115 INA219
───────── ─────── ─────── ─────── ───────
IO8 (SDA)─────SDA──────────SDA──────────SDA──────────SDA
IO9 (SCL)─────SCL──────────SCL──────────SCL──────────SCL
3V3 ──────────VCC──────────VCC──────────VCC──────────VCC
GND ──────────GND──────────GND──────────GND──────────GND
SDO→GND AD0→GND ADDR→GND
(0x76) (0x68) (0x48) (0x40)
Other supported sensors (same bus wiring): SHT31 (0x44), BH1750 (0x23).
NMEA 0183 Wiring (GPS / Chart Plotter)
GPS / chart plotter ESP32-S3
─────────────────── ────────
TX (3.3 V TTL NMEA out) ─────── IO16 (UART1 RX)
RX (optional NMEA in) ─────── IO17 (UART1 TX)
GND ─────── GND
VCC (3.3 V) ─────── 3V3
If the device outputs RS-232 levels, use a MAX3232 level shifter. Never connect RS-232 directly to ESP32 GPIO.
CAN Bus Wiring (NMEA 2000 / OBD-II)
TJA1050 / SN65HVD230 ESP32-S3
──────────────────── ────────
CTXD ─────────── IO5 (CAN TX)
CRXD ─────────── IO4 (CAN RX)
VCC (5 V for TJA1050) ─────────── VIN / external 5 V
GND ─────────── GND
CANH ──────────────── NMEA 2000 backbone / OBD-II CANH
CANL ──────────────── NMEA 2000 backbone / OBD-II CANL
NMEA 2000 runs at 250 kbps. OBD-II runs at 500 kbps. Set the baud rate in your
CANBusReaderconfiguration accordingly.
Software Prerequisites
- PlatformIO Core CLI or the PlatformIO IDE plugin for VS Code
- Python 3.8+
- Git
pip install platformio
Build & Flash
# 1. Clone
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
pio device monitor --baud 115200
nRF52840
pio run -e nrf52840-dk
pio run -t upload -e nrf52840-dk
First Run
- Power on the board. It broadcasts a WiFi AP:
ESP32_XXXXXX(last 6 hex digits of the MAC address). - Connect to that AP and open
http://192.168.4.1. - Enter your WiFi credentials and click Save.
- The board joins your network and prints its IP address on the serial console.
- Connect an MCP client to
http://<IP>/mcp(Streamable HTTP, see Connecting an MCP client), or the legacy WebSocketws://<IP>:9000. MCP authentication is off by default, so the examples below work as-is on a trusted network. To require a token, typeauth onon the serial console (or build with-D MCP_AUTH_DEFAULT=1); see Security. - On first boot the serial console prints a generated OTA password (
ota showprints it again).
Security
The device is meant for a trusted LAN. MCP authentication is optional and off by default: out of the box any host that can reach the device can use it, exactly as before. Turn it on for anything but a lab bench. On the ESP32-S3 N16R8 build the MCP transports are also offered over TLS (see TLS); elsewhere traffic is in clear text.
Turning authentication on or off (NVS namespace security, key auth):
| How | Effect |
|---|---|
Serial console auth on |
Require a token. A full-control token is generated and printed if none exists. Reboots |
Serial console auth off |
Accept clients without a token again (stored tokens are kept). Reboots |
-D MCP_AUTH_DEFAULT=1 build flag |
Ship boards with authentication on (used when the auth key is absent) |
| NVS image | Pre-provision auth, token and ro_token like the WiFi credentials |
When authentication is off every client has full control. Rate limits, the client limit and the Origin check stay active either way.
Threat model. With authentication off, any host that can reach port 9000 could open BLE connections to nearby devices, read sensor, bus and metrics data, clear logs, and tie up the server. Turning it on stops an unauthenticated host on the network from doing any of that. On its own it does not protect against someone who can sniff the traffic: over ws:// and http:// the token and all data travel in clear text, and the OTA password goes over plain HTTP Basic Auth. Use the TLS endpoints where available. Physical access to the USB serial console is trusted: it can show and change every secret.
MCP access tokens (NVS namespace security; used only when authentication is on):
| Token | Key | Access |
|---|---|---|
| Full control | token |
Every method |
| Read-only (optional) | ro_token |
Observation only, nothing that changes shared state: initialize, resources/*, sensors/read, metrics/*, logs/query, bus/history/read, bus/history/config/get, ble/scan/poll, ble/connect/results. Starting or stopping the shared BLE scan (ble/scan, ble/scan/stop, ble/scan/results, ble/scan/payloads), sensors/i2c/scan (it writes init commands to devices), ble/connect, ble/services/*, ble/disconnect, logs/clear, bus/history/config/set and any method not on the list need full control |
- When authentication is on and no token exists, a random 128-bit token is generated and printed on the serial console (
token showprints it again). - Clients send it as
Authorization: Bearer <token>or, from browsers (which cannot set WebSocket headers), as?token=<token>. - A connection without a valid token is closed with WebSocket close code 4401 before any message is processed. A read-only client calling a full-control method gets
-32020(data.required: "full").
Serial console (115200 baud on UART0; on the ESP32-S3-DevKitC-1 that is the USB port labelled UART/COM, not the native USB port; type help):
| Command | Effect |
|---|---|
auth status / auth on / auth off |
Show / require / stop requiring a token; on and off reboot |
token show |
Print both tokens |
token rotate / token set <value> |
New random / chosen (≥ 16 chars) full-control token; reboots to apply |
token ro rotate / token ro clear |
New / remove the read-only token; reboots |
ota show / ota rotate |
Print / replace the OTA password (rotate reboots) |
Tokens can also be pre-provisioned in an NVS image, like the WiFi credentials.
Resource limits.
| Limit | Default | Build flag | When exceeded |
|---|---|---|---|
| Concurrent MCP clients | 4 | MCP_MAX_CLIENTS |
Close code 4429 |
| Requests per client | burst 20, then 10/s | MCP_RATE_BURST, MCP_RATE_PER_SEC |
-32021 Rate limited with data.retryAfterMs |
| Idle clients | ping every 15 s | — | Dropped after 2 missed pongs |
Port-80 HTTP endpoints. With authentication on, the status and settings endpoints need a token too: reads accept either token, and changes need the full-control token. Without a token the response is 401; a read-only token on a change gets 403. See HTTP Endpoints. The HTML pages themselves stay public (they contain no device data), and the WiFi setup page, dashboard and bus-history page ask for the token when they get a 401. One exception: while the device has no WiFi network saved and serves its setup access point, everything stays open, since nobody can know the token before provisioning. A device that falls back to its access point because its saved network is unreachable still requires the token.
OTA.
- There is no compiled-in default password. A random per-device password is generated on first boot, and also on a device that still holds the old
admindefault. It is printed once on the serial console. - After 5 consecutive wrong logins from one IP address, that address gets
429(withRetry-After) for 30 s, doubling up to 5 minutes per further failure. Other hosts are not affected, so a guessing host can't lock the owner out. Up to 32 source addresses are tracked. Beyond that, the remaining sources share one lockout, so rotating addresses doesn't buy extra guesses. The tradeoff: an attacker with more than 32 failing LAN addresses can delay OTA logins from new hosts for a few minutes. USB flashing and the serial console are never affected.
TLS
The esp32-s3-devkitc-1-n16r8 build (-D MCP_TLS=1) also serves the MCP transports over TLS on port 443:
| Endpoint | Same as |
|---|---|
https://<device>/mcp |
http://<device>/mcp: Streamable HTTP, the same sessions and tokens |
wss://<device>/ws |
ws://<device>:9000: the JSON-RPC WebSocket, with pushes, the same 4401/4429 close codes, Authorization header or ?token= |
The plain endpoints stay available. Authentication works the same on all of them.
Certificate. On first boot, once WiFi is up, the device makes an EC P-256 key and a self-signed certificate, valid until 2049, and keeps them in NVS (namespace tls). It is a leaf certificate (CA:FALSE, server authentication only), so trusting it never trusts anything else. The certificate names <hostname>.local, <hostname> and the IP address the device had then. The boot log shows the names and the SHA-256 fingerprint, and so does the serial command tls show. tls rotate makes a new key and certificate (new fingerprint) on the next boot. Use it if the device gets a different IP address, or use the .local name instead.
Trusting it.
- Download the certificate from
http://<device>/tls.pem. - Compare its fingerprint with the serial console:
openssl x509 -in tls.pem -noout -fingerprint -sha256. - Give it to the client as the only CA:
curl --cacert tls.pem https://<ip>/mcp …- Python:
ssl.create_default_context(cafile="tls.pem") - Node-based MCP clients (the Inspector, Claude Code,
mcp-remote):NODE_EXTRA_CA_CERTS=tls.pem
The client then checks the name too. Use the IP in the certificate or <hostname>.local.
Limits.
- Each TLS connection needs about 40 KB of buffers. mbedTLS is switched to PSRAM for this, and the server keeps at most 6 sockets.
- A full ECDSA handshake takes about 2 s. Keep-alive connections and WebSockets pay it once.
wss://clients count toward the same 4-client WebSocket limit asws://:9000.- There is no TLS on the other boards: there's no PSRAM, and the 4 MB boards have no flash headroom for it.
Not covered yet.
- OAuth 2.1 (MCP authorization for HTTP transports) doesn't fit on the device.
/mcptakes the same static bearer token, which MCP clients can send as a configuredAuthorizationheader.
Web Dashboard
A browser-based dashboard is served from flash at http://<IP>/app.
| Tab | What it does |
|---|---|
| Sensors | Scan I²C bus, display detected devices, read values, auto-refresh |
| Metrics | List all metrics, live values, sparkline history chart |
| Logs | Query and clear metric log entries |
| MCP Console | Interactive JSON-RPC console with preset requests and live message log |
HTTP Endpoints (port 80)
The Auth on column applies only when authentication is turned on (see Security); with it off, every endpoint is open. Send Authorization: Bearer <token>, or ?token= on /ws.
| Method | Path | Description | Auth on |
|---|---|---|---|
| GET | / |
WiFi setup page | public |
| POST | /save |
Save WiFi credentials (ssid, password form params) |
full |
| GET | /status |
Network status JSON | read |
| WS | /ws |
Real-time network status WebSocket | read (?token=) |
| GET | /app |
Browser dashboard | public |
| GET / POST | /discovery |
Read / change mDNS and discovery settings | read / full |
| GET | /bus-history-config |
Bus history settings page | public |
| GET / POST | /bus-history |
Read / change the bus history config JSON | read / full |
| GET | /ota |
OTA upload page | public |
| GET | /ota/status |
Firmware version and update state | public |
| GET / POST | /ota/config |
OTA settings | OTA password (Basic) |
| POST | /ota/update |
Firmware upload | OTA password (Basic) |
| POST / GET / DELETE | /mcp |
MCP Streamable HTTP | read or full, per method |
| GET | /tls.pem |
The device's TLS certificate (N16R8 build; see TLS) | public |
MCP API Reference
All methods use JSON-RPC 2.0. No access token is needed unless authentication is turned on (see Security). Two transports serve the same methods:
| Transport | Endpoint | Use it for |
|---|---|---|
| Streamable HTTP (MCP standard) | POST http://<IP>/mcp |
Standard MCP clients: Claude Code, Claude Desktop through mcp-remote, the MCP Inspector, the official SDKs |
| WebSocket (legacy) | ws://<IP>:9000 |
The web dashboard and existing WebSocket clients; supports push notifications (resources/subscribe) |
| Over TLS (ESP32-S3 N16R8) | https://<IP>/mcp, wss://<IP>/ws |
The same two transports, encrypted (see TLS) |
Connecting an MCP client
Claude Code:
claude mcp add --transport http esp32 http://<IP>/mcp
# with authentication on:
claude mcp add --transport http esp32 http://<IP>/mcp --header "Authorization: Bearer <token>"
Claude Desktop, or any stdio-only client, through mcp-remote:
{
"mcpServers": {
"esp32": {
"command": "npx",
"args": ["mcp-remote", "http://<IP>/mcp", "--allow-http"]
}
}
}
With authentication on, add "--header", "Authorization:${MCP_AUTH}" to args and "env": { "MCP_AUTH": "Bearer <token>" }.
MCP Inspector: npx @modelcontextprotocol/inspector, then choose transport Streamable HTTP, URL http://<IP>/mcp (add the Authorization header when authentication is on).
Streamable HTTP details
POST /mcptakes one JSON-RPC message and returnsapplication/json. Notifications get202 Accepted.initialize(sent without a session id) returns anMcp-Session-Idheader that every later request must carry.- Unknown or expired sessions get
404; the client should re-initialize. Sessions expire after 10 minutes idle, andDELETE /mcpends one. - Up to 4 sessions at a time, separate from the 4 WebSocket clients. When all 4 are taken, a new
initializereplaces the least recently used session that has been idle for at least 30 s, because many clients, such as the MCP Inspector CLI, never sendDELETE. Its client gets404on its next request and starts over. Some sessions are never replaced: one that owns a BLE scan, link or subscription, and a full-control session when the new one is read-only. - With authentication on, every request needs
Authorization: Bearer <token>(401otherwise). A browserOriginmust match the device's host (403otherwise), which protects against DNS rebinding. GET /mcpreturns405: the server doesn't open SSE streams, so HTTP clients get no push notifications andresources.subscribeisfalsefor them.- Requests are limited to 16 KB.
Protocol and capabilities
- Versions:
2025-06-18(preferred),2025-03-26and2024-11-05. A supported requested version is echoed back; otherwise the server answers with2025-06-18. A non-string version is-32602. - Capabilities:
resources: {subscribe, listChanged: false}andtools: {listChanged: false}. - Lifecycle:
ping,notifications/initializedandnotifications/cancelledare handled. Notifications never get a response, and string request ids are supported.
Tools
tools/list exposes the device's methods as MCP tools, with JSON Schema inputs and the annotations readOnlyHint, destructiveHint, idempotentHint and openWorldHint.
tools/callreturns the method's result instructuredContent, plus a JSON text block (results over 4 KB get a one-line text summary to save RAM).- A method error (e.g.
Feature busy) comes back asisError: truewith the error instructuredContent.error. - Tools inherit the authorization of the method they wrap. A read-only token only sees and calls the read-only tools.
| Tool | Method |
|---|---|
sensors_scan, sensors_read |
sensors/i2c/scan, sensors/read |
bus_history_read, bus_history_config_get, bus_history_config_set |
bus/history/* |
metrics_list, metrics_get, metrics_history, logs_clear |
metrics/*, logs/clear |
system_features |
system/features |
ble_scan, ble_scan_poll, ble_scan_results, ble_scan_payloads, ble_scan_stop |
ble/scan* (BLE boards only) |
ble_connect, ble_connect_results, ble_services_start, ble_services_results, ble_services_stop, ble_disconnect |
ble/connect*, ble/services/*, ble/disconnect |
ble_write, ble_subscribe, ble_unsubscribe, ble_notifications |
ble/write, ble/subscribe, ble/unsubscribe, ble/notifications |
The JSON-RPC methods below remain callable directly.
Not implemented yet: progress notifications, cancellation of running scans or enumerations, logging/setLevel, pagination cursors, resources/templates/list, prompts, completion and elicitation.
Protocol
| Method | Params | Description |
|---|---|---|
initialize |
protocolVersion? |
Server info, negotiated protocol version, capabilities |
ping |
— | Liveness check; empty result |
tools/list |
— | MCP tools (see Tools) |
tools/call |
name, arguments? |
Call a tool |
resources/list |
— | List registered MCP resources |
resources/read |
uri |
Read a resource by URI |
resources/subscribe |
uri |
Subscribe to push updates for a resource |
resources/unsubscribe |
uri |
Cancel a subscription |
system/features |
— | Feature availability, state, owner and conflicts, plus the active memory plan (see Features and structured errors) |
Sensors
| Method | Params | Description |
|---|---|---|
sensors/i2c/scan |
— | Scan I²C bus; auto-detect and initialise drivers |
sensors/read |
sensorId? |
Read all channels of one sensor (omit ID to read all) |
sensors/i2c/scan
{"jsonrpc":"2.0","method":"sensors/i2c/scan","id":1}
{
"jsonrpc":"2.0","id":1,
"result":{"devices":[
{"address":118,"name":"BME280","supported":true,"parameters":["temperature","pressure","humidity"]},
{"address":104,"name":"MPU6050","supported":true,"parameters":["accel_x","accel_y","accel_z","gyro_x","gyro_y","gyro_z","temperature"]}
]}
}
sensors/read
{"jsonrpc":"2.0","method":"sensors/read","id":2,"params":{"sensorId":"bme280_0x76"}}
{
"jsonrpc":"2.0","id":2,
"result":{"readings":[
{"sensorId":"bme280_0x76","parameter":"temperature","value":22.4,"unit":"°C","timestamp":1234567890,"valid":true},
{"sensorId":"bme280_0x76","parameter":"humidity","value":58.1,"unit":"%RH","timestamp":1234567890,"valid":true},
{"sensorId":"bme280_0x76","parameter":"pressure","value":101320.0,"unit":"Pa","timestamp":1234567890,"valid":true}
]}
}
Bus History
Bus history accumulates CAN frames, NMEA lines, decoded NMEA 2000 messages, and OBD-II records in circular RAM buffers. The buffers are sized from a configurable RAM budget and their configuration is persisted to LittleFS.
| Method | Params | Description |
|---|---|---|
bus/history/read |
type, limit? |
Read accumulated messages from history buffers |
bus/history/config/get |
— | Read current buffer sizing configuration |
bus/history/config/set |
config fields | Resize buffers and persist configuration |
bus/history/read
type must be one of: can, nmea, nmea2000, obdii. limit defaults to all stored entries.
{"jsonrpc":"2.0","method":"bus/history/read","id":3,"params":{"type":"can","limit":10}}
{
"jsonrpc":"2.0","id":3,
"result":{
"type":"can",
"frames":["7E8#0441050300000000","7E8#04410D0000000000"],
"count":2,
"capacity":500
}
}
{"jsonrpc":"2.0","method":"bus/history/read","id":4,"params":{"type":"nmea2000"}}
{
"jsonrpc":"2.0","id":4,
"result":{
"type":"nmea2000",
"messages":[
{"pgn":129025,"priority":2,"source":0,"name":"Position Rapid Update",
"valid":true,"hasPosition":true,"latitude":47.6097,"longitude":-122.3331}
],
"count":1,"capacity":200
}
}
{"jsonrpc":"2.0","method":"bus/history/read","id":5,"params":{"type":"obdii"}}
{
"jsonrpc":"2.0","id":5,
"result":{
"type":"obdii",
"records":[
{"service":1,"pid":12,"name":"Engine RPM","value":1500,"unit":"rpm","valid":true},
{"service":1,"pid":13,"name":"Vehicle Speed","value":65,"unit":"km/h","valid":true}
],
"count":2,"capacity":300
}
}
bus/history/config/get
{"jsonrpc":"2.0","method":"bus/history/config/get","id":6}
{
"jsonrpc":"2.0","id":6,
"result":{
"canFrameCount":500,
"nmeaLineCount":1000,
"nmea2000Count":200,
"obdiiCount":300,
"ramBudgetBytes":1048576,
"safetyMarginBytes":65536,
"freeHeapBytes":2097152
}
}
bus/history/config/set
All fields are optional; omitted fields retain their current values.
{
"jsonrpc":"2.0","method":"bus/history/config/set","id":7,
"params":{"canFrameCount":1000,"ramBudgetBytes":2097152}
}
{"jsonrpc":"2.0","id":7,"result":{"ok":true,"canFrameCount":1000,"nmeaLineCount":1000,"nmea2000Count":200,"obdiiCount":300,"ramBudgetBytes":2097152,"safetyMarginBytes":65536}}
Set
canFrameCount,nmeaLineCount,nmea2000Count,obdiiCountall to0to enable auto-sizing: the server splitsramBudgetBytesequally among the four buffer types based on the size of each record type.
Metrics
| Method | Params | Description |
|---|---|---|
metrics/list |
category? |
List all registered metrics (name, type, unit, category) |
metrics/get |
name |
Current value of one metric |
metrics/history |
name, seconds? |
Historical samples for one metric (default: last 300 s) |
metrics/list
{"jsonrpc":"2.0","method":"metrics/list","id":8,"params":{"category":"system"}}
{
"jsonrpc":"2.0","id":8,
"result":{"metrics":[
{"name":"system.heap.free","type":"gauge","description":"Free heap","unit":"bytes","category":"system"},
{"name":"system.uptime","type":"counter","description":"Uptime","unit":"s","category":"system"},
{"name":"system.wifi.rssi","type":"gauge","description":"WiFi signal strength","unit":"dBm","category":"system"}
]}
}
Metric types: counter (cumulative integer), gauge (current value), histogram (min/max/mean/count object).
metrics/get
{"jsonrpc":"2.0","method":"metrics/get","id":9,"params":{"name":"system.heap.free"}}
{
"jsonrpc":"2.0","id":9,
"result":{"name":"system.heap.free","type":"gauge","value":214032,"unit":"bytes","category":"system","timestamp":1234567890}
}
For histogram metrics, value is an object: {"mean":…,"min":…,"max":…,"count":…}.
metrics/history
{"jsonrpc":"2.0","method":"metrics/history","id":10,"params":{"name":"system.heap.free","seconds":60}}
{
"jsonrpc":"2.0","id":10,
"result":{"name":"system.heap.free","entries":[
{"ts":1234567800,"val":214100},
{"ts":1234567830,"val":214032}
]}
}
Logs
| Method | Params | Description |
|---|---|---|
logs/query |
name?, seconds? |
Query binary metric log (default: last 3600 s) |
logs/clear |
— | Delete all log entries from LittleFS |
{"jsonrpc":"2.0","method":"logs/query","id":11,"params":{"name":"system.heap.free","seconds":120}}
{
"jsonrpc":"2.0","id":11,
"result":{"name":"system.heap.free","count":4,"entries":[
{"ts":1234567810,"val":214100},
{"ts":1234567840,"val":214032}
]}
}
{"jsonrpc":"2.0","method":"logs/clear","id":12}
{"jsonrpc":"2.0","id":12,"result":{"ok":true}}
Subscriptions
{"jsonrpc":"2.0","method":"resources/subscribe","id":13,"params":{"uri":"sensor://i2c/bme280_0x76"}}
After subscribing the server pushes unsolicited notifications/resources/updated on every value change:
{"jsonrpc":"2.0","method":"notifications/resources/updated","params":{"uri":"sensor://i2c/bme280_0x76"}}
Features and structured errors
Some features cannot run at the same time (for example BLE and an OTA flash), and some are not built for every board. system/features reports the live state of each one; the same document is published as the resource device://features, so a client can resources/subscribe to it and get notifications/resources/updated whenever a feature changes state.
OTA takes priority over BLE: an authenticated firmware upload stops a running scan and drops the GATT link, and BLE requests are refused with -32010 (blockedBy: "ota") until the upload ends.
{"jsonrpc":"2.0","method":"system/features","id":30}
{"jsonrpc":"2.0","id":30,"result":{
"features":[
{"id":"ota","available":true,"state":"idle","conflictsWith":["ble.central.scan","ble.central.gatt","ble.peripheral"]},
{"id":"ble.central.scan","available":true,"state":"active","detail":"scanning","owner":"client#2","conflictsWith":["ota","ble.peripheral"]},
{"id":"ble.central.gatt","available":true,"state":"idle","conflictsWith":["ota","ble.peripheral"]},
{"id":"ble.peripheral","available":false,"reason":"not implemented","state":"idle","conflictsWith":["ota","ble.central.scan","ble.central.gatt"]},
{"id":"sensors.i2c","available":true,"state":"idle","conflictsWith":[]},
{"id":"bus.can","available":true,"state":"idle","conflictsWith":[]}
],
"memoryPlan":{"mode":"psram","busHistoryInPsram":true,"busHistoryCap":1048576,"bleMaxDevices":64,"bleCaptureBytes":49152},
"board":"ESP32-S3-DevKitC-1"}}
state is idle, active (with a detail such as scanning, connecting, connected, discovering or flashing) or blocked (with blockedBy). A feature started by a client is owned by it, and is released when that client disconnects: its scan is stopped and its GATT link dropped, so a vanished client cannot hold the radio.
A request that cannot run gets a structured error instead of a bare started:false. The codes are stable:
| Code | Message | Meaning | data |
|---|---|---|---|
-32010 |
Feature busy | The feature is already running, or a conflicting feature is | feature, blockedBy, state, owner?, retryAfterMs, resolve? (method that clears the blocker) |
-32011 |
Feature unavailable | Compiled out, no hardware, or not implemented. Used for every ble/* method on boards without BLE, instead of -32601 |
feature, reason |
-32012 |
Resource limit | Reserved: memory-plan or buffer caps reached | — |
-32013 |
Feature not ready | A precondition is missing (e.g. ble/services/start while not connected) |
feature, reason, resolve? |
{"jsonrpc":"2.0","id":14,"error":{"code":-32010,"message":"Feature busy",
"data":{"feature":"ble.central.scan","blockedBy":"ble.central.scan","state":"scanning",
"owner":"client#2","retryAfterMs":3400,"resolve":"ble/scan/stop"}}}
Bluetooth (BLE)
The ESP32-S3 acts as a BLE central controlled over MCP: it captures what nearby devices broadcast (useful for reverse-engineering advertising formats) and can connect to a device to enumerate and read its GATT database. Every call is non-blocking or time-bounded, so a slow or misbehaving peer can never hang the MCP server.
Supported boards: esp32-s3-devkitc-1 and esp32-s3-devkitc-1-n16r8 (PSRAM). On the 4 MB-flash boards the BLE stack cannot fit alongside the WebSocket server and OTA, so the ble/* methods are not compiled there and return -32011 Feature unavailable; the nRF52 targets have no MCP server.
Capabilities
| Area | What it does |
|---|---|
| Advertising scan | Active scan (requests scan responses) for a fixed duration or continuously; per device: MAC, address type, name, RSSI, advertised services, manufacturer data, connectable flag, first/last seen |
| Payload history | Distinct raw payloads per device (up to 64, oldest dropped first) — payload changes reveal state changes in the broadcaster |
| Payload registry | Distinct payloads across all devices, independent of MAC — survives phones and trackers that rotate their MAC address |
| Capture filters | minRssi, manufacturerId, serviceUuid, macPrefix decide what is stored, so the device of interest is not crowded out in a busy RF environment |
| Connect | Asynchronous GATT connect with an enforced timeout; public, random static and resolvable private addresses (address type taken from the scan, or given explicitly); repeatable connect / disconnect / reconnect |
| Enumerate & read | All primary/secondary services and characteristics with properties (up to 512 attributes); every readable value read in full (long reads), as hex + printable text. Up to 512 bytes are kept per value with PSRAM, 128 without, and at most 32 KB (8 KB without PSRAM) over all values of the link. A longer value, or one that arrives once that total is used up, is cut and marked truncated: true, and length gives its real size |
| Notifications | During enumeration: subscribes to every notify/indicate characteristic and captures the latest value within a bounded window (≤ 10 s) |
| Write | ble/write writes a characteristic (with or without response, up to 512 bytes), addressed by handle or UUID. Needs the full-control token |
| Subscribe | ble/subscribe enables notifications or indications on one characteristic for as long as needed (up to 8 at once). Values are pushed to WebSocket clients as notifications/ble/value; HTTP clients read them with ble/notifications (32-value queue, oldest dropped and counted) |
| Memory-aware limits | Capture limits follow the boot-time memory plan: 64 devices / 48 KB with PSRAM, 24 devices / 16 KB without; least-recently-heard devices are evicted first |
MTU. After connecting, the device asks for an ATT MTU of 517 and reports the negotiated value as mtu in ble/connect/results. The exchange completes a few seconds after the link opens, and the MTU is 23 until then. Writes with a response can be up to 512 bytes; longer than MTU − 3, they are sent as a long write. A write without a response must fit in MTU − 3 bytes, otherwise it gets -32602 with data.mtu and data.maxBytes.
BLE 5 extended advertising. The S3 builds scan with the BLE 5 extended scanner (BLE_EXT_SCAN=1, the default; build with -D BLE_EXT_SCAN=0 for the legacy scanner). It listens on both the 1M and the Coded PHY and receives legacy and extended advertisements alike. A device seen with extended advertising gets "extended": true, plus phy (primary) and secondaryPhy (1M, 2M or coded) in ble/scan/results. Extended advertising data up to 1650 bytes is reassembled; the name, services and manufacturer data are parsed from all of it, and each payloadHistory entry keeps the first 64 bytes. With extended scanning, connects use the extended create-connection on the 1M PHY. The controller doesn't allow legacy and extended commands to be mixed.
Pairing and bonding. A characteristic that needs an encrypted link shows readError (for example insufficient-encryption) and needsPairing: true in ble/services/results. To read it:
- Call
ble/pair, then pollble/pair/resultsuntil it reportspaired. - Run
ble/services/startagain.
Pairing methods:
- Just Works: the default, with no parameters. The key is not authenticated.
- Passkey entry: with
mitm: true. If the peripheral displays a passkey,ble/pair/resultsreportsneeds: "passkey"; answer withble/pair/passkey. Alternatively, givepasskeytoble/pairup front, or useiocap: "display"with apasskeyfor the peripheral to type. - Numeric comparison:
resultsreportsneeds: "confirm"and thecompareValue; answer withble/pair/confirm.
Bonds are stored in NVS and survive reboots. On a later connection, ble/pair re-encrypts with the stored key, with no new pairing (existingBond: true). ble/bonds/list shows the bonds and ble/bonds/clear removes one or all. If you clear a bond here, also remove it on the peripheral. A peripheral that still holds an old bond asks for security when the link opens, and that pairing fails until it forgets the bond.
Not supported (yet): descriptor writes other than the CCCD; more than one connection at a time; and acting as a peripheral/advertiser.
Verified on hardware (ESP32-S3-DevKitC-1 N16R8) against an nRF52840 peripheral (random static address), an Android phone (rotating random address) and a BlueZ peripheral (public address): connect median 0.43 s (15/15), 47 connect/disconnect cycles with clean teardown on the peer, full enumeration of a phone (7 services / 37 characteristics) with ≥ 49 KB internal heap free throughout.
| Method | Params | Description |
|---|---|---|
ble/scan |
durationMs?, minRssi?, manufacturerId?, serviceUuid?, macPrefix? |
Start a scan (default 5000 ms; 0 = continuous until ble/scan/stop); returns immediately. If a scan is already running, or an OTA update is in progress: -32010 Feature busy with retryAfterMs (time left on a timed scan) and resolve: "ble/scan/stop". The optional capture filter decides which devices are stored (AND-combined; manufacturerId is a hex prefix of the manufacturer data with the company id little-endian, e.g. 0xDEAD → "adde"), so ambient traffic cannot crowd out the device of interest. Device count and capture size follow the boot-time memory plan (64 devices / 48 KB with PSRAM, 24 / 16 KB without); when full, the least-recently-heard device is evicted |
ble/scan/results |
mac?, serviceUuid?, manufacturerId?, macPrefix? |
Stop the scan (if running) and return captured devices; optional case-insensitive mac returns only that device with its full payload history; optional AND-combined response filters (serviceUuid, manufacturerId hex, macPrefix) never affect capture. Also returns evicted (devices dropped this scan to stay within the limits), maxDevices, and per-device lastSeen |
ble/scan/payloads |
— | Stop the scan and return the MAC-independent payload registry: distinct payloads across ALL broadcasters, first-seen order, with count + firstSeen/lastSeen (ms since scan start), plus dropped: distinct payloads discarded because the registry (64 entries) was full. The primary artifact for protocol reverse-engineering — survives per-MAC MAC-rotation churn |
ble/scan/poll |
— | Live read of the payload registry WITHOUT stopping the scan (stateless; diff by firstSeen) |
ble/scan/stop |
— | Stop a continuous scan early |
ble/connect |
mac, timeoutMs?, addrType? |
Begin an asynchronous GATT connect to a peer MAC (default timeout 10000 ms; a peripheral that advertises about once a second, like a BlueZ default, often needs 5–10 s). addrType is public, random, rpa-public or rpa-random; when omitted, the type recorded by the last scan for that MAC is used (public if it was not seen). Most phones, watches and sensors use random addresses and cannot be opened as public. A malformed mac is -32602; a link that is already connecting, connected, enumerating or closing (or an OTA in progress) is -32010 with the GATT state and resolve: "ble/disconnect" |
ble/connect/results |
— | Poll the outcome of the last async connect |
ble/disconnect |
— | Drop the GATT link |
ble/services/start |
— | Enumerate services/characteristics (background task); returns immediately. Not connected (or still connecting / closing): -32013 Feature not ready with resolve; an enumeration already running: -32010 with resolve: "ble/services/results" |
ble/services/results |
notifyCaptureMs? |
Wait for enumeration + notified values (default 3000 ms, capped at 10000 ms) |
ble/services/stop |
— | Unsubscribe from notifications and close the link |
ble/write |
handle or uuid, value (hex), withResponse? (default true), timeoutMs? (≤ 5000) |
Write a characteristic and wait for the write response. handle comes from ble/services/results; a uuid found in several services returns -32602 with the candidate handles. The characteristic must have the write (or, without response, write-no-response) property. Not connected or not enumerated yet: -32013; another write in flight: -32010; GATT failure: -32000 with gattStatus |
ble/subscribe |
handle or uuid, indicate? |
Enable notifications (default when supported) or indications. Result says delivery: "push" (WebSocket) or "poll" (HTTP) |
ble/unsubscribe |
handle or uuid |
Disable them again |
ble/notifications |
— | Values notified since the last call: {values:[{handle, uuid, valueHex, valueText, ts}], dropped, subscriptions, connected} |
ble/pair |
mitm?, passkey?, confirm?, iocap? (none, display, display-yesno, keyboard, keyboard-display) |
Encrypt the link, pairing and bonding first unless a bond exists. Asynchronous: returns {started, existingBond, iocap, mitm}. Not connected: -32013; already pairing: -32010 |
ble/pair/results |
— | {state: idle|pairing|paired|failed, encrypted, bonded, authenticated, existingBond, needs?, passkey?, compareValue?, reason?}. needs is passkey or confirm while it waits for an answer |
ble/pair/passkey |
passkey |
Enter the passkey the peripheral displays |
ble/pair/confirm |
accept |
Answer a numeric comparison |
ble/bonds/list |
— | {bonds:[{mac, addrType}]} |
ble/bonds/clear |
mac? |
Remove one bond, or all; {removed} |
ble/scan / ble/scan/results
{"jsonrpc":"2.0","method":"ble/scan","id":14,"params":{"durationMs":10000}}
{"jsonrpc":"2.0","id":14,"result":{"started":true,"scanning":true}}
{"jsonrpc":"2.0","method":"ble/scan/results","id":15}
{
"jsonrpc":"2.0","id":15,
"result":{"devices":[
{
"mac":"62:38:e6:6b:1c:f9","name":"","rssi":-56,"connectable":true,"addrType":"random",
"count":2,
"payloadHistory":[
"0201010effff006db643ce97fe427cd5964c03038fae",
"0201010effff006db643ce97fe427cc1ba0b03038fae"
],
"services":"0000ae8f-0000-1000-8000-00805f9b34fb",
"manufacturer":"ff006db643ce97fe427cd5964c"
}
]}
}
Notes for reverse engineering:
payloadHistoryholds the distinct raw payloads (oldest → newest) seen per device, bounded to 64 retained entries (payloads capped at 64 bytes each; the device count and total capture size follow the boot-time memory plan). A change between entries is a state change in the broadcaster (e.g. a button press or level change). When the bound is reached the oldest entry is dropped;countis the number of distinct payloads currently retained.- The unfiltered
ble/scan/resultsresponse serialises only the newest 4 payloads per device (countstill reports the true distinct total, sopayloadHistorylength may be less thancount). Pass the optionalmacparam (case-insensitive) to fetch a single device's full history — e.g.ble/scan/resultswith{"mac":"62:38:e6:6b:1c:f9"}. This keeps the quick-look response small even when the BLE radio is flooded while preserving deep per-device capture for protocol reverse-engineering. manufacturercontains the manufacturer-specific data as hex — company ID is the first two bytes (little-endian). The example payload above uses manufacturer ID0xFF00and the 8-byte prefix6D B6 43 CE 97 FE 42 7C(a broadcast-controlled toy protocol), withD5 96 4C→C1 BA 0Bshowing a state change.isConnectableis a heuristic from the BLE flags AD type; absent/malformed flags default to connectable.
ble/connect / ble/connect/results / ble/services/*
{"jsonrpc":"2.0","method":"ble/connect","id":16,"params":{"mac":"00:1b:66:c6:da:c8","timeoutMs":10000}}
{"jsonrpc":"2.0","id":16,"result":{"started":true,"connecting":true,"connected":false,"addrType":"public"}}
ble/connect returns immediately; the open handshake completes in the background within timeoutMs (the parameter is enforced). Poll for the outcome:
{"jsonrpc":"2.0","method":"ble/connect/results","id":17}
{"jsonrpc":"2.0","id":17,"result":{"connecting":false,"connected":true}}
{"jsonrpc":"2.0","method":"ble/services/start","id":18}
{"jsonrpc":"2.0","method":"ble/services/results","id":19}
{
"jsonrpc":"2.0","id":19,
"result":{"connected":true,"services":[
{"uuid":"00001800-0000-1000-8000-00805f9b34fb","characteristics":[
{"handle":3,"uuid":"00002a00-0000-1000-8000-00805f9b34fb","properties":"read",
"valueHex":"4c452d4844203335304254","valueText":"LE-HD 350BT"}
]}
]}
}
GATT enumeration runs in the background so a slow or uncooperative peer cannot block the MCP server. Every operation is time-bounded: the open handshake (timeoutMs), service discovery (10 s cap), characteristic reads (5 s for the whole read phase), and the notified-value capture window (notifyCaptureMs, default 3000 ms, capped at 10000 ms because the call blocks the MCP task while it waits). ble/services/stop (or ble/disconnect) closes the link, tearing down any in-flight work safely.
Client libraries and examples
| File | What |
|---|---|
examples/client/client.ts |
Typed WebSocket client: request(), tools, and BLE helpers: bleScanAndCollect, bleDevices, blePayloads, bleConnect (waits for the link), bleEnumerate, bleWrite, bleSubscribe(target, onValue), bleNotifications, bleDisconnect. Errors are MCPError with the server's code and data |
examples/client/ble_example.ts |
Scan → connect → enumerate → subscribe walk-through (npx tsx ble_example.ts [mac]) |
examples/client/mcp_ble.py |
Dependency-free Python client over Streamable HTTP, with a CLI: scan, enumerate <mac>, write <mac> <handle> <hex>, watch <mac> <handle>, tools |
Example GATT write and subscription with the Python CLI:
export MCP_URL=http://192.168.1.50 # and MCP_TOKEN=<token> if authentication is on
python3 examples/client/mcp_ble.py enumerate aa:bb:cc:dd:ee:ff --addr-type random
python3 examples/client/mcp_ble.py write aa:bb:cc:dd:ee:ff 32 01ff --addr-type random
python3 examples/client/mcp_ble.py watch aa:bb:cc:dd:ee:ff 34 --seconds 10 --addr-type random
I2C Sensor Reference
| Sensor | Addresses | Parameters | Units |
|---|---|---|---|
| BME280 / BMP280 | 0x76, 0x77 | temperature, pressure, humidity¹ |
°C, Pa, %RH |
| MPU6050 | 0x68, 0x69 | accel_x/y/z, gyro_x/y/z, temperature |
g, °/s, °C |
| ADS1115 | 0x48–0x4B | ch0_V, ch1_V, ch2_V, ch3_V |
V (±4.096 range) |
| SHT31 | 0x44, 0x45 | temperature, humidity |
°C, %RH |
| AHT20 | 0x38 | temperature, humidity |
°C, %RH |
| BH1750 | 0x23, 0x5C | light_lux |
lux |
| INA219 | 0x40–0x4F | bus_voltage_V, shunt_mV, current_mA, power_mW |
V, mV, mA, mW |
¹ humidity is not available on BMP280.
NMEA 0183 Sentences Supported
| Sentence | Description | Fields Decoded |
|---|---|---|
| GGA | GPS Fix Data | time, lat, lon, fix quality, satellites, HDOP, altitude, geoid separation |
| RMC | Recommended Minimum Navigation | time, active, lat, lon, speed (kn & km/h), course, magnetic variation |
| VTG | Track Made Good / Ground Speed | course (true & magnetic), speed (kn & km/h) |
| GSV | Satellites in View | total satellites, per-satellite PRN, elevation, azimuth, SNR |
| MWV | Wind Speed and Angle | angle, relative/true, speed, unit (K/M/N) |
| DBT | Depth Below Transducer | depth (feet / metres / fathoms) |
| DPT | Depth of Water | depth (metres) |
| HDG | Heading – Deviation & Variation | heading, deviation, variation (E/W) |
| HDT | Heading – True | heading (true north) |
Parsing features: XOR checksum validation, DDMM.MMMM → signed decimal degrees, HHMMSS.SS time, talker ID extraction, graceful empty-field handling.
NMEA 2000 PGNs Supported
| PGN | Name | Key Fields |
|---|---|---|
| 127250 | Vessel Heading | heading, variation |
| 127257 | Attitude | pitch, roll, yaw |
| 128259 | Speed Through Water | speedKnots |
| 128267 | Water Depth | depthMetres, offset |
| 129025 | Position Rapid Update | latitude, longitude |
| 129026 | COG & SOG | courseOverGround, speedOverGround |
| 130306 | Wind Data | speedKnots, angle, apparent/true flag |
| 130310 | Water Temperature | tempCelsius |
OBD-II PIDs Supported (Service 01)
Selected PIDs decoded; full list in src/CANParser.cpp:
| Category | PIDs |
|---|---|
| Engine | RPM, load, coolant temp, intake air temp, MAP, MAF, timing advance |
| Fuel | Fuel pressure, trim (short/long), rail pressure, injection timing, fuel rate |
| Emissions | O2 sensor voltages, EGR, evap system, DPF pressure |
| Motion | Vehicle speed, throttle position, accelerator pedal position |
| Temperature | Oil temp, intake air temp, EGR temp, engine exhaust gas temps (EGT) |
| Electrical | Control module voltage, battery voltage |
| Hybrid | Hybrid battery remaining life |
| Torque | Driver demand, actual torque, reference torque |
| Vehicle info | VIN, calibration IDs (service 09) |
Discovery
On network connect the server registers two mDNS services and periodically sends a UDP capability beacon:
| Discovery | Details |
|---|---|
| mDNS | _mcp._tcp and _http._tcp with TXT records: version, capabilities, detected sensors |
| UDP broadcast | JSON beacon to 255.255.255.255:5354 every 30 s (configurable); includes sensor manifest |
mDNS and UDP are triggered automatically on network join, I2C scan completion, MCP server ready, and bus history config changes.
Testing
Tests compile and run natively on Linux — no hardware required.
# All tests
pio test -e native
# Specific suites
pio test -e native -f test_nmea_parser
pio test -e native -f test_can_parser
pio test -e native -f test_i2c_sensors
pio test -e native -f test_bus_reader
pio test -e native -f test_mcp_server
pio test -e native -f test_metrics_system
# With coverage (requires lcov)
pio test -e native --coverage
| Suite | What is covered |
|---|---|
test_nmea_parser |
GGA, RMC, VTG, GSV, MWV, DBT, DPT, HDG, HDT, checksum validation |
test_can_parser |
OBD-II PIDs, NMEA 2000 PGNs 127250/127257/128259/128267/129025/129026/130306/130310 |
test_i2c_sensors |
BME280, MPU6050, ADS1115, SHT31, BH1750, INA219 via mock I2C |
test_bus_reader |
Timed reads, raw/parsed modes, timeout handling |
test_mcp_server |
JSON-RPC dispatch, resource management, method registration |
test_metrics_system |
Counters, gauges, histograms, LittleFS persistence |
Extending with Custom MCP Methods
Register additional JSON-RPC handlers at runtime:
mcpServer.registerMethodHandler("myns/doSomething",
[](uint8_t clientId, uint32_t reqId, const JsonObject& params) {
StaticJsonDocument<256> doc;
doc["result"]["ok"] = true;
std::string out;
serializeJson(doc, out);
return out;
});
// Remove when no longer needed
mcpServer.unregisterMethodHandler("myns/doSomething");
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Add tests for new functionality (
pio test -e nativemust pass) - Open a pull request
See CONTRIBUTING.md for coding style and guidelines.
License
MIT — see LICENSE.
관련 프로젝트 살펴보기
불러오는 중…