Logo vun iTunes/Apple Music CLI & MCP Server

iTunes/Apple Music CLI & MCP Server

Communautéit
chew-z

This is MCP server for playing from Apple Music Library

Editeurchew-z
Repositoryitunes.vim
SproochGo
Forks
0
Stären
10
Disponibel Tools
0
Transporttypstdio
Kategorien
Linken
  • Tools mat KI-Workflows verbannen

    iTunes/Apple Music CLI & MCP Server stellt MCP-Funktioune bereit, déi vu kompatibele KI-Clienten a KI-Agente kënne benotzt ginn.

  • 0 disponibel Tools

    Kuckt Iech déi opruffbar Aktiounen hei drënner un, mat Nimm a Beschreiwungen, wa se vum Server geliwwert ginn.

  • Konfiguratioun fir ze kopéieren

    Benotzt d'Installatiounsbeispiller, fir dëse Server an Ärem bevorzugte MCP-Client ze konfiguréieren.

  • Indicateure fir Open Source

    10 Stären an 0 Forks aus dem verlinkte Repository.

iTunes/Apple Music CLI & MCP Server

High-performance command-line tool and MCP server for iTunes/Apple Music integration on macOS

Go Version Platform SQLite MCP

Overview

A Go-based tool that bridges command-line interfaces and AI applications with your Apple Music library. Features ultra-fast search (<7ms via SQLite FTS5), smart playback control, and integration with Large Language Models through the Model Context Protocol (MCP).

Key Features

  • Ultra-Fast Search: SQLite FTS5 database with <7ms query performance
  • Smart Playback: ID-based track lookup with playlist context support
  • Audio Control: EQ presets and output device management (local/AirPlay)
  • MCP Integration: 14 specialized tools for AI/LLM applications
  • Database-First: Normalized SQLite schema keyed by persistent Apple Music IDs
  • Context-Aware: context.Context flows from MCP requests down to SQLite queries and JXA processes, so cancellation propagates end to end
  • Radio Stations: Apple Music stations with database-backed CRUD and search
  • Vim Plugin: fzf-powered library search and playback from inside Vim/Neovim (vim-plugin/)

Project History

This project evolved from a legacy VIM plugin for iTunes integration. The original plugin remains untouched in the master branch as a reference. The current implementation is a complete rewrite focused on modern Apple Music integration, database performance, and AI/LLM compatibility through the MCP protocol — and includes a rewritten Vim plugin (vim-plugin/) that fronts the Go CLI instead of JXA scripts.

Architecture

+-------------------+    +--------------------+    +-------------------+
|   CLI Tool        |    |   MCP Server       |    |  Apple Music      |
|   (itunes)        |    |  (mcp-itunes)      |    |  Desktop App      |
+---------+---------+    +---------+----------+    +---------+---------+
          |                        |                         |
          +----------+-------------+                         |
                     |                                       |
          +----------v------------+              +----------v--------+
          |   itunes.Client       |              |   JXA Scripts     |
          |   (core library)      |<-------------+   (via osascript  |
          +----------+------------+              |    stdin)         |
                     |                           +-------------------+
          +----------v------------+
          |   SQLite Database     |
          |   FTS5 Search         |
          +-----------------------+
  • Search path: queries hit the local SQLite database directly — the Apple Music app is not involved.
  • Playback path: Go pipes embedded JXA scripts to osascript via stdin (no temp files) to drive the Apple Music app.
  • Library refresh: Apple Music → JXA bulk property fetch → SQLite (~15–30 seconds even for 10k+ track libraries).

Installation

Prerequisites

  • macOS (required for Apple Music integration)
  • Go 1.25+
  • Apple Music app (installed and configured)
  • Terminal access with Automation permissions for AppleScript/JXA

Build from Source

bash
git clone <repository-url>
cd itunes

go build -o bin/itunes .                 # CLI tool
go build -o bin/mcp-itunes ./mcp-server  # MCP server
go build -o bin/itunes-migrate ./cmd/migrate  # Migration tool

Quick Start

Database Setup (first)

bash
# First-time setup or library refresh (~15-30 seconds)
./bin/itunes-migrate -from-script

# Validate existing database
./bin/itunes-migrate -validate

When to refresh: first install, library changes, metadata updates, or search issues.

