MCP-AppleMusic: AppleScript-Based Music Control Server

┌─────────────────────────────────────────────────────┐
│ Analysis Summary                                    │
├─────────────────────────────────────────────────────┤
│ Type: Project                                       │
│ Purpose: AppleScript-Based Music Control Server     │
│ Primary Language: python + markdown + toml          │
│ LOC: 272                                            │
│ Test Files: 0                                       │
│ Architecture: python                                │
│ Confidence: High                                    │
└─────────────────────────────────────────────────────┘

Analyzed: 936fb77f from 2025-09-11

MCP-AppleMusic: AppleScript-Based Music Control Server

The MCP-AppleMusic project provides a FastMCP server implementation for controlling Apple Music on macOS through AppleScript commands. This 272-line codebase creates an MCP (Model Context Protocol) server that exposes Apple Music functionality as callable tools, enabling programmatic control of music playback, library search, and playlist management through AppleScript automation.

The implementation centers around a simple pattern: Python functions decorated with @mcp.tool() that execute AppleScript commands via the osascript system utility. The server exposes eight core functions including playback controls (itunes_play, itunes_pause, itunes_next, itunes_previous), library operations (itunes_search, itunes_library), and advanced features like playlist creation and specific song playback.

Quick Start

brew install uv

Add to Claude Desktop’s claude_desktop_config.json:

{
  "mcpServers": {
    "iTunesControlServer": {
      "command": "uvx",
      "args": ["-p", "3.13", "-n", "mcp-applemusic"]
    }
  }
}

Time to first result: ~5 minutes (requires macOS with Apple Music installed)

Alternative Approaches

Solution Platform Support Setup Complexity API Coverage Integration
MCP-AppleMusic macOS only Low Basic controls MCP protocol
AppleScript Editor macOS only None Full Apple Music API Manual scripting
Music.app URL schemes macOS/iOS None Limited controls URL-based
osascript CLI macOS only None Full Apple Music API Command line
iTunes COM (Windows) Windows only Medium Full iTunes API COM interface

Architecture and Implementation

The core architecture revolves around a single AppleScript execution function in mcp_applemusic.py:5-8:

def run_applescript(script: str) -> str:
    """Execute an AppleScript command via osascript and return its output."""
    result = subprocess.run(["osascript", "-e", script], capture_output=True, text=True)
    if result.returncode != 0:
        return f"Error: {result.stderr.strip()}"
    return result.stdout.strip()

Each tool function follows a consistent pattern of constructing an AppleScript command and executing it. Basic playback controls demonstrate this approach in mcp_applemusic.py:18-21:

@mcp.tool()
def itunes_play() -> str:
    """Start playback in Music (iTunes)."""
    script = 'tell application "Music" to play'
    return run_applescript(script)

More complex operations like library search use multi-line AppleScript with string interpolation (mcp_applemusic.py:52-60):

script = f"""
tell application "Music"
    set trackList to every track of playlist "Library" whose name contains "{query}"
    set output to ""
    repeat with t in trackList
        set output to output & (name of t) & " - " & (artist of t) & linefeed
    end repeat
    return output
end tell
"""

The playlist creation function demonstrates the most sophisticated AppleScript construction, building dynamic conditions for multiple songs (mcp_applemusic.py:81-95):

def itunes_create_playlist(name: str, songs: str) -> str:
    # Split the songs string into a list.
    song_list = [s.strip() for s in songs.split(",") if s.strip()]
    if not song_list:
        return "No songs provided."
    # Build a condition string that matches any one of the song names.
    conditions = " or ".join([f'name is "{s}"' for s in song_list])

Performance Characteristics

Bundle Impact:

  • Core module: ~165 lines Python
  • Total package: ~272 lines across 3 files
  • Runtime dependencies: FastMCP library, subprocess (built-in)

Other Considerations:

  • Runtime dependencies: 2 (FastMCP ≥1.2.1, Python 3.13+)
  • Test coverage: 0 test files found
  • Build tooling: Basic pyproject.toml configuration

Best for: macOS-specific Apple Music automation within MCP-compatible environments like Claude Desktop

When to Use MCP-AppleMusic

The evidence suggests this project fits well for:

  • MCP-based AI assistants needing music control capabilities, as demonstrated by the Claude Desktop integration example in the README
  • macOS automation workflows where AppleScript execution through Python provides better error handling than direct AppleScript
  • Simple music control interfaces requiring only basic playback, search, and playlist operations without complex music library management

Consider alternatives when:

  • Cross-platform support is required since the implementation is macOS-specific due to AppleScript dependency
  • Advanced music library operations are needed as the current implementation only covers basic functionality shown in the 8 exposed tools
  • High-performance music processing is required since each operation involves subprocess calls to osascript, adding execution overhead