get_artist_info
Retrieve detailed information about a Spotify artist, including their top tracks, using the artist's Spotify ID.
Instructions
Get detailed information about a Spotify artist.
Args:
artist_id: Spotify artist ID
Returns:
Dict with artist info and top tracksInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| artist_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Handler function for the 'get_artist_info' tool. Uses @mcp.tool() decorator for FastMCP registration, calls spotify_client.artist() and spotify_client.artist_top_tracks(), constructs an Artist model and parses top tracks, returning structured dict output.
@mcp.tool() @log_tool_execution def get_artist_info(artist_id: str) -> dict[str, Any]: """Get detailed information about a Spotify artist. Args: artist_id: Spotify artist ID Returns: Dict with artist info and top tracks """ try: logger.info(f"🎤 Getting artist info: {artist_id}") result = spotify_client.artist(artist_id) top_tracks = spotify_client.artist_top_tracks(artist_id) artist = Artist( name=result["name"], id=result["id"], genres=result.get("genres", []), popularity=result.get("popularity"), followers=result.get("followers", {}).get("total"), ) tracks = [parse_track(track) for track in top_tracks.get("tracks", [])[:10]] return { "artist": artist.model_dump(), "top_tracks": [track.model_dump() for track in tracks], } except SpotifyException as e: raise convert_spotify_error(e) from e - Pydantic Artist model (BaseModel) used by get_artist_info for structured output, with fields: name, id, genres, popularity, followers.
class Artist(BaseModel): """A Spotify artist.""" name: str id: str genres: list[str] | None = None popularity: int | None = None followers: int | None = None - Pydantic Track model (BaseModel) used for parsing top tracks in get_artist_info.
class Track(BaseModel): """A Spotify track with metadata.""" name: str id: str artist: str artists: list[str] | None = None album: str | None = None album_id: str | None = None release_date: str | None = None duration_ms: int | None = None popularity: int | None = None external_urls: dict[str, str] | None = None - src/spotify_mcp/fastmcp_server.py:445-447 (registration)Tool registered via the @mcp.tool() decorator on the handler function, which automatically registers it with the FastMCP server.
@mcp.tool() @log_tool_execution def get_artist_info(artist_id: str) -> dict[str, Any]: - parse_track helper function used to convert raw Spotify track dicts into Track model instances for the top_tracks output.
def parse_track(item: dict[str, Any]) -> Track: """Parse Spotify track data into Track model.""" album_data = item.get("album", {}) return Track( name=item["name"], id=item["id"], artist=item["artists"][0]["name"] if item.get("artists") else "Unknown", artists=[a["name"] for a in item.get("artists", [])], album=album_data.get("name"), album_id=album_data.get("id"), release_date=album_data.get("release_date"), duration_ms=item.get("duration_ms"), popularity=item.get("popularity"), external_urls=item.get("external_urls"), )