itunes_play_song
Play a specific song in Apple Music by matching the exact song name. Returns a confirmation message upon successful playback. Part of the MCP-AppleMusic server for macOS control.
Instructions
Play the first track whose name exactly matches the given song name. Returns a confirmation message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| song | Yes |
Implementation Reference
- mcp_applemusic.py:64-77 (handler)The handler function for the 'itunes_play_song' tool. It uses AppleScript via run_applescript to find and play a song by exact name match in the Music library, returning a confirmation message.@mcp.tool() def itunes_play_song(song: str) -> str: """ Play the first track whose name exactly matches the given song name. Returns a confirmation message. """ script = f""" tell application "Music" set theTrack to first track of playlist "Library" whose name is "{song}" play theTrack return "Now playing: " & (name of theTrack) & " by " & (artist of theTrack) end tell """ return run_applescript(script)
- mcp_applemusic.py:5-10 (helper)Helper function used by itunes_play_song (and other tools) to execute AppleScript commands.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()
- mcp_applemusic.py:64-64 (registration)The @mcp.tool() decorator registers the itunes_play_song function as an MCP tool.@mcp.tool()