add_tracks_to_playlist
Add songs from your library or Apple Music catalog to an existing playlist using track IDs and playlist ID.
Instructions
Add tracks to an existing playlist.
Args: playlist_id: The target playlist ID (starts with 'p.'). track_ids: List of track IDs to add. track_type: 'library-songs' for tracks from your library (default), 'songs' for catalog tracks found via search_catalog.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_id | Yes | ||
| track_ids | Yes | ||
| track_type | No | library-songs |
Implementation Reference
- src/mcp_apple_music/server.py:384-407 (handler)The `add_tracks_to_playlist` function handles the request to add tracks to a specific Apple Music playlist by communicating with the client API.
async def add_tracks_to_playlist( playlist_id: str, track_ids: list[str], track_type: str = "library-songs", ) -> str: """Add tracks to an existing playlist. Args: playlist_id: The target playlist ID (starts with 'p.'). track_ids: List of track IDs to add. track_type: 'library-songs' for tracks from your library (default), 'songs' for catalog tracks found via search_catalog. """ if not track_ids: return "❌ No track IDs provided." client = _get_client() body = {"data": [{"id": tid, "type": track_type} for tid in track_ids]} await client.post(f"/me/library/playlists/{playlist_id}/tracks", body) return ( f"✅ Added {len(track_ids)} track(s) to playlist [{playlist_id}].\n" f" Track IDs: {', '.join(track_ids)}" )