Tutorial: LAN AI MCP Bridge & Autonomous Agent Workflow
PylotOS includes a zero-dependency Model Context Protocol (MCP) JSON-RPC 2.0 stdio server (tools/mcp_bridge/ in PylotOS/pylotos) and a repo-packaged agent skill (skills/pylotos-dev/SKILL.md).
Together with pylotos-sdk, AI coding agents (Claude Code, Cursor, Windsurf, VS Code Copilot, Gemini CLI) can write an adaptive MicroPython app, verify it locally in pylotos-sim, deploy it over Wi-Fi to a physical ESP32 board, read live stdout/stderr logs, and visually inspect a PNG screenshot of the real LCD — closing the entire embedded hardware-in-the-loop cycle autonomously.
1. Setup in Claude Code / Cursor / Windsurf
Add the bridge to .mcp.json (or claude_desktop_config.json):
{
"mcpServers": {
"pylotos": {
"command": "python3",
"args": ["-m", "tools.mcp_bridge"],
"cwd": "/path/to/pylotos",
"env": {
"PYLOTOS_HOST": "pylotos-cardputer.local",
"PYLOTOS_OTA_KEY": "optional-fleet-key-for-unattended-deploy"
}
}
}
}
Tip: Even without PYLOTOS_HOST, calling discover_devices automatically scans _pylotos._tcp.local. via mDNS and probes /api/ota/info across your LAN!
2. Complete 15-Tool MCP Reference
| Category | Tool Name | Purpose |
|---|---|---|
| Discovery & HW | discover_devices | Multicast mDNS (_pylotos._tcp.local.) + HTTP probe returning board IDs, chips, IPs, and asym-v1 OTA state. |
describe_board | Full hal.describe() JSON: display archetype, input caps, memory/PSRAM, buses, active wireless radios & expansion_ports. | |
| Visual & UI | get_ui_state | Current pylotos.ui widget tree, focus index, active theme, and notification queue JSON. |
capture_screenshot | Captures the live physical ESP32 framebuffer over :8266 and returns an MCP image/png block for multimodal AI vision! | |
| App Lifecycle | list_apps | Lists installed /apps/* scripts, active running state, and boot autostart config. |
read_app_file | Reads UTF-8 source or config files under /apps/. | |
deploy_app | Atomic SHA-256 verified upload with automatic .bak backup, optional run=true, and crash rollback_guard=true. | |
run_app / stop_app | Starts or cleanly stops a foreground /apps/ script (triggering hal.wireless_reset_app_handles()). | |
rollback_app | Restores the previous .bak version of an app in one call. | |
read_app_logs | Incremental since_seq stdout/stderr ringbuffer reader for live exception & print debugging. | |
| Config & Diag | get_app_config / set_app_config | Reads or deep-merges per-device /apps/.config/<app>.json overrides without modifying shared Python code. |
get_coredump | Checks 0x13000 Flash ELF Core Dump metadata and optionally downloads Base64 ELF slices. | |
trigger_ota_check | Queries or triggers Asymmetric Recovery-OTA (asym-v1) checks against a manifest URL. |
3. Recommended Autonomous Agent Loop
- Inspect Hardware: Call
discover_devices->describe_boardto learn exact screen dimensions, input profile, and attached radios/overlays. - Simulate Locally First: Run
pytestorpylotos-sim <script.py> --board <board_id>usingpylotos-sdkto catch layout or MicroPython syntax issues in< 1s. - Atomic Deploy: Call
deploy_app(path="my_app.py", content=..., run=True, rollback_guard=True). - Verify Logs & Pixels: Call
read_app_logsto confirm zero tracebacks, then callcapture_screenshotto visually confirm widget alignment on the physical screen!