Skip to main content
Glama
mpc-bridge
by brcina
README.md
# mpc-bridge

Makes the content of a song on an **Akai MPC** readable for an AI assistant: tracks, programs, pads, sequences,
clips and **notes**. While working on the MPC you can talk to the assistant about composition, arrangement, harmony
and groove, and the assistant knows what is actually in the song.
It connects through the open Model Context Protocol (MCP) and a CLI, so it works with any MCP-capable assistant.

```
User:       The bassline in scene 1 feels too busy, what do you think?
Assistant:  (reads the song) The bass plays C#2 on every eighth and hits almost every kick on beats 1 and 3.
            Leave out beat 1 and come in on 1.2.480 instead; that gives the kick room …
```

**Status:** v1 in progress. Reading and rendering local project files works (CLI, tested on real projects).
Next: fetch projects from the MPC over SSH, MCP server. Progress: [ROADMAP.md](ROADMAP.md).

Tested with an MPC Live III on MPC OS 3.10.1. Unofficial, not affiliated with Akai/inMusic.

## How it works

```
MPC (developer mode, SSH)
 └─ save the project (.xpj)
        │ SSH (fetch, spec 003)
        ▼
Computer
 ├─ xpj.ts     gzip → 5 header lines → JSON
 ├─ parse.ts   JSON → song model (model.ts): tracks, pads, sequences, clips, notes
 ├─ render.ts  text for the assistant: overview, notes per bar with chords, drum grid
 ├─ CLI        mpc-bridge overview | track | tracks
 └─ MCP        tools for the assistant (spec 004)
```

The `.xpj` of MPC OS 3.x is compressed JSON containing every note. Reading it needs no code on the MPC and no script
signing ([ADR 0001](docs/adr/0001-read-xpj-over-ssh.md)). Format: [docs/xpj-format.md](docs/xpj-format.md).

| Version | Content |
|---|---|
| **v1** | Save → fetch `.xpj` over SSH → CLI + MCP server |
| **v2** | Lua script on the MPC: export on request (no saving), write notes into new clips |
| **v3** | Live state: selected track, playing clips, transport, Q-Links |
| **v4** | Mixdown analysis |

## Requirements

- **Node.js ≥ 24** (runs TypeScript directly, no build step)
- To access the MPC: MPC OS ≥ 3.10.1 with **developer mode**, MPC and computer on the same network
  (not a guest Wi-Fi; client isolation blocks SSH there)

## Installation

```sh
git clone https://github.com/brcina/mpc-bridge.git && cd mpc-bridge
npm install
```

With nvm: `nvm use` (the version is in `.nvmrc`).

## Usage

```sh
node src/cli.ts overview <project.xpj> [--seq N]                                # song overview
node src/cli.ts track    <project.xpj> <track no.|name> [--seq N] [--steps 16|32]  # one track
node src/cli.ts tracks   <project.xpj> [--seq N]                                # all tracks in detail
```

Tracks are selected by number (as on the MPC, starting at 1) or by name (also partial, case-insensitive).
The text output is currently German (see the open question in [spec 004](specs/004-mcp-server/requirements.md)).

Fetching a project from the MPC until `fetch` exists:

```sh
ssh root@<MPC-IP> 'cat "/media/<drive>/Projects/NAME.xpj"' > samples/NAME.xpj
```

### Preparing the MPC (developer mode)

Preferences → Info, then tap: the **Version** value 3×, the **Serial number** value 2×, the **Firmware version**
value 1×. Then `ssh root@<MPC-IP>` (IP under Preferences → Wi-Fi). Note: root SSH **without a password**; use it only
on your own network and switch it off before travelling ([spec 001](specs/001-secure-ssh/requirements.md)).

## Development

```sh
npm test            # tests
npm run typecheck   # type check
```

Workflow (specs, ADRs), conventions and rules for contributions: [CONTRIBUTING.md](CONTRIBUTING.md).
Notes for AI assistants: [AGENTS.md](AGENTS.md).

### Project structure

```
mpc-bridge/
├─ src/
│  ├─ xpj.ts       decode .xpj (gzip, header, JSON)
│  ├─ raw.ts       loose types for the raw JSON
│  ├─ model.ts     song model + helpers (audible notes, positions, note names)
│  ├─ parse.ts     raw JSON → song model
│  ├─ theory.ts    key estimate, chord names, note lengths
│  ├─ render.ts    text output (for assistants and the terminal)
│  └─ cli.ts       command line
├─ test/           node:test
├─ specs/          one folder per piece of work: requirements, design
├─ docs/adr/       architecture decisions
├─ docs/           xpj-format.md, research.md
└─ samples/        your own .xpj files for testing (not in git)
```

## Security and privacy

- Developer mode opens root SSH without a password: only on your own network.
- Later Lua scripts need a signing salt read from your own MPC. It is never committed or published, and neither are
  Akai binaries ([ADR 0005](docs/adr/0005-signing-salt-stays-local.md)).
- Songs (`samples/`, `.cache/`) stay local.

## References

External repos used for reading, cloned next to this repo in `../refs/` (not part of it):

| Repo | Used for |
|---|---|
| `MPC-project-file-definitions` | Docs of the `.xpj` format (OS 3.7+) |
| `mpfree` | `tools/mpc-import/inspect-xpj.py`: Python reference for reading `.xpj` |
| `padporter` | `core/src/XpjReader.cpp`: `.xpj` → MIDI (C++) |
| `mpcsample` | `.xpj` codec (TypeScript) |
| `mpc-controllers` | Lua controller script API (3.10), limits, findings |
| `mpc-launchpad-pro-mk3` | Complete Lua API dump |
| `mpc-plugin-builder-sdk` | Official plugin SDK, SSH patterns |
| `mpc-vst-plugins` | MPC OS internals, plugin manager |
| `mpc-remote-screen` | Remote screen viewer |
| `az0x-open-source` | GPL sources of the MPC Linux environment |

## License

[MIT](LICENSE). Akai, MPC and inMusic are trademarks of their respective owners; this project is unofficial.