get_user_playlists
Retrieve and organize a user's TIDAL playlists sorted by last updated date, displaying key details like title, track count, and TIDAL URL for easy access and management.
Instructions
Fetches the user's playlists from their TIDAL account.
USE THIS TOOL WHENEVER A USER ASKS FOR:
- "Show me my playlists"
- "List my TIDAL playlists"
- "What playlists do I have?"
- "Get my music collections"
- Any request to view or list their TIDAL playlists
This function retrieves the user's playlists from TIDAL and returns them sorted
by last updated date (most recent first).
When processing the results of this tool:
1. Present the playlists in a clear, organized format
2. Include key information like title, track count, and the TIDAL URL for each playlist
3. Mention when each playlist was last updated if available
4. If the user has many playlists, focus on the most recently updated ones unless specified otherwise
Returns:
A dictionary containing the user's playlists sorted by last updated date
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_server/server.py:390-450 (handler)MCP tool registration and handler for 'get_user_playlists'. This function authenticates the user and proxies requests to the Tidal API Flask endpoint at /api/playlists to fetch the user's playlists.@mcp.tool() def get_user_playlists() -> dict: """ Fetches the user's playlists from their TIDAL account. USE THIS TOOL WHENEVER A USER ASKS FOR: - "Show me my playlists" - "List my TIDAL playlists" - "What playlists do I have?" - "Get my music collections" - Any request to view or list their TIDAL playlists This function retrieves the user's playlists from TIDAL and returns them sorted by last updated date (most recent first). When processing the results of this tool: 1. Present the playlists in a clear, organized format 2. Include key information like title, track count, and the TIDAL URL for each playlist 3. Mention when each playlist was last updated if available 4. If the user has many playlists, focus on the most recently updated ones unless specified otherwise Returns: A dictionary containing the user's playlists sorted by last updated date """ # 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 your playlists. Please use the tidal_login() function." } try: # Call the Flask endpoint to retrieve playlists with the specified limit response = requests.get(f"{FLASK_APP_URL}/api/playlists") # Check if the request was successful if response.status_code == 200: return { "status": "success", "playlists": response.json().get("playlists", []), "playlist_count": len(response.json().get("playlists", [])) } 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 playlists: {error_data.get('error', 'Unknown error')}" } except Exception as e: return { "status": "error", "message": f"Failed to connect to TIDAL playlists service: {str(e)}" }
- tidal_api/app.py:293-327 (handler)Core implementation of the playlists fetching logic in the Flask API. Retrieves playlists using the Tidal BrowserSession, formats them with details like ID, title, description, track count, and sorts by last updated date.@app.route('/api/playlists', methods=['GET']) @requires_tidal_auth def get_user_playlists(session: BrowserSession): """ Get the user's playlists from TIDAL. """ try: # Get user playlists playlists = session.user.playlists() # Format playlist data playlist_list = [] for playlist in playlists: playlist_info = { "id": playlist.id, "title": playlist.name, "description": playlist.description if hasattr(playlist, 'description') else "", "created": playlist.created if hasattr(playlist, 'created') else None, "last_updated": playlist.last_updated if hasattr(playlist, 'last_updated') else None, "track_count": playlist.num_tracks if hasattr(playlist, 'num_tracks') else 0, "duration": playlist.duration if hasattr(playlist, 'duration') else 0, "url": f"https://tidal.com/playlist/{playlist.id}" } playlist_list.append(playlist_info) # Sort playlists by last_updated in descending order sorted_playlists = sorted( playlist_list, key=lambda x: x.get('last_updated', ''), reverse=True ) return jsonify({"playlists": sorted_playlists}) except Exception as e: return jsonify({"error": f"Error fetching playlists: {str(e)}"}), 500