music-mcp #
MCP server for the ~/Music collection. Fetches missing music from sources
(Deezer first), converts FLAC → OGG Vorbis 192 kbps, embeds cover art, fetches
lyrics, corrects tags, organizes into the collection layout, and controls the
local MPD instance.
Layout #
~/Music/<Album Artist>/<Album>/NN - Title.ogg (+ NN - Title.lrc if lyrics found)
- OGG Vorbis 192 kbps only (no FLAC kept).
- Cover art embedded as
METADATA_BLOCK_PICTUREvorbis comment. - Lowercase vorbis comments: title, artist, album, albumartist, tracknumber, discnumber, date, genre, isrc.
- Lyrics via lrclib.net (keyless),
[re:rmpc-lrclib]header, synced preferred.
Tools #
| Tool | Purpose |
|---|---|
search_music |
Search a source (deezer) for artists/albums/tracks |
artist_discography |
Classified discography + which are already in the collection |
album_status |
Is this album in the collection? tracks/lyrics/art counts |
library_stats |
Collection-wide counts + coverage |
fetch_album |
Full pipeline for one album (no-op if already present) |
fetch_artist |
Studio discography pipeline (opt-in EPs/singles/live) |
enrich_album |
Re-run lyrics + tag fixes on an existing album dir |
deezer_status |
Is the stored ARL valid? user id + premium/lossless flags (read-only) |
deezer_login |
Single clean login attempt to save a fresh ARL (see note below) |
mpd_status |
Now playing, position, volume, playlist length |
mpd_control |
play/pause/resume/toggle/next/prev/stop/seek/volume |
mpd_queue |
list/add/search/clear the playlist |
play_music |
Play by name from the collection (optionally fetch if missing) |
rescan_library |
Rebuild the MPD database |
Pipeline (fetch_album / fetch_artist) #
- Check the collection first (fuzzy artist+album match) → no-op if present.
- Resolve the album: internal Deezer
album.getDiscographywhen a valid ARL is present (reliable studio/EP/single classification), else the public search API. - Download FLAC via the
deemixCLI (reads~/.config/deemix/login.json). - Convert:
ffmpeg -vn -map 0:a -c:a libvorbis -b:a 192k(parallel). - Embed cover art with mutagen (
METADATA_BLOCK_PICTURE), normalize tags. - Fetch lyrics from lrclib.net (idempotent, 429 backoff).
- Organize into
~/Music/<albumartist>/<album>/NN - Title.ogg. mpc updateto rescan MPD.
Deezer ARL #
Deezer downloads need a valid ARL. The server reads it from
~/.config/deemix/login.json. When the ARL is invalid (expired / account
locked), ARL-dependent paths (discography classification, downloads) raise a
clear ARLInvalid error; everything else (library, search, conversion, lyrics,
MPD) keeps working.
Logging in to get a fresh ARL #
deezer_status checks the stored ARL (read-only). deezer_login performs a
single headless login (playwright chromium with stealth: real Chrome UA,
webdriver hidden, realistic viewport/locale/tz) to harvest a fresh ARL and
write it to ~/.config/deemix/login.json, then verifies it against the
gw-light getUserData API.
Credentials come from the email/password args, else DEEZER_EMAIL /
DEEZER_PASSWORD, else ~/.config/music-mcp/deezer.json. The password is
never persisted.
Why single-attempt: repeated automated logins trigger Deezer's
"suspicious activity" risk system, which disables the password and locks the
account. So deezer_login makes exactly ONE attempt and, if it detects a risk
wall (suspicious activity, disabled password, email verify, 2FA), it stops and
returns the wall state + a screenshot path — it never retries. Run it only
after the account is confirmed unblocked; if it reports a wall, clear that
wall (e.g. complete the email verification) and try once more.
Setup #
cd ~/Sources/music-mcp
python3 -m pip install --user --break-system-packages -e .
# register with jcode (already done in ~/.jcode/mcp.json)
Environment overrides: MUSIC_MCP_MUSIC_DIR, MUSIC_MCP_STAGING_DIR,
MUSIC_MCP_DEEMIX_BIN, MUSIC_MCP_DEEZER_LOGIN_JSON, MUSIC_MCP_MPD_HOST,
MUSIC_MCP_MPD_PORT, MUSIC_MCP_LYRCLIB_BASE, MUSIC_MCP_ENCODE_WORKERS.
Run #
python3 -m music_mcp # stdio MCP server
Source extension #
sources/deezer.py is the reference implementation of the Source protocol
(search, discography, download_album). Add a new file under sources/
and register it in sources.get_source() to support another backend.