get_playlist_tracks
Retrieve track listings from Apple Music playlists by providing a playlist ID, enabling users to view and manage their music library content.
Instructions
Get the tracks inside a specific playlist.
Args: playlist_id: Library playlist ID (starts with 'p.'). Use get_library_playlists to find IDs. limit: Maximum tracks to return, 1–100 (default 100).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_id | Yes | ||
| limit | No |
Implementation Reference
- src/mcp_apple_music/server.py:320-345 (handler)The implementation of the get_playlist_tracks tool handler, which fetches tracks from a specific Apple Music playlist using the library client.
@mcp.tool() async def get_playlist_tracks(playlist_id: str, limit: int = 100) -> str: """Get the tracks inside a specific playlist. Args: playlist_id: Library playlist ID (starts with 'p.'). Use get_library_playlists to find IDs. limit: Maximum tracks to return, 1–100 (default 100). """ client = _get_client() data = await client.get( f"/me/library/playlists/{playlist_id}/tracks", params={"limit": min(max(1, limit), 100)}, ) tracks = data.get("data", []) if not tracks: return f"No tracks found in playlist '{playlist_id}'." lines = [f"🎵 Tracks in playlist [{playlist_id}] — {len(tracks)} tracks:\n"] for i, t in enumerate(tracks, 1): a = t.get("attributes", {}) lines.append( f" {i}. {a.get('name', '?')} — {a.get('artistName', '?')}" f" | Type: {t.get('type', '?')} | ID: {t.get('id', '?')}" )