Metadata-Version: 2.5
Name: hydrogen-mcp-server
Version: 0.3.2
Summary: Local MCP server for the Hydrogen drum machine: live OSC control, song and drumkit editing, MIDI import and export, and audio rendering
Project-URL: Repository, https://github.com/RandyNorthrup/hydrogen-mcp-server
Project-URL: Issues, https://github.com/RandyNorthrup/hydrogen-mcp-server/issues
Project-URL: Changelog, https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/CHANGELOG.md
Project-URL: Releases, https://github.com/RandyNorthrup/hydrogen-mcp-server/releases
Author: Randy Northrup
License-Expression: MIT
License-File: LICENSE
Keywords: drum-machine,fastmcp,hydrogen,mcp,midi,model-context-protocol,osc
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
Requires-Python: <3.15,>=3.13
Requires-Dist: defusedxml==0.7.1
Requires-Dist: fastmcp==4.2.6
Requires-Dist: pillow==13.0.0; sys_platform == 'win32'
Requires-Dist: pydantic==2.14.4
Requires-Dist: pywin32==312; sys_platform == 'win32'
Description-Content-Type: text/markdown

# Hydrogen MCP Server

![Hydrogen MCP Server banner with a charcoal drum sequencer and illuminated mint and amber pads](https://raw.githubusercontent.com/RandyNorthrup/hydrogen-mcp-server/main/docs/assets/hydrogen-banner.jpg)

**Sequence, mix, and render Hydrogen projects from your local MCP client.**

[![Checks](https://github.com/RandyNorthrup/hydrogen-mcp-server/actions/workflows/quality.yml/badge.svg?branch=main)](https://github.com/RandyNorthrup/hydrogen-mcp-server/actions/workflows/quality.yml)
[![PyPI version](https://img.shields.io/pypi/v/hydrogen-mcp-server?style=flat-square&label=PyPI&color=126958)](https://pypi.org/project/hydrogen-mcp-server/)
[![Downloads](https://img.shields.io/pypi/dm/hydrogen-mcp-server?style=flat-square&label=Downloads&color=34485A)](https://pypistats.org/packages/hydrogen-mcp-server)
[![GitHub stars](https://img.shields.io/github/stars/RandyNorthrup/hydrogen-mcp-server?style=flat-square&label=Stars&color=B8860B)](https://github.com/RandyNorthrup/hydrogen-mcp-server/stargazers)
[![Python 3.13–3.14](https://img.shields.io/badge/Python-3.13%E2%80%933.14-3670A0?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
[![FastMCP 4.2.6](https://img.shields.io/badge/FastMCP-4.2.6-126958?style=flat-square)](https://gofastmcp.com/)
[![Hydrogen 1.2.7](https://img.shields.io/badge/Hydrogen-1.2.7-34485A?style=flat-square)](#platform-support)
[![MIT license](https://img.shields.io/badge/License-MIT-316A50?style=flat-square)](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/LICENSE)

[Quick start](#quick-start) · [Add it to your agent](#add-it-to-your-agent) · [Tool overview](#tool-overview) · [First groove](#make-a-two-bar-groove) · [Configuration](#configuration)

This independent integration exposes **31 MCP tools** and maps **67 OSC action names** from Hydrogen 1.2.7. It supports live transport and mixer control, native project editing with any installed drumkit, drumkit creation, MIDI import and export, audio rendering and inspection, and Windows desktop controls for Hydrogen menus and dialogs.

## Quick start

1. Install [uv](https://docs.astral.sh/uv/) and [Hydrogen](https://hydrogen-music.org/downloads/). The Windows Hydrogen installer includes `hydrogen.exe` and `h2cli.exe`. uv downloads Python 3.13 by itself when your system has none.
2. Check that the server finds Hydrogen. The command prints the detected paths and exits with status 1 when the app or `h2cli` is missing.

   ```sh
   uvx hydrogen-mcp-server --check
   ```

3. [Add the server to your agent](#add-it-to-your-agent), then ask it for a beat: *"Make a two-bar rock groove with the GM kit and render it to WAV."*

The server runs on your machine over stdio. It needs no account, API key, or network service. It is tested against Hydrogen 1.2.7 on Windows, Linux, and macOS. See [platform support](#platform-support) for what each platform offers.

## Add it to your agent

Every MCP client starts the same command. `uvx` fetches the package from PyPI once and caches it.

```sh
uvx hydrogen-mcp-server
```

| Agent | Setup |
| --- | --- |
| Claude Code | `claude mcp add --scope user hydrogen -- uvx hydrogen-mcp-server` |
| Codex CLI | `codex mcp add hydrogen -- uvx hydrogen-mcp-server` |
| Gemini CLI | `gemini mcp add --scope user hydrogen uvx hydrogen-mcp-server` |
| Grok CLI | `grok mcp add hydrogen uvx hydrogen-mcp-server` |
| VS Code and GitHub Copilot | Add the `servers` entry below to `.vscode/mcp.json` |
| Claude Desktop, Cursor, and other clients | Add the `mcpServers` entry below to the client's MCP settings file |

Clients with an `mcpServers` block share one format. Claude Desktop opens its file from **Settings → Developer → Edit Config**. Cursor reads `~/.cursor/mcp.json` or `.cursor/mcp.json` in a project, and Gemini CLI reads `~/.gemini/settings.json`.

```json
{
  "mcpServers": {
    "hydrogen": {
      "command": "uvx",
      "args": ["hydrogen-mcp-server"]
    }
  }
}
```

VS Code names the block `servers` and states the transport.

```json
{
  "servers": {
    "hydrogen": {
      "type": "stdio",
      "command": "uvx",
      "args": ["hydrogen-mcp-server"]
    }
  }
}
```

An installed package keeps your songs and renders in `~/Hydrogen Projects`. Add an `env` block to change that folder or any other [setting](#configuration). `uvx` keeps the version it fetched first: run `uvx hydrogen-mcp-server@latest` once to upgrade, or pin a version with `uvx hydrogen-mcp-server@0.3.2`. Each [GitHub release](https://github.com/RandyNorthrup/hydrogen-mcp-server/releases) carries the same wheel with its checksums. To follow unreleased work, use `uvx --from git+https://github.com/RandyNorthrup/hydrogen-mcp-server hydrogen-mcp`.

### Run from a checkout

```sh
git clone https://github.com/RandyNorthrup/hydrogen-mcp-server.git
cd hydrogen-mcp-server
uv sync --locked --no-dev
```

Register the absolute path of `.venv/Scripts/hydrogen-mcp.exe` on Windows, or `.venv/bin/hydrogen-mcp` on Linux and macOS, as the command with no arguments. A checkout keeps projects in its own `projects` folder.

### Connect to Hydrogen for live control

Ask your agent to open Hydrogen, or call `hydrogen_launch`. It starts the app with OSC enabled, waits until Hydrogen answers and its interface has loaded, and reports `osc_ready` and `interface_ready`. When your saved preferences have OSC off or use another port, the launch uses a copy of them with OSC on. The copy lives in your projects folder, and your own preferences file stays unchanged. The launch declines to start a second Hydrogen while one already answers on the OSC port.

To control a Hydrogen that you start yourself:

1. Open **Preferences → OSC** in Hydrogen.
2. Enable **OSC support** and **OSC feedback**. Use port `9000` or set `HYDROGEN_OSC_PORT` to match your app.
3. Restart Hydrogen. It opens its OSC listener at startup.

`hydrogen_status` shows a timestamp in `osc.last_feedback_received_at` once Hydrogen answers. Until then, `osc.hint` names the setting to change, and `osc_supported` tells you whether this Hydrogen build has OSC at all. Offline project editing and `h2cli` audio export work with the desktop app closed. Keep trusted source files in the configured project or library roots.

## Tool overview

| Workflow | Tools |
| --- | --- |
| Discover files, live controls, and feedback | `hydrogen_list`, `hydrogen_status`, `hydrogen_controls` |
| Control transport, recording, BPM, mixer, timeline, MIDI triggers, and JACK | `hydrogen_live` |
| Launch Hydrogen and work with the active song | `hydrogen_launch`, `hydrogen_open_song`, `hydrogen_new_song`, `hydrogen_save_as` |
| Compose and inspect songs, patterns, instruments, and layered samples | `hydrogen_read_song`, `hydrogen_edit_song`, `hydrogen_read_instrument`, `hydrogen_read_pattern`, `hydrogen_write_pattern`, `hydrogen_add_live_pattern`, `hydrogen_open_pattern` |
| Read and create playlists | `hydrogen_read_playlist`, `hydrogen_write_playlist` |
| Create, load, inspect, validate, import, upgrade, and export drumkits | `hydrogen_create_drumkit`, `hydrogen_load_drumkit`, `hydrogen_read_drumkit`, `hydrogen_validate_drumkit`, `hydrogen_import_drumkit`, `hydrogen_export_drumkit` |
| Render a mix, export isolated stereo stems, and check the result | `hydrogen_render`, `hydrogen_render_stems`, `hydrogen_read_audio` |
| Convert between songs and Standard MIDI Files | `hydrogen_import_midi`, `hydrogen_export_midi` |
| View and interact with a Hydrogen window on Windows | `hydrogen_desktop_windows`, `hydrogen_desktop_image`, `hydrogen_desktop_input` |

The `hydrogen://reference/osc` resource lists the action signatures. For live controls, `sent_unconfirmed` means the UDP datagram was sent. Mixer feedback comes back through `hydrogen_status`. `hydrogen_save_as` verifies the saved song file and changes the active save path. Save current edits before opening or creating another live song. To change the notes or instruments of the open song, call `hydrogen_save_as`, edit that file with `hydrogen_edit_song`, and open the result with `hydrogen_open_song`.

For Windows desktop control, list the windows, capture a selected window, then send client-relative pointer coordinates or keyboard input to that window. The feature requires an interactive Windows session. Plugins and JACK operations depend on support in the installed Hydrogen build.

## Make a two-bar groove

Ask your MCP client to create two bars with the factory GM kit and export a stereo WAV. To call the tools directly, send this payload to `hydrogen_edit_song`. With no `source`, the song starts blank and takes its instruments from the drumkit.

```json
{
  "output": "Grooves/first-beat.h2song",
  "edit": {
    "name": "First beat",
    "bpm": 110,
    "drumkit": { "scope": "factory", "path": "drumkits/GMRockKit/drumkit.xml" },
    "patterns": [
      {
        "name": "Beat",
        "notes": [
          { "instrument": 0, "position": 0 },
          { "instrument": 0, "position": 48 },
          { "instrument": 0, "position": 96 },
          { "instrument": 0, "position": 144 }
        ]
      }
    ],
    "arrangement": [["Beat"], ["Beat"]]
  }
}
```

Then send this payload to `hydrogen_render`.

```json
{
  "source": { "path": "Grooves/first-beat.h2song" },
  "output": "Grooves/first-beat.wav"
}
```

Send `{ "source": { "path": "Grooves/first-beat.wav" } }` to `hydrogen_read_audio` to confirm the length and peak level. Both files appear in the `Grooves` folder of your projects folder. File references use paths relative to `projects`, `user`, or `factory`. Discover those paths with `hydrogen_list`. Every edit writes a new file and leaves existing files untouched, so choose a new output path for each version. Drumkit imports can also create a folder in the user library.

### Editing and rendering details

- **Templates and drumkits.** Pass a `source` song to edit a copy of it, or omit it to start blank. Set `drumkit` to a `drumkit.xml` manifest from `hydrogen_list` to replace the instruments. Notes for instrument IDs missing from the new kit are removed.
- **Notes and timing.** Use instrument IDs from `hydrogen_read_song` for offline edits. Hydrogen uses 48 ticks per quarter note and 192 ticks for a 4/4 bar. In a pattern edit, `notes` replaces every note and `add_notes` keeps the existing ones. `remove_patterns` deletes patterns from the song, its arrangement, and its virtual links. Live OSC indexes are zero-based except for one-based mixer `strip` positions.
- **Audio.** Hydrogen renders WAV, AIFF, FLAC, Ogg Vorbis, Opus, AU, CAF, Wave64, VOC, and MP3. MP3 and Opus need a Hydrogen build whose audio library includes those codecs, as the Windows build does. Use 48 kHz for Opus and 8-bit PCM for VOC. Stems are separate stereo WAVs rendered by Hydrogen.
- **Audio checks.** `hydrogen_read_audio` reports channels, sample rate, frames, and duration for every format Hydrogen renders. PCM and float files in WAV, Wave64, AIFF, AU, and CAF also report peak level and a `silent` flag. A silent render usually means Hydrogen could not find the samples. Use the frame count of a sample when you trim or loop it.
- **MIDI export.** `hydrogen_export_midi` writes what the MIDI export of Hydrogen writes: the arrangement on the grid, each note on the MIDI output note and channel of its instrument, and channel 10 for instruments without a channel. A note that plays its whole sample lasts 12 ticks. The file also carries tempo markers, time signatures taken from the pattern sizes, timeline tags as markers, and velocity automation. Swing, humanize, and lead or lag belong to playback and stay out of the file. `skipped_notes` counts notes that make no sound (zero velocity, zero probability, or automation at zero), notes outside their pattern or without an instrument, and notes outside the MIDI pitch range. A column whose length is no multiple of three ticks has no MIDI time signature and is counted in `columns_without_time_signature`.
- **MIDI import.** `hydrogen_import_midi` reads format 0 and 1 files and writes one pattern per distinct bar. Instruments come from a template song or a drumkit. A MIDI note plays the instrument with that MIDI output note, and the result lists unmapped note numbers. Set `pitched_instrument` to play all other notes as keys of one instrument, for a bass line or melody. Set `channel` to read one channel, such as 10 for drums. Notes play their whole sample unless `note_lengths` keeps the MIDI durations. Time signatures set the pattern sizes, and tempo changes and markers snap to bar starts. A time signature that no Hydrogen pattern can hold is counted in `ignored_time_signatures`, and the earlier one stays in effect.
- **Sample layers.** `sample_instruments` adds instruments from existing audio files. `sample_layers` edits gain, pitch, velocity range, trim, loop, or sample assignment. Keep custom samples with the project for portable exports.
- **Drumkits.** `hydrogen_create_drumkit` turns the instruments of a song into a drumkit folder with its samples, and returns a reference you can pass to `drumkit`. Import and export Hydrogen’s `.h2drumkit` archives. The import tool’s upgrade mode accepts a manifest or archive and writes the upgraded result to a new directory. `hydrogen_read_instrument` reads the layers of a song instrument or of a kit instrument.

## Configuration

Set these variables in your MCP client's `env` block. From a checkout, you can also copy [`.env.example`](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/.env.example) to `.env` and run `uv run --env-file .env hydrogen-mcp`. Reconnect the client after changing settings. Run `hydrogen-mcp --check` to see the values in effect.

| Environment variable | Windows default | macOS default | Linux default |
| --- | --- | --- | --- |
| `HYDROGEN_INSTALL_DIR` | `C:/Program Files/Hydrogen` | `/Applications/Hydrogen.app` | Unset. Point it at an extracted AppImage or at a prefix such as `/usr/local` |
| `HYDROGEN_APP` | `hydrogen.exe` in the install directory | `Contents/MacOS/hydrogen` in the bundle | `hydrogen` on `PATH`, or `AppRun` in the install directory |
| `HYDROGEN_CLI` | `h2cli.exe` in the install directory | `h2cli` on `PATH` | `h2cli` on `PATH`, or `usr/bin/h2cli` in the install directory |
| `HYDROGEN_SYSTEM_DATA` | `data` in the install directory | `Contents/Resources/data` in the bundle | `/usr/share/hydrogen/data`, or `usr/share/hydrogen/data` in the install directory |
| `HYDROGEN_USER_DATA` | `~/.hydrogen/data` | `~/Library/Application Support/Hydrogen/data` | `~/.hydrogen/data` |
| `HYDROGEN_CONFIG` | `~/.hydrogen/hydrogen.conf` | `~/Library/Application Support/Hydrogen/hydrogen.conf` | `~/.hydrogen/hydrogen.conf` |
| `HYDROGEN_OSC_PORT` | `9000` | `9000` | `9000` |
| `HYDROGEN_PROJECT_DIR` | `~/Hydrogen Projects` for an installed package, or `projects` inside a checkout | Same | Same |

The MCP server sends OSC over loopback. Hydrogen controls its own listener, so check its firewall access before using OSC on an untrusted network. Hydrogen resolves the asset references inside songs and kits used for native rendering.

### Platform support

| Platform | Hydrogen package | What works |
| --- | --- | --- |
| Windows | Official installer | Everything, including desktop controls |
| Linux | Official AppImage, or a distribution package of 1.2.7 | Everything except desktop controls |
| macOS | Official app | Song editing, MIDI conversion, audio checks, and opening songs in the app. The official macOS app is built without OSC and without `h2cli`. Live control, rendering, stems, and drumkit validation, creation, and archives work with a Hydrogen build that includes them |

The official AppImage holds `h2cli` and the factory data inside the image. Extract it once and point the server at the folder:

```sh
./Hydrogen-1.2.7-x86_64.AppImage --appimage-extract
export HYDROGEN_INSTALL_DIR="$PWD/squashfs-root"
```

## Verification

CI runs formatting, lint, types, protocol tests, security and dependency checks, workflow audits, and a wheel build on Windows. CodeQL scans the Python code and the workflows for security and quality problems, and pull requests get a dependency review. It runs the protocol tests on Linux and macOS with Python 3.13 and 3.14. It also installs the official Hydrogen 1.2.7 packages on Linux and macOS and runs the native suite there. That suite verifies live OSC, app launch, song and kit operations, MIDI round trips, rendering in every format, and stem isolation against Hydrogen itself. On Windows it runs locally and also covers desktop capture and input.

```powershell
uv sync --locked
uv run --locked ruff format --check .
uv run --locked ruff check .
uv run --locked mypy
uv run --locked pytest -q
uv run --locked bandit -q -r src
uv run --locked deptry .
uv run --locked vulture src tests --min-confidence 80
uv run --locked pip-audit --local --progress-spinner off
uv build --no-sources
```

Run the native suite on a machine with Hydrogen installed. The launch and desktop tests open disposable Hydrogen windows with their own preferences and data folders.

```powershell
$env:HYDROGEN_NATIVE_TESTS = '1'
uv run --locked pytest -q
```

A release is cut by pushing a `v` tag that matches the package version. The release workflow tests the tag, builds the wheel and source archive, attaches them with checksums to the GitHub release, and publishes the same files to PyPI through trusted publishing.

[Changelog](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/CHANGELOG.md) · [Verification notes](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/PLAN.md) · [Security policy](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/SECURITY.md) · [MIT license](https://github.com/RandyNorthrup/hydrogen-mcp-server/blob/main/LICENSE)
