Skip to main content
Glama
mcp-box-of-synths

mcp-box-of-synths

by boxofrules
README.md
# mcp-box-of-synths

[![Ko-fi](https://img.shields.io/badge/Ko--fi-Support%20Box%20Of%20Rules-FF5E5B?logo=ko-fi&logoColor=white)](https://ko-fi.com/boxofrules)

The [Model Context Protocol](https://modelcontextprotocol.io/) server for
[Box Of Synths](https://boxofsynths.com), the free synth from Box Of Rules that designs
sounds from words. It gives any MCP client, Claude Desktop, Claude Code, an agent of your
own, **25 tools**: a capability descriptor and contract handshake, the parameter registry, the
patch recipe schema, knowledge-base search, identity resolution, patch design, render,
validation and clamping, theme building, the local preset library, a door into the
running plugin (its Inbox, Outbox and status), and the player's Waveform Analyser runs, so an
agent can be the designer.

The server runs no model of its own. Whatever connects to it already brings one, so it
exposes the database, the contract and the write paths, and the connecting model does the
designing. There is nothing to host and no key to issue.

> **The knowledge base is not in this repository.** The server reads the Box Of Synths
> knowledge base from a `data/` folder, which is proprietary and is not published here. It will
> ship with the Box Of Synths installer; until then the server starts, but the knowledge tools
> have nothing to search. The source is published for reference and may be made private again
> once the server ships inside the installer. Box Of Synths: patent applications pending.

## Features

### The contract
- **`get_capabilities`**: start here. Every closed vocabulary in the recipe contract (families, waves, filter types, control and link targets, slot kinds, fx refs, modules, theme keys), the hard limits, the size of the registry and knowledge base, which optional features work on this machine right now, and the suggested order of calls.
- **`contract_version`**: which recipe schema this server writes and the oldest it reads. Pass the highest schema you understand as `client` and it says plainly whether the two can interoperate, so a mismatch is caught in one call rather than as a pile of validation errors later.

### The recipe
- **`list_params`**: every addressable parameter (112): id, label, group, kind, range, default, unit, choices.
- **`get_schema`**: the patch recipe as a JSON Schema 2020-12 document, schema version 2: oscillators, sub, noise, filter, envelopes, LFOs, chorus and delay, the IR blend, the analogue pre-amp voice on the sum (`analogue.voice` 0-19, `analogue.amount` 0-100), the modules (pre-amp channel, octaver, fuzz, bit crusher, flange, phaser), `post`, `mix`, `links`, controls with their `tip`, and slots with `kind`, `ref` and `locked`.
- **`validate_patch`**: strict checks against that contract, `{valid, errors[]}`. Rejects; never repairs.
- **`clamp_patch`**: the forgiving counterpart. Returns the canonical patch the plugin would load with every addressable parameter pulled into range, and names what it changed, so a clamped 40000 Hz cutoff is something you are told about rather than something you discover by ear. Anything clamping cannot repair -- a bad `family`, say, which it will not guess at -- comes back in `remaining_errors`.
- **`set_param`**: one parameter on a patch, clamped to its range and kind. `fx.octave.mix` is the two-sided octaver dial.
- **`add_slot` / `remove_slot`**: pin a registry parameter onto the row, or take it off.

### Designing and hearing
- **`search_knowledge`**: text search over the synth knowledge base (synths, iconic patches, effects, drum machines, genres, glossary).
- **`resolve_identity`**: what a request is actually about, without designing anything. Runs the designer's own identity gate and reports the record and the synth it elected, each with its score. It is the same matcher `design_patch` uses, so what you are told was matched is what would be matched.
- **`design_patch`**: words in, a complete valid patch out. A TypeScript port of the plugin's offline designer, cross-checked against the plugin's own console tool when it is built.
- **`render_patch`**: renders a patch or a whole rack to a WAV through the plugin's `BoSynTest render` and returns peak, RMS, dBFS, duration.
- **`make_theme`**: a valid theme JSON from a handful of colours.

### The library
- **`list_presets` / `get_preset` / `save_preset`**: the local preset library the plugin reads (`~/Music/Box of Rules/Synths`).

### The running plugin
- **`plugin_status`**: what the plugin is doing, from its `status.json`: version, method, whether it is in MCP mode, the sound on the synth, the requests waiting.
- **`plugin_read_requests`**: what the player typed while the plugin's METHOD is MCP, oldest first, with the current patch and their standing note.
- **`plugin_load_patch`**: drops a patch in the plugin's Inbox. A running instance puts it on the synth as one undo step. `answers` clears the request it answers; `note` is a line in the chat.
- **`plugin_request_design`**: asks the plugin to design through whichever designer the player chose. Optional `analysis_run` (a uuid from `list_analyses`) aims that design at a Waveform Analyser recording's measured fingerprint.

- **`plugin_draw_wave`**: sends a drawn waveform (`samples`, one cycle of 8 to 4096 numbers from -1 to 1, or a named `shape`) to the running plugin. Free: the app's own matcher recreates it, no AI and no tokens. Every take is saved, take 1 goes on the synth, and the takes come back with how each was made and `error_db` (lower is closer).
- **`plugin_use_draw_take`**: puts another take from an earlier drawing on the synth, by the `id` `plugin_draw_wave` returned.

### The Waveform Analyser
- **`list_analyses`**: the player's saved Waveform Analyser runs from boxofsynths.com -- Box Of Synths and the Waveform Analyser share one account and one token wallet. Each run carries a uuid, type, label, source file and a measured summary (duration, spectral shape, band percentages, loudness, dynamics, pitch/harmonic and rhythm facts). Pass a run's uuid to `plugin_request_design`'s `analysis_run` to have the hosted designer aim at it. A clear structured error, not a crash, when there's no site token, the token isn't live, the site is unreachable, or none are available.

## Requirements

- Node 20 or newer (built and tested on 24).
- For `render_patch` and the design cross-check: the plugin repo built beside this one, or `BOSYN_BINARY` pointing at its `BoSynTest`. Everything else works without it.
- For the `plugin_*` tools: Box Of Synths 1.0.2 or later open on the same machine. It reads its Inbox every two seconds whatever method is chosen; `plugin_read_requests` (requests the player types) waits for the Agent method, which is not selectable yet in 1.0.2.

## What works today

Everything except the knowledge base. With this repository alone:

- the contract tools (`get_capabilities`, `list_params`, `get_schema`, `validate_patch`, `clamp_patch`, `set_param`, slots, themes) work in full;
- `design_patch` designs from its built-in rules; with the knowledge base it also matches named synths, records and artists;
- the `plugin_*` tools drive Box Of Synths while it is open on the same machine: load a patch, ask for a design (made from the database unless you allow agents to spend in Settings, Advanced), set a theme, draw a wave;
- `search_knowledge` and `resolve_identity` answer, but find nothing until the knowledge base is installed.

The knowledge base ships with the Box Of Synths app. To use it, point `BOSYN_DATA_DIR` at its data folder.

## Installation

```bash
git clone https://github.com/boxofrules/mcp-box-of-synths.git
cd mcp-box-of-synths
npm install
npm run build
```

## Configuration

### Claude Code

```bash
claude mcp add box-of-synths -- node /path/to/mcp-box-of-synths/dist/stdio.js
```

### Claude Desktop

Add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "box-of-synths": {
      "command": "node",
      "args": ["/path/to/mcp-box-of-synths/dist/stdio.js"],
      "env": {
        "BOSYN_BINARY": "/path/to/inst-box-of-synths/build/BoSynTest_artefacts/Release/BoSynTest"
      }
    }
  }
}
```

### Environment

Copy `.env.example` to `.env` if anything differs from the defaults.

| Var | Default | What it does |
| --- | --- | --- |
| `PORT` | `8788` | HTTP transport port. |
| `PUBLIC_URL` | `https://mcp-synths.boxofrules.com` | What the served server card advertises. A placeholder until a domain is decided. |
| `BOSYN_BINARY` | `../inst-box-of-synths/build/BoSynTest_artefacts/Release/BoSynTest` | The plugin's console tool. Missing is reported as `binary_missing`, never a crash. |
| `BOSYN_PRESET_DIR` | `~/Music/Box of Rules/Synths` | The plugin's library: presets, and the Inbox, Outbox and `status.json` the `plugin_*` tools use. |
| `BOSYN_SOURCE_DIR` | `../inst-box-of-synths` | Only the two generator scripts read it. |
| `BOSYN_SETTINGS_FILE` | platform default, see Activation below | The plugin's JUCE PropertiesFile settings path. |
| `BOSYN_LICENCE_STATE` | unset | Dev override for the licence gate (`unlocked`/`trial`/`locked`). See Activation below. |
| `BOSYN_SITE_URL` | the settings file's `bosyn_site_url`, then `https://boxofsynths.com` | Override for `list_analyses`. See Waveform Analyser below. |

## Activation

Box Of Synths is a licensed plugin: a player activates it with a licence key, and the plugin
records that on the machine in two places, neither of which this server writes:

- `<library>/status.json` -- `"activated": true|false` and `"state": "unlocked"|"trial"|"locked"`.
- its own settings file, a JUCE PropertiesFile (`<VALUE name="bosyn_licence_state" val="..."/>`
  among others) at `~/Library/Application Support/Box of Rules/Box of Synths/Box of Synths.settings`
  on macOS, `%APPDATA%\Box of Rules\Box of Synths\Box of Synths.settings` on Windows, or
  `~/.config/Box of Rules/Box of Synths/Box of Synths.settings` on Linux.

`src/lib/licence.ts`'s `licenceState()` reads both (status.json first, once the plugin has
written a boolean `activated` into it; the settings file otherwise) and answers `unknown` --
counted as **not activated** -- when neither says anything. `unlocked` and `trial` both count as
activated; `locked` does not.

**What's gated.** `buildServer()` wraps every tool except five in the licence check: an
unactivated call returns an MCP error (`isError: true`) naming the state and
`https://boxofsynths.com/buy`, before the real handler runs. The five that stay open regardless
of activation, because they only describe the contract or say why everything else is locked:
`get_capabilities`, `contract_version`, `plugin_status`, `list_params`, `get_schema`. Everything
that touches the knowledge base, designs, renders, reads or writes presets, or reads or writes
the plugin's Inbox/Outbox is gated. `get_capabilities` and `plugin_status` both carry a `licence`
field (`{state, activated, source}`) so a connecting agent can see exactly why it is locked.

**Dev override.** `BOSYN_LICENCE_STATE=unlocked` (or `trial`/`locked`) short-circuits both files
-- for tests, and for James's own machine before the plugin build lands. An unrecognised value
is treated as `unknown` (fails closed, not open).

## Waveform Analyser

Box Of Synths and the [Waveform Analyser](https://boxofrules.com) share one account and one
token wallet. The same settings file the plugin writes for activation also carries
`bosyn_site_token` (the machine's API key, `bos_...`) and `bosyn_site_url` -- `src/lib/site.ts`
reads them (`BOSYN_SITE_URL` overrides the URL for tests) and calls boxofsynths.com's
`GET /api/v1/analyses` to fetch the player's saved Waveform Analyser runs. `list_analyses` (a
gated tool, like every other data tool) returns them: uuid, type, label, source file and a
measured summary (duration, spectral centroid/rolloff/bandwidth/flatness, band percentages,
LUFS, crest factor, dynamic range, harmonic ratio, fundamental, inharmonicity, zero-crossing
rate, tempo). Pass a run's uuid as `plugin_request_design`'s `analysis_run` and a running
instance forwards it to `POST /api/v1/design`, aiming the hosted designer at that recording's
measured fingerprint instead of only its words. `get_capabilities`'s `features.analyses.available`
says whether a site token is configured at all, without making the network call itself.

## Usage

With the plugin's METHOD set to MCP, the player types a request and the plugin writes it to
its Outbox. An agent with this server:

1. `plugin_read_requests` to see what was asked, with the current patch.
2. `design_patch` (or its own judgement) to make a patch; `validate_patch` to be sure.
3. `plugin_load_patch { patch, answers: <id>, note: "what I went for" }`. The sound lands on the synth as one undo step and the note appears in the chat.

Without the plugin running, the same tools design, validate, render and save patches to the
library, where the plugin's LIBRARY finds them.

## Transports

- **stdio** (`npm run start:stdio`): one process per client. What the configuration above uses.
- **Streamable HTTP** (`npm start`): stateless, a fresh server per request, `POST /mcp`, a server card at `/.well-known/mcp/server-card.json`, `/up` for health. The same shape as the family server `mcp-box-of-rules`. Smoke test:

```bash
curl -s -X POST http://localhost:8788/mcp \
  -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"design_patch","arguments":{"request":"warm analog pad"}}}'
```

## Development

```bash
npm test                 # tsc, then node's built-in test runner: 158 tests
npm run extract-params   # regenerate data/params.generated.json from the plugin's SynthParams.h
npm run sync-knowledge   # copy the plugin's knowledge base into data/
```

`src/lib/recipe.ts` is a faithful port of the plugin's `Patch::fromVar` / `toVar`, quirks
included; read its header before changing it. `src/lib/params.ts` holds a hand-written
accessor per registry id and refuses to start if the generated registry names one it lacks.
The tests run end to end over the SDK's in-memory transport and over the real stdio entry;
the ones that need the built plugin binary skip rather than fail without it.

## Deployment

Not yet. When it is time: `Dockerfile` and `deploy/` carry the same systemd and nginx shape
as `mcp-box-of-rules`; `.github/workflows/build.yml` publishes an image on a `v*` tag; the
domain in `resources/server-card.json` is a placeholder. A Linux host will not have
`BoSynTest`, so `render_patch` reports `binary_missing` there until a Linux build ships.

## Changelog

See [CHANGELOG.md](CHANGELOG.md).

## Licence

To be decided before publication. `package.json` says MIT for the server code; the plugin
it talks to is source-available and proprietary, and its knowledge base is Box Of Rules'.