Skip to main content
Glama

thonny-ai

The MCP server and AI plugin for Thonny. Let Claude Code, Claude Desktop, Cursor or any MCP client program your Raspberry Pi Pico and ESP32 in MicroPython, visibly, safely and hands-free.

tests release License: MIT Python 3.10+ MCP MicroPython

thonny-ai demo: an AI agent drives Thonny, runs code, syncs files and watches a robot loop

Recorded with Thonny's local Python interpreter; with a board connected, the same tools drive MicroPython on the board.


thonny-ai connects AI coding assistants to Thonny, the beginner-friendly Python IDE used in many classrooms, and to the MicroPython board plugged into it. The AI can run code on the board, read sensors, watch a robot's main loop, manage files and deploy a project. Every command appears in Thonny's shell, in front of you, and you can require a click to approve each action.

  • 🧑‍🏫 For students and teachers: the AI's work is visible and reviewable, not hidden in a chat.

  • 🤖 For makers: “deploy, run, watch the sensor output, fix, repeat” without copy-paste.

  • 🔌 For MCP users: a clean, dependency-free MCP server for real hardware.

Contents

Quick start · What you can ask · Features · Tools · Compatibility · How it works · Security · FAQ · Contributing

Related MCP server: pico-bay

Quick start

Option A: ready-made Thonny (Windows). Download Thonny-AI-portable.zip, unzip, run thonny.exe. Nothing to install.

Option B: your existing Thonny. In Thonny, open Tools → Open system shell… and run:

pip install git+https://github.com/AstroQuestStudio/thonny-ai

Then restart Thonny, open View → AI Assistant and click Connect Claude Code. Done: start a new Claude Code session (or type /mcp) and talk to your board.

The server is started with Thonny's own Python (python -m thonny_ai_mcp):

{
  "mcpServers": {
    "thonny-ai": {
      "command": "C:/path/to/Thonny/python.exe",
      "args": ["-m", "thonny_ai_mcp"],
      "env": { "THONNY_AI_PROJECT": "C:/path/to/your/project" }
    }
  }
}
  • Claude Desktop: claude_desktop_config.json

  • Cursor: .cursor/mcp.json

  • Claude Code (manual): claude mcp add thonny-ai -s user -- "C:/path/to/Thonny/python.exe" -m thonny_ai_mcp

  • Any other client that speaks MCP over stdio works the same way.

On macOS / Linux use the python3 Thonny runs with (Tools → Open system shell…, then which python3).

What you can ask

“Blink the Pico W's onboard LED 5 times.”

“Read the internal temperature sensor every second for 10 seconds and tell me if it drifts.”

“Start src/main.py and watch the ultrasonic distance readings. Are they noisy? Suggest a filter.”

“Deploy src/ to the board and check that main.py starts without errors.”

“What files are on the board, and how much flash is left?”

“My motor doesn't turn: check the PWM on GP15, then try duty 50%.”

Features

👀 Visible AI

Code sent by the AI appears after >>> in Thonny's shell, syntax-highlighted and tinted, exactly as if it had been typed.

✋ Human in the loop

AI Assistant panel: a log of every action (run, write, delete, sync…). Tick Approve every AI action and nothing touches the board until you click Allow.

🔁 Long-running programs

start a robot loop or a sensor stream, monitor what it prints while it runs, interrupt it. The AI can debug code that never returns.

🔌 Auto-reconnect

Replug the board, or survive a USB glitch: Thonny reconnects by itself. No more “Connection lost, use Stop/Restart”. A deliberate Disconnect is never undone.

⚡ Smart sync

sync uploads a project folder and only sends files whose SHA-256 changed, then restarts main.py.

🧰 Works without Thonny

Thonny closed? The MCP server talks to the board over the serial port (MicroPython raw REPL), and can even listen to main.py without stopping it.

🪶 Zero extra dependency

Standard library + pyserial, which Thonny already bundles.

🌍 English / Français

The UI follows Thonny's language. More languages welcome.

AI code in Thonny's shell

AI Assistant panel asking for approval

MCP tools

Tool

What it does

status

How the board is reached right now: through Thonny (interpreter, port, state, approval mode) or direct serial

info

Board fact sheet: firmware, CPU MHz, free RAM and flash, unique id, Wi-Fi state, root files

exec

Run MicroPython code and return prints and tracebacks; a timeout interrupts runaway loops

start

Launch a program that runs forever (robot loop, data logger) without waiting

monitor

Read what the running program prints, without stopping it

interrupt

Stop the running program (Ctrl-C, escalating to Stop/Restart if needed)

run_file

Run a local .py file on the board without saving it there

ls · read · write · rm

Manage the board's filesystem

sync

Upload a folder (default src/), only changed files, then soft-reset (dry_run, force)

reset

Soft reset: boot.py then main.py run again

shell

Read Thonny's shell, i.e. what the user sees

open

Open a local file in Thonny's editor

Compatibility

Status

Thonny 4.1+ (tested on 5.0) on Windows, macOS, Linux

