Skip to main content
Glama

itunes_play_song

Play a specific song in Apple Music by searching for its exact name. Use this tool to control playback on macOS through AppleScript commands.

Instructions

Play the first track whose name exactly matches the given song name. Returns a confirmation message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
songYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the logic to play a specific song from the Music (iTunes) library using AppleScript. It searches for the first track matching the song name exactly and plays it, returning a confirmation message with artist.
    @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)
  • Helper function used by itunes_play_song and other tools to execute AppleScript commands via subprocess.
    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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kennethreitz/mcp-applemusic'

If you have feedback or need assistance with the MCP directory API, please join our Discord server