Skip to main content
Glama
microbit-makecode-mcp

microbit-makecode-mcp

README.md
# microbit-makecode-mcp

MCP server that lets Claude (Claude Code / Claude Desktop) and other MCP clients **program the BBC micro:bit in Microsoft MakeCode** ([makecode.microbit.org](https://makecode.microbit.org/)): write the program, see it as blocks, fix compile errors, try it in the simulator, add extensions, save `.hex` files and flash the board over USB.

It works in the browser **you already have open** (Chrome or Edge): it attaches to it, uses its MakeCode tab (opening one if needed) and drives the editor the way its own buttons do. It never launches a browser of its own, so your MakeCode projects, settings and paired micro:bit stay where they are. It needs no firmware on the board and no private API.

How it differs from other micro:bit MCP servers: those talk to a board over USB serial (show text on the LEDs, read sensors) or build C++ CODAL firmware. This one is for **writing MakeCode programs**, the blocks and JavaScript that students and teachers use.

## Install

No install step is needed: MCP clients run it with `npx microbit-makecode-mcp` (Node.js 18+). To work on the code instead:

```powershell
git clone https://github.com/nguyenquocan0101/microbit-makecode-mcp
cd microbit-makecode-mcp
npm install
npm run build
```

## Allow the connection (once per browser)

Requires **Chrome 144+** (or a recent Edge).

1. In your browser open `chrome://inspect/#remote-debugging` (Edge: `edge://inspect/#remote-debugging`).
2. Turn on **Allow remote debugging for this browser instance**.
3. The first time the server attaches, the browser asks whether to allow it: click **Allow**.

The server finds the browser through the `DevToolsActivePort` file the browser writes into its profile folder (Chrome, Chrome Beta/Canary, Edge, Brave, Cốc Cốc, Chromium), then tries port 9222. If nothing is reachable, every tool says which case it is: no browser open, or remote debugging still off.

## Register with Claude

**Claude Code**

```powershell
claude mcp add microbit -- npx -y microbit-makecode-mcp
```

**Claude Desktop**: add to `claude_desktop_config.json` (`%APPDATA%\Claude\` on Windows)

```json
{
  "mcpServers": {
    "microbit": { "command": "npx", "args": ["-y", "microbit-makecode-mcp"] }
  }
}
```

Then ask, for example: *"Make a micro:bit program: button A shows a heart, button B shows the temperature. Test it in the simulator, then flash it."*

## Tools

| Tool | What it does |
|---|---|
| `status` | Attaches to your browser, opens MakeCode if needed; reports project, view, extensions, simulator, micro:bit connection, open dialogs |
| `screenshot` | Screenshot of the MakeCode window |
| `list_blocks` | Block APIs as TypeScript signatures with their block text. No argument: namespaces. With `namespace` (`basic`, `input`, `led`, `radio`, `neopixel`...): its functions |
| `get_code` | Reads the open program as MakeCode TypeScript |
| `set_code` | Replaces the program, shows it as blocks (or JavaScript when it has no block form) and returns compile errors |
| `new_project` | Creates a new project, optionally with code (your other projects are kept) |
| `add_extension` | Adds an extension: built-in (`servo`, `bluetooth`, `datalogger`...), GitHub `owner/repo`, or a search term (`maqueen`, `cutebot`...) |
| `run_simulator` / `stop_simulator` | Starts / stops the on-screen micro:bit simulator |
| `save_hex` | Compiles and saves a `.hex` file (copy it to the MICROBIT drive to flash; it also contains the source) |
| `open_file` | Opens a `.hex`, `.mkcd`, `.ts` or `.py` file as a project |
| `connect_device` | Connects the micro:bit over WebUSB through MakeCode's pairing dialog |
| `flash` | Compiles and flashes the connected micro:bit (connects first if needed); returns compile errors instead when there are any |

Programs are MakeCode TypeScript, which MakeCode shows as blocks:

```ts
input.onButtonPressed(Button.A, function () {
    basic.showIcon(IconNames.Heart)
})
basic.forever(function () {
    led.toggle(2, 2)
    basic.pause(500)
})
```

`set_code` replaces the whole program of the open project. Claude is told to read it first with `get_code` or to start with `new_project` when it may hold your work; MakeCode's own undo and project history still apply.

## USB and the first connect

WebUSB lets a page open a device only after a person picks it. The first `connect_device` (or `flash`) clicks through MakeCode's pairing dialog and the browser then shows its device chooser under the address bar: **select the micro:bit and click Connect**. Later connects reuse that permission. If the chooser is left unanswered, the tool reports it and closes the pairing dialog.

## Environment variables

| Variable | Purpose |
|---|---|
| `MAKECODE_CDP_URL` | Attach to this DevTools endpoint instead of discovering one (e.g. `http://127.0.0.1:9222`) |
| `MAKECODE_URL` | Editor URL (default `https://makecode.microbit.org/`; e.g. the beta editor) |
| `MAKECODE_BROWSER_DATA_DIRS` | Browser profile folders to look in for `DevToolsActivePort` (path-list separated) |

## Development

`npm run smoke` runs every tool through the MCP protocol against a throwaway browser:

```powershell
chrome --headless=new --remote-debugging-port=9333 --user-data-dir=$env:TEMP\mkmcp-profile
$env:MAKECODE_CDP_URL = "http://127.0.0.1:9333"; npm run smoke
```

## Limits

- MakeCode has no public API for a top-level page, so the server uses the editor's internal methods. If a MakeCode update changes them, tools fail with a clear "MakeCode internals changed" error instead of doing something wrong.
- Programs are read and written as TypeScript; Python projects can be opened but not edited as Python.
- The `flash` path has been checked up to the WebUSB device chooser; flashing a real board has not been tested yet.

## License

[MIT](LICENSE)

TDQS

A3.8/5.0

Scored across 13 tools

Disambiguation4/5

Most tools target a distinct resource+action pair (get_code/set_code, run_simulator/stop_simulator, save_hex/flash, connect_device). The few overlaps — set_code vs new_project both injecting a program, and flash vs connect_device (flash connects implicitly) — are explicitly clarified in the descriptions. An agent can select correctly, though it must read carefully for the code-writing and device-flashing pairs.

Naming Consistency4/5

The dominant pattern is verb_noun (list_blocks, get_code, set_code, new_project, add_extension, run_simulator, save_hex, open_file, connect_device), which is predictable and readable. A handful of deviations — bare nouns 'status' and 'screenshot', and the bare verb 'flash' — are natural terms but break the pattern slightly.

Tool Count5/5

13 tools is squarely in the well-scoped range and each one maps to a real workflow step: attach, inspect, read/write code, extensions, simulate, save, open, connect, flash. There is no filler or redundant tool in the set.

Completeness4/5

The core lifecycle — attach, read code, replace code, new project, add extensions, list blocks, simulate, save .hex, open files, pair and flash a device — is fully covered with no dead ends. Minor gaps exist: no way to remove an extension, no listing/switching among MakeCode's existing projects, and no serial/console output reading during simulation or flashing.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues