This document provides instructions for building, testing, and using the ESP32 Model Context Protocol (MCP) implementation.
- PlatformIO Core (CLI) or PlatformIO IDE
- Python 3.7 or higher
- Git
- ESP32 S3 DevKitC-1 board
- USB cable for programming
- (Optional) NeoPixel LED strip for LED control functionality
All required libraries are managed through PlatformIO's dependency system:
- FastLED
- ArduinoJson
- LittleFS
- ESPAsyncWebServer
- AsyncTCP
- Unity (for testing)
project_root/
├── platformio.ini # Project configuration
├── HOWTO.md # This file
├── data/
│ └── wifi_setup.html # Web interface file
├── include/
│ ├── NetworkManager.h # Network manager header
│ ├── RequestQueue.h # Thread-safe queue header
│ ├── MCPServer.h # MCP server header
│ └── MCPTypes.h # MCP types header
├── src/
│ ├── main.cpp # Main application file
│ ├── NetworkManager.cpp # Network manager implementation
│ └── MCPServer.cpp # MCP server implementation
└── test/
├── test_main.cpp
├── test_request_queue.cpp
├── test_network_manager.cpp
├── test_mcp_server.cpp
└── mock/ # Mock implementations for testing
├── mock_wifi.h
├── mock_websocket.h
└── mock_littlefs.h
-
Clone the repository:
git clone <repository-url> cd <project-directory>
-
Install project dependencies:
pio pkg install
-
Build the filesystem:
pio run -t uploadfs
-
For development build:
pio run
-
For release build:
pio run -e release
-
Build and upload to device:
pio run -t upload
-
Run all tests:
pio test -e native -
Run specific test file:
pio test -e native -f test_request_queue -
Run tests with verbose output:
pio test -e native -v
To generate test coverage report:
pio test -e native --coverage- Define the resource in MCPTypes.h
- Implement the resource handler in MCPServer
- Register the resource in main.cpp
Example:
// In main.cpp
mcp::MCPResource timeResource{
"system_time",
"system://time",
"application/json",
"System time information"
};
mcpServer.registerResource(timeResource);The device starts in AP mode if no WiFi credentials are configured:
- Connect to the ESP32 AP (SSID format: ESP32_XXXXXX)
- Navigate to http://192.168.4.1
- Enter WiFi credentials
- Device will attempt to connect to the network
The implementation follows the MCP specification with support for:
- Resource discovery
- Resource reading
- Resource updates via WebSocket
- Subscription system
begin(): Initializes network managementisConnected(): Checks WiFi connection statusgetIPAddress(): Gets current IP addressgetSSID(): Gets current network SSID
begin(bool isNetworkConnected): Starts MCP serverregisterResource(const MCPResource& resource): Registers new resourceunregisterResource(const std::string& uri): Removes resourcehandleClient(): Processes client requests
Thread-safe queue implementation for handling requests:
push(const T& item): Adds item to queuepop(T& item): Removes and returns item from queueempty(): Checks if queue is emptysize(): Returns number of items in queue
-
Upload Failed
- Check USB connection
- Verify board selection in platformio.ini
- Try pressing the BOOT button during upload
-
Network Connection Failed
- Verify WiFi credentials
- Check signal strength
- Ensure network supports ESP32
-
Test Failures
- Run tests with -v flag for detailed output
- Check mock implementations match real hardware behavior
- Verify test dependencies are installed
Enable debug logging in platformio.ini:
build_flags =
-D CORE_DEBUG_LEVEL=5For additional support:
- Check issue tracker
- Review MCP protocol documentation
- Contact development team
[License information here]