itunes_all_songs
Retrieve all songs from your Apple Music library to view a formatted list of tracks with artist names.
Instructions
Get a list of all songs in the Music library. Returns a formatted list of all tracks with their names and artists.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_applemusic.py:141-157 (handler)The handler function for the 'itunes_all_songs' tool. It uses AppleScript to fetch all tracks from the Music app's Library playlist and returns a list formatted as 'Track Name - Artist' for each track. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() def itunes_all_songs() -> str: """ Get a list of all songs in the Music library. Returns a formatted list of all tracks with their names and artists. """ script = """ tell application "Music" set trackList to every track of playlist "Library" 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)Shared helper function used by itunes_all_songs (and other tools) to execute AppleScript commands via the osascript 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()