Skip to main content
Glama
SuperCollider Headless MCP Server

SuperCollider Headless MCP Server

by dheerajstvpm
README.md
# SuperCollider Headless MCP Server

[![npm version](https://img.shields.io/npm/v/supercollider-headless-mcp.svg)](https://www.npmjs.com/package/supercollider-headless-mcp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org/)
[![Status: Active Development](https://img.shields.io/badge/status-active%20development-orange.svg)](https://github.com/dheerajstvpm/supercollider-headless-mcp)

> ⚠️ **Active Development** β€” This project is under active development. APIs may change between versions. Use in production at your own risk.

An **Model Context Protocol (MCP) server** that gives any MCP-compatible LLM unrestricted access to **SuperCollider** audio synthesis (`scsynth`) and algorithmic composition (`sclang`) β€” **zero manual installation required**.

## πŸš€ One-Command Installation

```bash
npx -y supercollider-headless-mcp
```

That's it. The server automatically:
1. Downloads the latest official SuperCollider release for your platform (Windows/macOS/Linux)
2. Extracts it to `~/.supercollider-mcp/runtime/` (no admin rights needed)
3. Prunes IDE/GUI bloat, keeping only `sclang`, `scsynth`, `SCClassLibrary`, `plugins`, and runtime libraries
4. Boots `scsynth` in headless mode with a versatile starter SynthDef library
5. Exposes 6 MCP tools + 2 reusable prompts for audio synthesis and algorithmic composition

## πŸ“¦ Supported MCP Clients

| Client | Configuration |
|--------|---------------|
| **Claude Code** | `claude mcp add supercollider npx -y supercollider-headless-mcp` |
| **VS Code (Copilot)** | Add to `.vscode/mcp.json` (see below) |
| **Cursor** | Settings β†’ MCP β†’ Add server |
| **Cline** | Settings β†’ MCP Servers β†’ Add |
| **Windsurf** | Settings β†’ MCP β†’ Add server |

### VS Code / Copilot Configuration (`.vscode/mcp.json`)

```json
{
  "servers": {
    "supercollider": {
      "command": "npx",
      "args": ["-y", "supercollider-headless-mcp"],
      "env": {}
    }
  }
}
```

### Cursor Configuration (`.cursor/mcp.json`)

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

### Cline Configuration (`.cline/mcp_settings.json`)

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

## πŸ›  Available Tools

### 1. `setup_engine`
Provision SuperCollider runtime, boot `scsynth`, load SynthDef library.

```typescript
await mcp.callTool("setup_engine", {
  forceReprovision: false,  // Force re-download
  sampleRate: 48000,        // Sample rate
  blockSize: 64,            // Block size
  device: "default"         // Audio device (optional)
});
```

**Returns:** Runtime paths, version, sample rate, audio device, block size, loaded SynthDefs.

---

### 2. `play_code`
Evaluate arbitrary `sclang` code β€” SynthDefs, Pdefs, Tdefs, Ndefs, patterns, buffers, microtonal scales.

```typescript
await mcp.callTool("play_code", {
  code: `
    s.sync;
    Pdef(\\ambient, Pbind(
      \\instrument, \\warmStrings,
      \\degree, Pseq([0, 2, 4, 5, 7, 9, 11, 12], inf),
      \\dur, 0.5,
      \\amp, 0.3
    )).play;
  `,
  timeout: 60000
});
```

**Returns:** Console output, errors, return value. Automatically wraps code with `s.sync` before/after for safe SynthDef compilation.

---

### 3. `stop_all`
Immediately silence all sound (`CmdPeriod.run`) while keeping `scsynth` booted.

```typescript
await mcp.callTool("stop_all", {});
```

---

### 4. `list_and_set_audio_device`
List available output devices (`ServerOptions.outDevices`). Optionally switch device and reboot `scsynth`.

```typescript
// List devices
await mcp.callTool("list_and_set_audio_device", {});

// Switch device
await mcp.callTool("list_and_set_audio_device", { setDevice: "Headphones" });
```

---

### 5. `export_wav`
Render a self-contained pattern/score to a 24-bit `.wav` file using Non-Real-Time mode (`Score.recordNRT`).

```typescript
await mcp.callTool("export_wav", {
  code: `
    Pdef(\\render, Pbind(
      \\instrument, \\warmStrings,
      \\degree, Pseq([0, 2, 4, 5, 7, 9, 11, 12], 2),
      \\dur, 0.5,
      \\amp, 0.4
    )).play;
  `,
  outputPath: "./output/ambient-track.wav",
  duration: 30,
  sampleRate: 48000
});
```

---

### 6. `get_status`
Get server boot state, CPU load, active synths, loaded SynthDefs, audio device info.

```typescript
await mcp.callTool("get_status", {});
```

---

## 🎡 Built-in SynthDef Library

| SynthDef | Description | Key Parameters |
|----------|-------------|----------------|
| `\warmStrings` | Rich analog-style pads | freq, amp, gate, attack, decay, sustain, release, cutoff, res, pan |
| `\soloFlute` | Expressive flute with vibrato/breath | freq, amp, gate, vibratoRate, vibratoDepth, breathiness, pan |
| `\subBass` | Deep sub-bass with drive | freq, amp, gate, attack, decay, sustain, release, drive, pan |
| `\pluckSynth` | Karplus-Strong plucked strings | freq, amp, gate, attack, decay, coef, pan |
| `\kick` | Punchy kick drum | freq, amp, gate, attack, decay, pitchDecay, drive, pan |
| `\snare` | Snare with tone/noise mix | freq, amp, gate, attack, decay, tone, noiseMix, pan |
| `\hihat` | Closed/open hi-hat | freq, amp, gate, attack, decay, open, pan |
| `\mcpLimiter` | Master safety limiter (always active) | threshold, dur |

---

## 🧠 Reusable Prompts

### `compose_track`
Generate complete multi-track compositions.

```typescript
await mcp.getPrompt("compose_track", {
  style: "ambient",           // ambient, techno, experimental, etc.
  duration: "120",            // seconds
  bpm: "90",                  // tempo
  key: "C major",             // musical key
  instruments: "warmStrings, soloFlute, subBass, pluckSynth"
});
```

### `design_synth`
Design custom SynthDefs with best practices.

```typescript
await mcp.getPrompt("design_synth", {
  type: "pad",                // pad, lead, bass, drum, texture, etc.
  features: "subtractive, filter modulation",
  controls: "freq, amp, gate, cutoff, res, attack, decay, sustain, release",
  polyphony: "8"
});
```

---

## πŸ’‘ Example Prompts for LLMs

### Simple Ambient Pad
> "Create a slow-evolving ambient pad using the warmStrings synth, with notes from a C major scale, 8-second attack/release, and subtle filter modulation."

### Generative Drum Pattern
> "Make a generative drum pattern using kick, snare, and hihat with Pbrown for kick placement, Pseq for snare on 2 and 4, and Pwhite for hi-hat density. 120 BPM."

### Microtonal Composition
> "Compose a piece using 19-EDO tuning (19 equal divisions of the octave) with the soloFlute synth. Use Scale.new to define the tuning."

### NRT Render to WAV
> "Render a 60-second ambient track to output.wav at 48kHz/24-bit using Score.recordNRT. Use Pdef patterns with warmStrings and subBass."

### Custom SynthDef Design
> "Design a FM synthesis bass SynthDef with 2 operators, configurable ratio, index, and ADSR envelope. Include example Pbind usage."

---

## πŸ”§ Advanced Usage

### Environment Variables

| Variable | Description |
|----------|-------------|
| `SUPERCOLLIDER_PATH` | Override auto-detected sclang path |

### Runtime Location

Managed runtime: `~/.supercollider-mcp/runtime/supercollider-{platform}-{arch}/`

### Manual Provisioning

```bash
# Force re-download latest SuperCollider
npx -y supercollider-headless-mcp --force-reprovision
```

---

## πŸ— Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MCP Client (LLM)                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ JSON-RPC over stdio
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              supercollider-headless-mcp Server              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Provisioner β”‚  β”‚ SC Session   β”‚  β”‚ MCP Tools/Prompts  β”‚  β”‚
β”‚  β”‚ (download,  │──│ (sclang +    │──│ (setup, play,      β”‚  β”‚
β”‚  β”‚  extract,   β”‚  β”‚  scsynth,    β”‚  β”‚  stop, device,     β”‚  β”‚
β”‚  β”‚  prune)     β”‚  β”‚  SynthDefs)  β”‚  β”‚  export, status)   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ spawn
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SuperCollider Runtime                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  sclang  │──│ scsynth  β”‚  β”‚ SCClassLibrary + plugins β”‚  β”‚
β”‚  β”‚ (lang)   β”‚  β”‚ (audio)  β”‚  β”‚ (pruned, headless)       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ“‹ Requirements

- **Node.js** β‰₯ 18
- **No SuperCollider installation needed** (auto-provisioned)

---

## πŸ› Troubleshooting

### "sclang not found" / Provisioning fails
```bash
# Set custom path if auto-detection fails
export SUPERCOLLIDER_PATH="/path/to/sclang"
npx -y supercollider-headless-mcp
```

### Audio device issues
```typescript
// List devices first
await mcp.callTool("list_and_set_audio_device", {});

// Then set specific device
await mcp.callTool("list_and_set_audio_device", { setDevice: "Your Device Name" });
```

### Permission errors (Windows)
Run terminal as Administrator for first run, or ensure `~/.supercollider-mcp` is writable.

### macOS Gatekeeper
If extraction fails: `xattr -d com.apple.quarantine ~/.supercollider-mcp/runtime/...`

---

## πŸ“„ License

MIT License β€” see [LICENSE](LICENSE) for details.

---

## πŸ™ Acknowledgments

- [SuperCollider](https://supercollider.github.io/) β€” The amazing audio synthesis engine
- [Model Context Protocol](https://modelcontextprotocol.io/) β€” For the open protocol
- [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) β€” TypeScript SDK

---

## πŸ”— Links

- **npm**: https://www.npmjs.com/package/supercollider-headless-mcp
- **GitHub**: https://github.com/dheerajstvpm/supercollider-headless-mcp
- **Issues**: https://github.com/dheerajstvpm/supercollider-headless-mcp/issues

TDQS

A3.8/5.0

Scored across 6 tools

Disambiguation4/5

Each tool has a distinct primary purpose: setup, code evaluation, global stop, device management, NRT export, and status reporting. Minor overlap existsβ€”setup_engine loads SynthDefs which play_code can also do, and get_status reports audio device info that list_and_set_audio_device also exposesβ€”but descriptions clarify the boundaries.

Naming Consistency4/5

All tools use snake_case with a verb-first pattern (setup_engine, play_code, stop_all, export_wav, get_status), which is predictable. list_and_set_audio_device is a longer compound verb but still follows the convention; stop_all lacks an explicit object but remains readable.

Tool Count5/5

Six tools cover the core lifecycle of a headless SuperCollider runtime without redundancy. The set is tightly scoped and each tool earns its place.

Completeness4/5

The surface covers setup, arbitrary code execution, global silence, device switching, WAV export, and statusβ€”sufficient for most workflows. Minor gaps remain, such as no explicit engine shutdown/quit or per-node stop, though play_code can work around these via sclang.