✅ unit tests on all three OS in CI

Raspberry Pi Pico W, MicroPython 1.29

🟢 early hardware tests passed (exec, files, deploy, through Thonny and serial); full checklist in progress

Raspberry Pi Pico / Pico 2 / Pico 2 W, ESP32, ESP32-S3, ESP8266

🟡 expected to work (same MicroPython raw REPL). Send a hardware report

CircuitPython boards

🟡 untested. Reports welcome

Claude Code, Claude Desktop, Cursor, any MCP stdio client

✅ standard MCP (protocol 2024-11-05 → 2025-06-18)

How it works

flowchart LR
    AI["AI client<br/>(Claude Code, Cursor…)"] -- "MCP / stdio" --> MCP["thonny_ai_mcp<br/>MCP server"]
    MCP -- "Thonny open:<br/>HTTP 127.0.0.1:47821" --> P["thonny-ai plugin<br/>inside Thonny"]
    P --> T["Thonny<br/>shell · panel · approval"]
    T -- USB --> B[("MicroPython board")]
    MCP -. "Thonny closed:<br/>serial raw REPL" .-> B
  • A serial port can only be opened by one program. While Thonny is connected it owns the port, so the MCP server goes through Thonny. That is also why everything shows up in its shell.

  • File transfers use Thonny's own backend commands, so they don't clutter the shell.

  • Each MCP tool call is one operation: one approval and one row in the panel, even when it needs many round-trips (a sync of 20 files, for example).

Security model

  • The bridge listens on 127.0.0.1 only.

  • Every request must carry the X-Thonny-AI: 1 header, and requests with an Origin header are rejected, so web pages open in your browser cannot reach it.

  • With Approve every AI action on, code execution and file changes wait for your click, and are denied after 2 minutes without an answer. Read-only actions (status, info, ls, read, monitor, shell) never wait.

  • When you deny an action, the AI receives an explicit “denied by the user” error.

Found a problem? Please report it privately, see SECURITY.md.

FAQ

Yes: thonny-ai. It ships a Thonny plugin and an MCP server (python -m thonny_ai_mcp) that lets any MCP client drive Thonny and the MicroPython board connected to it.

Yes. With thonny-ai, Claude Code can run MicroPython on the board (exec), deploy a project (sync), start a long-running program and read its output live (start + monitor), and manage files, while you watch everything in Thonny.

No. Its code is echoed in Thonny's shell and every action is logged in the AI Assistant panel. Turn on Approve every AI action to allow or deny each action before it runs.

No. When Thonny is closed, the MCP server connects to the board over USB serial by itself. Keeping Thonny open gives you the visual log, the approval gate and auto-reconnect.

mpremote and rshell are command-line tools for humans and scripts. thonny-ai is built for AI agents working next to a human: MCP tools with structured results, long-running program monitoring, and visibility and approval inside the IDE students already use. They work well side by side.

Any client that supports MCP over stdio: Claude Code, Claude Desktop, Cursor, VS Code with MCP, and more. The model itself runs in your client. thonny-ai only runs locally.

That is what it was designed for: everything the AI does is visible in the shell, logged in a panel, and can require the student's (or teacher's) approval. It is MIT-licensed and free.

Why not just copy-paste into a chatbot?

Copy-paste with a chatbot

CLI tools (mpremote…)

thonny-ai

AI runs code and reads the real output

❌ you relay it

⚠️ only through a shell tool

✅

Watch a running robot loop

❌

⚠️ manual

✅ start / monitor

Visible in the IDE, reviewable

❌

❌

✅

Approve each action

❌

❌

✅

Auto-reconnect after unplugging

❌

❌

✅

Beginner-friendly (Thonny)

✅

❌

✅

Configuration

Setting

Where

Default

Approve every AI action

AI Assistant panel

off

Auto-reconnect the board

AI Assistant panel

on

Bridge port

thonny_ai.port in Thonny's configuration / THONNY_AI_PORT for the MCP server

47821

Folder for relative paths

THONNY_AI_PROJECT

MCP server working directory

Disable serial fallback

THONNY_AI_SERIAL_FALLBACK=0

enabled

Force a serial port

THONNY_AI_SERIAL_PORT=COM3

auto-detect

Development

python -m pip install -e ".[test]"
PYTHONPATH=tests python -m unittest discover -s tests -v   # 54 tests, no board needed
python tests/e2e_thonny.py /path/to/thonny.exe             # 21 steps in a real Thonny window
python bundle/build_portable.py thonny-X.Y.Z-windows-portable.zip

The unit tests use a fake board (sandboxed filesystem) and a fake serial port speaking the MicroPython raw REPL protocol. The end-to-end script drives a real Thonny through the MCP tools. Real-board behaviour is checked with the hardware checklist.

Contributing

Contributions are very welcome, from a translation to a new tool: see CONTRIBUTING.md and the good first issues. Hardware reports for boards other than the Pico W are especially useful.