CLI Usage

bash
# Search your music library
./bin/itunes search "jazz"
./bin/itunes search "Miles Davis"
./bin/itunes search --json "Miles Davis"   # JSON output (used by the Vim plugin)

# Play tracks: play <playlist> [album] [track] [trackID]
./bin/itunes play "My Playlist" "" "" "B258396D58E2ECC9"   # ID with playlist context
./bin/itunes play "" "Kind of Blue" "So What"              # album + track name

# Current playback status
./bin/itunes now-playing   # or: status

# Radio stations
./bin/itunes search-stations "jazz"
./bin/itunes list-stations
./bin/itunes add-station --name "Name" --url "itmss://..." [--genre g --description d --homepage url]
./bin/itunes update-station <id> [--name/--url/--genre/--description/--homepage ...]
./bin/itunes delete-station <id>
./bin/itunes import-stations stations.json
./bin/itunes export-stations stations.json

MCP Server

bash
# Start MCP server (stdio transport)
./bin/mcp-itunes

Claude Desktop / Claude Code configuration:

json
{
  "mcpServers": {
    "itunes": {
      "command": "/path/to/bin/mcp-itunes"
    }
  }
}

Vim Plugin

Search and play from inside Vim/Neovim via fzf:

vim
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'chew-z/itunes.vim', { 'branch': 'main', 'rtp': 'vim-plugin' }
CommandDescription
:Tunes [query]Fuzzy-search the library and play the selected track
:TunesStatusShow the currently playing track
:TunesPlay [playlist]Play an entire playlist

The plugin shells out to bin/itunes (auto-detected, or set g:itunes_bin). See vim-plugin/README.md for configuration and docs/VIM-PLUGIN.md for design details.

MCP Tools (14)

Music Library:

  • search_itunes — search library (<7ms FTS5 performance)
  • search_advanced — filtered search (genre, artist, album, rating, starred, streaming)
  • play_track — play with ID-based lookup and optional playlist context
  • now_playing — current playback status and track info
  • refresh_library — rebuild database from Apple Music (~15–30 s, resource-intensive)

Playlists:

  • list_playlists — all playlists with metadata
  • get_playlist_tracks — tracks in a specific playlist

