Skip to main content
Glama

get_playlist_tracks

Retrieve all tracks from a specified TIDAL playlist to view song names, artists, albums, and durations. Provide the playlist ID to list contents.

Instructions

Retrieves all tracks from a specified TIDAL playlist. USE THIS TOOL WHENEVER A USER ASKS FOR: - "Show me the songs in my playlist" - "What tracks are in my [playlist name] playlist?" - "List the songs from my playlist" - "Get tracks from my playlist" - "View contents of my TIDAL playlist" - Any request to see what songs/tracks are in a specific playlist This function retrieves all tracks from a specific playlist in the user's TIDAL account. The playlist_id must be provided, which can be obtained from the get_user_playlists() function. When processing the results of this tool: 1. Present the playlist information (title, description, track count) as context 2. List the tracks in a clear, organized format with track name, artist, and album 3. Include track durations where available 4. Mention the total number of tracks in the playlist 5. If there are many tracks, focus on highlighting interesting patterns or variety Args: playlist_id: The TIDAL ID of the playlist to retrieve (required) limit: Maximum number of tracks to retrieve (default: 100) Returns: A dictionary containing the playlist information and all tracks in the playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
limitNo

Implementation Reference

  • MCP tool handler for 'get_playlist_tracks'. Decorated with @mcp.tool() for registration. Validates input, checks authentication, and proxies HTTP request to the backend Tidal Flask API to retrieve and return playlist tracks.
    def get_playlist_tracks(playlist_id: str, limit: int = 100) -> dict: """ Retrieves all tracks from a specified TIDAL playlist. USE THIS TOOL WHENEVER A USER ASKS FOR: - "Show me the songs in my playlist" - "What tracks are in my [playlist name] playlist?" - "List the songs from my playlist" - "Get tracks from my playlist" - "View contents of my TIDAL playlist" - Any request to see what songs/tracks are in a specific playlist This function retrieves all tracks from a specific playlist in the user's TIDAL account. The playlist_id must be provided, which can be obtained from the get_user_playlists() function. When processing the results of this tool: 1. Present the playlist information (title, description, track count) as context 2. List the tracks in a clear, organized format with track name, artist, and album 3. Include track durations where available 4. Mention the total number of tracks in the playlist 5. If there are many tracks, focus on highlighting interesting patterns or variety Args: playlist_id: The TIDAL ID of the playlist to retrieve (required) limit: Maximum number of tracks to retrieve (default: 100) Returns: A dictionary containing the playlist information and all tracks in the playlist """ # First, check if the user is authenticated auth_check = requests.get(f"{FLASK_APP_URL}/api/auth/status") auth_data = auth_check.json() if not auth_data.get("authenticated", False): return { "status": "error", "message": "You need to login to TIDAL first before I can fetch playlist tracks. Please use the tidal_login() function." } # Validate playlist_id if not playlist_id: return { "status": "error", "message": "A playlist ID is required. You can get playlist IDs by using the get_user_playlists() function." } try: # Call the Flask endpoint to retrieve tracks from the playlist response = requests.get( f"{FLASK_APP_URL}/api/playlists/{playlist_id}/tracks", params={"limit": limit} ) # Check if the request was successful if response.status_code == 200: data = response.json() return { "status": "success", "tracks": data.get("tracks", []), "track_count": data.get("total_tracks", 0) } elif response.status_code == 404: return { "status": "error", "message": f"Playlist with ID {playlist_id} not found. Please check the playlist ID and try again." } elif response.status_code == 401: return { "status": "error", "message": "Not authenticated with TIDAL. Please login first using tidal_login()." } else: error_data = response.json() return { "status": "error", "message": f"Failed to retrieve playlist tracks: {error_data.get('error', 'Unknown error')}" } except Exception as e: return { "status": "error", "message": f"Failed to connect to TIDAL playlist service: {str(e)}" }
  • Backend Flask API endpoint that implements the actual TIDAL playlist tracks retrieval using BrowserSession.playlist().items(), formats tracks, and serves data consumed by the MCP handler.
    @app.route('/api/playlists/<playlist_id>/tracks', methods=['GET']) @requires_tidal_auth def get_playlist_tracks(playlist_id: str, session: BrowserSession): """ Get tracks from a specific TIDAL playlist. """ try: # Get limit from query parameter, default to 100 if not specified limit = bound_limit(request.args.get('limit', default=100, type=int)) # Get the playlist object playlist = session.playlist(playlist_id) if not playlist: return jsonify({"error": f"Playlist with ID {playlist_id} not found"}), 404 # Get tracks from the playlist with pagination if needed tracks = playlist.items(limit=limit) # Format track data track_list = [format_track_data(track) for track in tracks] return jsonify({ "playlist_id": playlist.id, "tracks": track_list, "total_tracks": len(track_list) }) except Exception as e: return jsonify({"error": f"Error fetching playlist tracks: {str(e)}"}), 500
  • Utility functions used by the playlist tracks endpoint: format_track_data standardizes track info, bound_limit sanitizes the limit parameter.
    def format_track_data(track, source_track_id=None): """ Format a track object into a standardized dictionary. Args: track: TIDAL track object source_track_id: Optional ID of the track that led to this recommendation Returns: Dictionary with standardized track information """ track_data = { "id": track.id, "title": track.name, "artist": track.artist.name if hasattr(track.artist, 'name') else "Unknown", "album": track.album.name if hasattr(track.album, 'name') else "Unknown", "duration": track.duration if hasattr(track, 'duration') else 0, "url": f"https://tidal.com/browse/track/{track.id}?u" } # Include source track ID if provided if source_track_id: track_data["source_track_id"] = source_track_id return track_data def bound_limit(limit: int, max_n: int = 50) -> int: # Ensure limit is within reasonable bounds if limit < 1: limit = 1 elif limit > max_n: limit = max_n print(f"Limit set to {limit} (max {max_n})") return limit

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/yuhuacheng/tidal-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server