Skip to main content
Glama

SpotifyGetInfo

Retrieve detailed information about Spotify items, including tracks, albums, artists, or playlists. Input the item's URI to fetch its data, such as tracks for playlists or albums, and albums with top tracks for artists.

Instructions

Get detailed information about a Spotify item (track, album, artist, or playlist).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
item_uriYesURI of the item to get information about. If 'playlist' or 'album', returns its tracks. If 'artist', returns albums and top tracks.

Implementation Reference

  • Core handler function that implements the logic for retrieving detailed information about Spotify items (track, album, artist, playlist) using Spotipy API.
    def get_info(self, item_uri): """Gets detailed information about a Spotify item based on its URI.""" item_id = self._extract_id_from_uri(item_uri) if 'track' in item_uri: item = self.sp.track(item_id) info = { 'type': 'track', 'name': item['name'], 'artists': [artist['name'] for artist in item['artists']], 'album': item['album']['name'], 'duration_ms': item['duration_ms'], 'popularity': item['popularity'], 'uri': item['uri'], 'external_url': item['external_urls']['spotify'] if 'external_urls' in item else None } elif 'playlist' in item_uri: item = self.sp.playlist(item_id) info = { 'type': 'playlist', 'name': item['name'], 'owner': item['owner']['display_name'], 'description': item['description'], 'tracks_total': item['tracks']['total'], 'followers': item['followers']['total'], 'uri': item['uri'], 'external_url': item['external_urls']['spotify'] if 'external_urls' in item else None } elif 'album' in item_uri: item = self.sp.album(item_id) info = { 'type': 'album', 'name': item['name'], 'artists': [artist['name'] for artist in item['artists']], 'release_date': item['release_date'], 'total_tracks': item['total_tracks'], 'popularity': item['popularity'], 'uri': item['uri'], 'external_url': item['external_urls']['spotify'] if 'external_urls' in item else None } elif 'artist' in item_uri: item = self.sp.artist(item_id) info = { 'type': 'artist', 'name': item['name'], 'genres': item['genres'], 'followers': item['followers']['total'], 'popularity': item['popularity'], 'uri': item['uri'], 'external_url': item['external_urls']['spotify'] if 'external_urls' in item else None } else: raise ValueError(f"Unsupported URI type: {item_uri}") return info
  • Input schema definition for the SpotifyGetInfo tool using Pydantic model, specifying the required item_uri parameter.
    class GetInfo(ToolModel): """Get detailed information about a Spotify item (track, album, artist, or playlist).""" item_uri: str = Field(description="URI of the item to get information about. " + "If 'playlist' or 'album', returns its tracks. " + "If 'artist', returns albums and top tracks.")
  • Registration of the SpotifyGetInfo tool (as 'SpotifyGetInfo') in the MCP server's list_tools method via GetInfo.as_tool().
    tools = [ Playback.as_tool(), Search.as_tool(), Queue.as_tool(), GetInfo.as_tool(), Playlist.as_tool(), ]
  • MCP server tool handler that processes calls to SpotifyGetInfo by invoking the spotify_client.get_info method and returning JSON response.
    case "GetInfo": logger.info(f"Getting item info with arguments: {arguments}") item_info = spotify_client.get_info( item_uri=arguments.get("item_uri") ) return [types.TextContent( type="text", text=json.dumps(item_info, indent=2) )]
  • Helper method used by get_info to extract the Spotify resource ID from the provided URI.
    def _extract_id_from_uri(self, uri): """Extracts the ID portion from a Spotify URI.""" # Handle different URI formats # spotify:type:id # https://open.spotify.com/type/id if uri.startswith('spotify:'): parts = uri.split(':') return parts[-1] elif uri.startswith('http'): # Extract the path and split by '/' from urllib.parse import urlparse path = urlparse(uri).path parts = path.split('/') # The ID should be the last part return parts[-1] else: # Assume it's just the ID return uri @utils.validate

Other Tools

Related Tools

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/g2dgaming/spotify-mcp'

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