Skip to main content
Glama
g2dgaming

Spotify MCP Server

by g2dgaming

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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but lacks details on permissions needed, rate limits, response format, or error handling. For a tool with no annotations, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, with every element contributing to clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of handling multiple item types and no output schema, the description is incomplete. It does not explain what detailed information is returned (e.g., track details, album tracks) or handle edge cases, which is inadequate for a tool with diverse inputs and no structured output documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the schema providing details on the item_uri parameter, including its purpose and behavior for different item types. The description adds no additional parameter semantics beyond what the schema already covers, so it meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get detailed information') and resource ('Spotify item'), specifying the types of items (track, album, artist, or playlist). It distinguishes this as an information retrieval tool, but does not explicitly differentiate it from sibling tools like SpotifySearch, which might also retrieve information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as SpotifySearch for broader queries or SpotifyPlaylist for playlist-specific operations. It lacks explicit when/when-not instructions or named alternatives, leaving usage context implied but not clarified.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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