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

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.7/5.0
Behavior3/5

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

No annotations are present, so the description carries the full burden. It explains return differences by type (tracks for albums/playlists, albums/top tracks for artists), but does not specify nondestructive nature, authentication needs, or rate limits.

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, concise sentence with no wasted words. It efficiently conveys the core function.

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

Completeness3/5

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

Given no output schema, the description partially compensates by specifying behavior per item type, but it does not enumerate all returned fields (e.g., metadata like name, duration). This leaves some ambiguity for a simple tool.

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% and already details the URI parameter's behavior. The description adds no additional meaning beyond restating the tool's purpose, so baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the tool retrieves detailed information for a Spotify item (track, album, artist, or playlist), differentiating it from siblings like SpotifySearch (which searches by query) and SpotifyPlayback/Queue (which control playback).

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

Usage Guidelines3/5

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

Usage is implied by the schema requiring a URI, but the description does not explicitly state when to use this tool over siblings or provide exclusions. An agent must infer context from sibling names.

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

Deploy Server

Other Tools

Related Tools