itunes_search
Search the Apple Music library for tracks by name using a query, returning results formatted as 'Track Name - Artist'.
Instructions
Search the Music library for tracks whose names contain the given query. Returns a list of tracks formatted as "Track Name - Artist".
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- mcp_applemusic.py:45-62 (handler)The primary handler for the 'itunes_search' tool. It uses AppleScript via run_applescript to find tracks in the Music library matching the query and returns a formatted list.@mcp.tool() def itunes_search(query: str) -> str: """ Search the Music library for tracks whose names contain the given query. Returns a list of tracks formatted as "Track Name - Artist". """ 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 """ return run_applescript(script)
- mcp_applemusic.py:5-10 (helper)Helper function used by itunes_search to execute the AppleScript code for searching the library.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()