Skip to main content
Glama
keenanbass1

TIDAL MCP Server

by keenanbass1

get_artist_albums

Retrieve an artist's discography from TIDAL by providing their artist ID to access albums and track listings.

Instructions

Get albums by an artist (discography).

Args: artist_id: ID of the artist limit: Maximum albums to return (default: 20, max: 50)

Returns: List of albums by the artist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
artist_idYes
limitNo

Implementation Reference

  • The handler function implementing the get_artist_albums tool. It authenticates, fetches the artist, retrieves their albums via tidalapi, constructs Album objects, and returns an AlbumList.
    @mcp.tool()
    async def get_artist_albums(artist_id: str, limit: int = 20) -> AlbumList:
        """
        Get albums by an artist (discography).
    
        Args:
            artist_id: ID of the artist
            limit: Maximum albums to return (default: 20, max: 50)
    
        Returns:
            List of albums by the artist
        """
        if not await ensure_authenticated():
            raise ToolError("Not authenticated. Please run the 'login' tool first.")
    
        try:
            limit = min(max(1, limit), 50)
    
            artist = await anyio.to_thread.run_sync(session.artist, artist_id)
            if not artist:
                raise ToolError(f"Artist with ID '{artist_id}' not found")
    
            artist_albums = await anyio.to_thread.run_sync(
                lambda: artist.get_albums(limit=limit)
            )
    
            albums = []
            for album in artist_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 artist.name,
                        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",
                count=len(albums),
                albums=albums,
            )
        except ToolError:
            raise
        except Exception as e:
            raise ToolError(f"Failed to get artist albums: {str(e)}")
  • Pydantic BaseModel defining the output structure AlbumList for the get_artist_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 defining the Album entity used within the AlbumList output of get_artist_albums.
    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 get_artist_albums to ensure user authentication before 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