Skip to main content
Glama

itunes_create_playlist

Create and populate a new Apple Music playlist by specifying a name and listing exact track names. Returns confirmation with the number of tracks added.

Instructions

Create a new playlist with the given name and add tracks to it. 'songs' should be a comma-separated list of exact track names. Returns a confirmation message including the number of tracks added.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
songsYes

Implementation Reference

  • The main handler function for the 'itunes_create_playlist' tool. It processes a list of song names, constructs an AppleScript to create a new playlist in Music.app, adds matching tracks by duplicating them, and returns a confirmation message.
    @mcp.tool() def itunes_create_playlist(name: str, songs: str) -> str: """ Create a new playlist with the given name and add tracks to it. 'songs' should be a comma-separated list of exact track names. Returns a confirmation message including the number of tracks added. """ # 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. # Example: 'name is "Song1" or name is "Song2"' conditions = " or ".join([f'name is "{s}"' for s in song_list]) script = f""" tell application "Music" set newPlaylist to make new user playlist with properties {{name:"{name}"}} set matchingTracks to every track of playlist "Library" whose ({conditions}) repeat with t in matchingTracks duplicate t to newPlaylist end repeat return "Playlist \\"{name}\\" created with " & (count of tracks of newPlaylist) & " tracks." end tell """ return run_applescript(script)
  • Utility function used by the tool to execute AppleScript commands against the Music application.
    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()
  • Input schema and documentation for the tool, specifying parameters 'name' (str) for playlist name and 'songs' (str) as comma-separated track names.
    def itunes_create_playlist(name: str, songs: str) -> str: """ Create a new playlist with the given name and add tracks to it. 'songs' should be a comma-separated list of exact track names. Returns a confirmation message including the number of tracks added. """
  • The @mcp.tool() decorator registers the itunes_create_playlist function as an MCP tool.
    @mcp.tool()

Other Tools

Related Tools

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