Skip to main content
Glama
keenanbass1

TIDAL MCP Server

by keenanbass1

search_albums

Find albums on TIDAL by searching with album names, artist names, or combined queries to discover music content.

Instructions

Search for albums on TIDAL.

Args: query: Search query - album name, artist name, or combination limit: Maximum results (1-50, default: 10)

Returns: List of matching albums with id, title, artist, release date, track count, and URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
limitNo

Implementation Reference

  • The core handler function for the 'search_albums' tool, which includes the @mcp.tool() registration decorator. Performs authentication, searches TIDAL for albums, maps results to Album models, and returns AlbumList.
    @mcp.tool()
    async def search_albums(query: str, limit: int = 10) -> AlbumList:
        """
        Search for albums on TIDAL.
    
        Args:
            query: Search query - album name, artist name, or combination
            limit: Maximum results (1-50, default: 10)
    
        Returns:
            List of matching albums with id, title, artist, release date, track count, and URL
        """
        if not await ensure_authenticated():
            raise ToolError("Not authenticated. Please run the 'login' tool first.")
    
        try:
            limit = min(max(1, limit), 50)
            results = await anyio.to_thread.run_sync(
                lambda: session.search(query, models=[tidalapi.Album], limit=limit)
            )
    
            albums = []
            for album in results.get("albums", []):
                release_date = None
                if hasattr(album, "release_date") and album.release_date:
                    release_date = str(album.release_date)
    
                albums.append(
                    Album(
                        id=str(album.id),
                        title=album.name,
                        artist=album.artist.name if album.artist else "Unknown Artist",
                        release_date=release_date,
                        num_tracks=getattr(album, "num_tracks", 0),
                        duration_seconds=getattr(album, "duration", 0),
                        url=f"https://tidal.com/browse/album/{album.id}",
                    )
                )
    
            return AlbumList(status="success", query=query, count=len(albums), albums=albums)
        except Exception as e:
            raise ToolError(f"Album search failed: {str(e)}")
  • Pydantic BaseModel defining the output schema for the search_albums tool response.
    class AlbumList(BaseModel):
        """List of albums with metadata."""
    
        status: str = Field(description="Operation status (success/error)")
        query: Optional[str] = Field(None, description="Search query used (for search results)")
        count: int = Field(description="Number of albums returned")
        albums: List[Album] = Field(description="List of album objects")
  • Pydantic BaseModel for individual Album objects used within the AlbumList output schema.
    class Album(BaseModel):
        """Structured representation of a TIDAL album."""
    
        id: str = Field(description="Unique TIDAL album ID")
        title: str = Field(description="Album title")
        artist: str = Field(description="Primary artist name")
        release_date: Optional[str] = Field(None, description="Release date (YYYY-MM-DD)")
        num_tracks: int = Field(description="Number of tracks in album")
        duration_seconds: int = Field(description="Total album duration in seconds")
        url: str = Field(description="TIDAL web URL for the album")
  • Helper function used by search_albums (and other tools) to ensure user authentication before performing API calls.
    async def ensure_authenticated() -> bool:
        """
        Check if user is authenticated with TIDAL.
        Automatically loads persisted session if available.
        """
        if await anyio.Path(SESSION_FILE).exists():
            try:
                async with await anyio.open_file(SESSION_FILE, "r") as f:
                    content = await f.read()
                    data = json.loads(content)
    
                # Load OAuth session
                result = await anyio.to_thread.run_sync(
                    session.load_oauth_session,
                    data["token_type"]["data"],
                    data["access_token"]["data"],
                    data["refresh_token"]["data"],
                    None,  # expiry time
                )
    
                if result:
                    is_valid = await anyio.to_thread.run_sync(session.check_login)
                    if not is_valid:
                        await anyio.Path(SESSION_FILE).unlink()
                    return is_valid
                return False
            except Exception:
                await anyio.Path(SESSION_FILE).unlink()
                return False
    
        return await anyio.to_thread.run_sync(session.check_login)

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

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