Radio & Streams:

  • search_stations — find Apple Music radio stations by genre/name
  • play_stream — play streaming URLs (itmss://, https://)

EQ & Audio Output:

  • check_eq — current EQ status and available presets
  • set_eq — apply EQ presets (Rock, Jazz, Classical, …) or enable/disable
  • get_output_device — current audio output (local/AirPlay)
  • list_output_devices — available output devices
  • set_output_device — switch to local output (AirPlay selection must be manual)

MCP Resources: itunes://database/stats, itunes://database/playlists

Usage Pattern

Best practice is ID-based playback with playlist context for continuous play:

json
{"track_id": "B258396D58E2ECC9", "playlist": "My Jazz Collection"}

Track IDs come from search results and are Apple Music persistent IDs, which avoids name-matching and encoding issues.

Performance

  • Search: <7ms queries, <5µs cache hits
  • Database: ~760 bytes per track, ~800 tracks/sec migration
  • Storage: ~1MB per 1,000 tracks including FTS5 indexes
  • Driver: pure Go SQLite (modernc.org/sqlite, no CGO)

Environment Variables

VariableDefaultDescription
ITUNES_DB_PATH~/Music/iTunes/itunes_library.dbPrimary database path
ITUNES_BACKUP_DB_PATH~/Music/iTunes/itunes_library_backup.dbBackup database path
ITUNES_SEARCH_LIMIT15Maximum search results

Documentation

Developer docs live in docs/: architecture, database & FTS5 internals, JXA automation (including the bulk-fetch rule — required reading before touching any JXA script), and the Vim plugin.

Development

Project Structure

├── itunes.go              # CLI application (command dispatch + handlers)
├── mcp-server/            # MCP server (14 tools, grouped registration)
├── itunes/                # Core library: Client type, playback, EQ, JXA scripts
│   └── scripts/           # Embedded JXA automation scripts
├── database/              # SQLite + FTS5: schema, search, migrations
├── vim-plugin/            # Vim/Neovim frontend (fzf + CLI)
├── docs/                  # Developer documentation
├── logging/               # zap logger setup
└── cmd/migrate/           # Database migration/validation tool

The core library exposes itunes.NewClient(logger) owning the database connection and search manager; playback and audio-control functions are package-level and take a context.Context.

Build, Test, Lint

bash
./run_test.sh        # go test -v ./...
./run_lint.sh        # golangci-lint (zero findings expected)
./run_format.sh      # gofmt -w .

# Or directly:
go test ./...
go test ./database -bench=BenchmarkSearch

Troubleshooting

Database issues:

bash
./bin/itunes-migrate -from-script    # Initialize/refresh
./bin/itunes-migrate -validate       # Check status

Playback issues:

  • Use track_id from search results (most reliable)
  • Ensure the Apple Music app is running
  • Grant Automation permissions: System Settings → Privacy & Security → Automation

EQ/Audio issues:

  • EQ status is unavailable while using AirPlay (macOS limitation)
  • Specific AirPlay device selection must be done manually in the Music app

Radio station playback:

  • Stations must use itmss:// protocol URLs for playback; https:// URLs are homepage links only

License & Acknowledgments

MIT License — see LICENSE file for details.

Thanks to Apple Music, SQLite FTS5, the MCP Protocol, and modernc.org/sqlite.

Installatioun

TypingMind
{
  "mcpServers": {
    "itunes-vim": {
      "command": "./bin/mcp-itunes",
      "args": []
    }
  }
}

iTunes/Apple Music CLI & MCP Server MCP mat verschiddene KI-Modeller benotzen

TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Soubal iTunes/Apple Music CLI & MCP Server verbonnen ass, kënnt Dir et mat verschiddene KI-Modeller an TypingMind benotzen, amplaz et fir all Modell separat anzeriichten. Dës MCP-Integratioun leeft lokal iwwer den TypingMind-MCP-Connector op Ärem Apparat.

Ariichtungsuleedung fir de lokale Connector ze benotzen

Benotzt dës Optioun, wann den MCP-Server Zougrëff op lokal Fichieren, Appen oder privat Ressourcen op Ärem Computer brauch.

1

D'MCP-Astellungen opmaachen

Gitt an TypingMind op „Astellungen“, „Erweidert Astellungen“, dann op „Model Context Protocol“ a wielt „Connector ariichten“.

  1. Maacht TypingMind an Ärem Browser op.
  2. Klickt op d'Astellungssymbol.
  3. Gitt op „Erweidert Astellungen“.
  4. Maacht d'Sektioun „Model Context Protocol“ op.
  5. Klickt op „Connector ariichten“ a wielt „Dësen Apparat“.
Ariichtungsbildschierm vum TypingMind-MCP-Connector mat „Dësen Apparat“ ausgewielt
2

De Connector-Befeel ausféieren

Wielt „Dësen Apparat“, kopéiert de Befeel aus TypingMind a féiert en am Terminal aus. Loosst de Prozess lafen, wärend Dir MCP benotzt.

  1. Kopéiert den Ariichtungsbefeel, deen TypingMind uweist.
  2. Maacht Terminal op macOS oder Windows Terminal op Windows op.
  3. Pescht de Befeel an a féiert en aus.
  4. Bestätegt d'Installatioun vum Package, wann den Terminal Iech freet, ob Dir weiderfuere wëllt.
  5. Loosst den Terminal an de Prozess doranner lafen, wärend Dir MCP-Tools benotzt.
3

iTunes/Apple Music CLI & MCP Server als Server derbäisetzen

Wann de Connector-Status „Prett“ ass, klickt op „Serveren änneren“ a pescht d'MCP-Serverkonfiguratioun an.

  1. Waart, bis de Connector-Status „Prett“ weist.
  2. Klickt op „Serveren änneren“.
  3. Pescht d'MCP-Serverkonfiguratioun vu iTunes/Apple Music CLI & MCP Server an.
  4. Späichert d'Serverlëscht.
  5. Aktualiséiert, wann Dir kontrolléiere wëllt, ob de Connector nach ëmmer prett ass.
MCP-Astellunge vun TypingMind mat aktivem Server an dem Knäppchen „Serveren änneren“
{
  "mcpServers": {
    "itunes-vim": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

D'Verbindung mat verschiddene Modeller benotzen

Späichert d'Serverlëscht, maacht „Plugins“ op an aktivéiert d'MCP-Tools vu iTunes/Apple Music CLI & MCP Server. Wielt dann e belibegen ënnerstëtzte KI-Modell an TypingMind a benotzt d'Tools am Chat oder weist se engem KI-Agent zou.

  1. Maacht d'Säit „Plugins“ an TypingMind op.
  2. Aktivéiert d'MCP-Tools vu iTunes/Apple Music CLI & MCP Server.
  3. Start e Chat a wielt de KI-Modell, deen Dir benotze wëllt.
  4. Benotzt d'MCP-Tools am Chat oder weist se engem KI-Agent zou.
  5. Wiesselt bei Bedarf op en anere KI-Modell, ouni MCP nei ze verbannen.
TypingMind-Chat mat aktivéierte MCP-Tools an engem ausgewielte KI-Modell
Hëlleft Dir mir bei dëser Aufgab mat iTunes/Apple Music CLI & MCP Server?
iTunes/Apple Music CLI & MCP Server
Jo. Ech hunn et gelies.
Dat hunn ech mat iTunes/Apple Music CLI & MCP Server fonnt.

Heefeg gestallte Froen

Fir wat gëtt de MCP-Server iTunes/Apple Music CLI & MCP Server benotzt?

iTunes/Apple Music CLI & MCP Server ass e MCP-Server, deen et kompatibele KI-Clienten erlaabt, sech mat externen Tools a Kontext ze verbannen. An TypingMind kënnt Dir dëse MCP-Server eemol derbäisetzen a seng Tools an Ärem KI-Aarbechtsberäich zur Verfügung stellen.

Kann ech iTunes/Apple Music CLI & MCP Server MCP mat méi KI-Modeller an TypingMind benotzen?

Jo. TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Sou kënnt Dir iTunes/Apple Music CLI & MCP Server mat verschiddene KI-Modeller wéi Claude, ChatGPT, Gemini oder anere Modeller benotzen, déi Dir an TypingMind konfiguréiert hutt, ouni de MCP-Server fir all Modell separat anzeriichten.

Firwat iTunes/Apple Music CLI & MCP Server MCP mat TypingMind benotzen?

TypingMind ass eng vun de beschte Benotzeruewerfläche fir LLM-Chat, well et méi KI-Modeller, Prompts, Plugins, KI-Agenten, API-Schlësselen a MCP-Tools an engem Aarbechtsberäich zesummebréngt. Wann iTunes/Apple Music CLI & MCP Server verbonnen ass, kënnt Dir seng MCP-Tools mat Äre bevorzugte Modeller benotzen a gläichzäiteg Är Chataarbecht an TypingMind organiséieren.

Wéi verbannen ech iTunes/Apple Music CLI & MCP Server MCP mat TypingMind?

iTunes/Apple Music CLI & MCP Server leeft iwwer de lokale MCP-Connector vun TypingMind. Dat eegent sech am beschten, wann de MCP-Server Zougrëff op lokal Fichieren, Desktop-Apps, Kommandozeilen-Tools oder privat Ressourcen op Ärem Computer brauch.

Wéi eng Tools stellt iTunes/Apple Music CLI & MCP Server MCP an TypingMind zur Verfügung?

iTunes/Apple Music CLI & MCP Server stellt MCP-Funktiounen zur Verfügung, déi Dir op der Plugins-Säit vun TypingMind aktivéiere kënnt, fir se am Chat ze benotzen oder KI-Agenten zouzeweisen.

Muss ech meng API-Schlëssele mat TypingMind deelen, fir iTunes/Apple Music CLI & MCP Server MCP ze benotzen?

Nee. TypingMind setzt op lokal Veraarbechtung a léisst Iech d'Kontroll iwwer Är Modellubidder, API-Schlësselen, Prompts a MCP-Konfiguratioun. Wann iTunes/Apple Music CLI & MCP Server eng Authentifizéierung verlaangt, setzt déi néideg Headeren, OAuth-Astellungen oder lokal Konfiguratioun fir dee MCP-Server derbäi, wann Dir d'Verbindung erstallt.

Änlech MCP-Serveren

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