Roadmap

  • PyPI release and listing in Thonny's plugin manager

  • Wi-Fi (WebREPL): drive robots that can't stay on a USB cable

  • Plotter and variable snapshots for the AI

  • More UI languages

Français

thonny-ai permet à un assistant IA (Claude Code ou tout client MCP) de piloter Thonny et ta carte MicroPython (Raspberry Pi Pico, ESP32). Le code de l'IA s'affiche dans la console Thonny comme s'il était tapé, chaque action peut être soumise à ta validation, l'IA peut lancer un programme qui tourne en boucle (un robot) et lire ce qu'il affiche en direct, et Thonny se reconnecte tout seul quand on rebranche la carte. L'interface est en français si Thonny est en français.


If thonny-ai saves you time, a ⭐ helps other students and makers find it.

MIT © Mathis Cottereau · Not affiliated with the Thonny project: thonny-ai is a third-party plugin built on Thonny's public plugin interface.

Available Tools

15 tools
execA

Run MicroPython code on the board and return its output (prints and tracebacks). When Thonny is open, the code appears in its shell highlighted as coming from the AI, exactly like a student typing it. Stops the program currently running first. timeout in seconds (default 10, max 300); on timeout the code is interrupted. For programs that loop forever (robots, sensor streams) use start + monitor.

Inputs: code (required), timeout.

infoA

One-call board fact sheet: firmware and board name, CPU MHz, free/used RAM, free flash, unique id, Wi-Fi state, root files. Stops the program currently running.

Inputs: no named parameters.

interruptA

Stop the program running on the board (Ctrl-C, escalating to Stop/Restart in Thonny if needed).

Inputs: no named parameters.

lsC

List files on the board recursively, with sizes and free space.

Inputs: path.

monitorA

Read what the running program prints, for up to seconds (default 5, returns early if it ends). Never interrupts it: with Thonny closed it just listens to the board's console, so it also works for main.py running on its own after boot.

Inputs: seconds.

openA

Open a file from the computer in Thonny's editor (Thonny must be open).

Inputs: path (required).

readC

Read a file stored on the board.

Inputs: path (required).

resetA

Soft-reset the board (boot.py then main.py run again).

Inputs: no named parameters.

rmB

Delete a file or folder (recursively) on the board.

Inputs: path (required).

run_fileA

Run a .py file from the computer on the board without saving it there (path relative to the project directory). Default timeout 30 s.

Inputs: path (required), timeout.

shellA

Read the end of Thonny's shell, i.e. what the user sees (Thonny must be open).

Inputs: max_chars.

startA

Launch a long-running program WITHOUT waiting for it to end (robot main loop, sensor logging…): pass code, or path of a local .py file. Returns what it printed during the first wait seconds (default 1.5). Then use monitor to keep reading its output and interrupt to stop it. Stops the program currently running first.

Inputs: code, path, wait.

statusA

How the board is reached right now: Thonny open/connected (interpreter, port, state, whether the user must approve actions) or direct serial. Call it first when unsure.

Inputs: no named parameters.

syncA

Upload a project folder (default 'src') to the board, sending only files whose SHA-256 differs from the board copy, then soft-reset so main.py restarts. Options: remote_dir (default '/'), force (upload everything), dry_run (only report), reset (default true).

Inputs: force, reset, dry_run, local_dir, +1 more.

writeB

Write a text file on the board (parent folders are created).

Inputs: path (required), content (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 15 tools

    Disambiguation4/5

    The execution-related tools (exec, start, run_file, monitor) are closely related, but their descriptions clearly separate short-lived execution, long-running launch, output monitoring, and running a local file. A few side effects, like info also stopping the running program, could surprise agents, but overall the purposes are distinguishable.

    Naming Consistency3/5

    Names mix imperative verbs (exec, start, read, write), noun commands (info, status, shell), Unix-style commands (ls, rm), and one verb_noun pair (run_file). There is no consistent naming pattern, though all names are short, lowercase, and readable.

    Tool Count4/5

    Fifteen tools cover board execution, process control, filesystem management, and Thonny integration without feeling bloated. Some code-running tools could potentially be consolidated, but each addresses a distinct workflow.

    Completeness4/5

    The surface covers the main workflows: executing code, managing long-running processes, inspecting and modifying the board filesystem, and interacting with Thonny. Minor gaps exist, such as no direct way to run a file already stored on the board and text-only file writes.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to manage MicroPython and CircuitPython boards over USB, including listing boards, browsing and editing files, running Python code, resetting boards, and installing firmware.
      13
      254 npm
      7
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      Enables AI agents to compile, flash, erase, and read serial output from embedded development boards, with guardrails such as budget limits, serial port mutexes, and mandatory human confirmation for destructive operations.
      5
      -
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to interact with physical embedded target boards over a dual-CDC USB bridge using MCP tools. It exposes console reading, pattern waiting, command sending, reboot/login state machines, and in-RAM MicroPython execution while a single-owner daemon safely arbitrates access to the serial devices.
      6
      4
      Apache 2.0