get_favorite_tracks
Retrieve your saved favorite tracks from TIDAL to view or manage your preferred music collection.
Instructions
Retrieves tracks from the user's TIDAL account favorites.
USE THIS TOOL WHENEVER A USER ASKS FOR:
- "What are my favorite tracks?"
- "Show me my TIDAL favorites"
- "What music do I have saved?"
- "Get my favorite songs"
- Any request to view their saved/favorite tracks
This function retrieves the user's favorite tracks from TIDAL.
Args:
limit: Maximum number of tracks to retrieve (default: 20, note it should be large enough by default unless specified otherwise).
Returns:
A dictionary containing track information including track ID, title, artist, album, and duration.
Returns an error message if not authenticated or if retrieval fails.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No |
Implementation Reference
- mcp_server/server.py:50-104 (handler)MCP tool handler decorated with @mcp.tool() that implements the get_favorite_tracks tool logic by checking authentication and proxying requests to the Flask backend /api/tracks endpoint.@mcp.tool() def get_favorite_tracks(limit: int = 20) -> dict: """ Retrieves tracks from the user's TIDAL account favorites. USE THIS TOOL WHENEVER A USER ASKS FOR: - "What are my favorite tracks?" - "Show me my TIDAL favorites" - "What music do I have saved?" - "Get my favorite songs" - Any request to view their saved/favorite tracks This function retrieves the user's favorite tracks from TIDAL. Args: limit: Maximum number of tracks to retrieve (default: 20, note it should be large enough by default unless specified otherwise). Returns: A dictionary containing track information including track ID, title, artist, album, and duration. Returns an error message if not authenticated or if retrieval fails. """ try: # 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 favorite tracks. Please use the tidal_login() function." } # Call your Flask endpoint to retrieve tracks with the specified limit response = requests.get(f"{FLASK_APP_URL}/api/tracks", params={"limit": limit}) # Check if the request was successful if response.status_code == 200: return response.json() 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 tracks: {error_data.get('error', 'Unknown error')}" } except Exception as e: return { "status": "error", "message": f"Failed to connect to TIDAL tracks service: {str(e)}" }
- tidal_api/app.py:113-132 (helper)Flask backend endpoint /api/tracks that implements the core logic for fetching user's favorite tracks from TIDAL API using session.user.favorites.tracks(). Called by the MCP tool handler.@app.route('/api/tracks', methods=['GET']) @requires_tidal_auth def get_tracks(session: BrowserSession): """ Get tracks from the user's history. """ try: # TODO: Add streaminig history support if TIDAL API allows it # Get user favorites or history (for now limiting to user favorites only) favorites = session.user.favorites # Get limit from query parameter, default to 10 if not specified limit = bound_limit(request.args.get('limit', default=10, type=int)) tracks = favorites.tracks(limit=limit, order="DATE", order_direction="DESC") track_list = [format_track_data(track) for track in tracks] return jsonify({"tracks": track_list}) except Exception as e: return jsonify({"error": f"Error fetching tracks: {str(e)}"}), 500
- mcp_server/server.py:50-50 (registration)Registration of the get_favorite_tracks tool using the @mcp.tool() decorator.@mcp.tool()