Skip to main content
Glama
belljustin

Spotify Model Context Protocol

by belljustin

get_track_uris

Retrieve Spotify track URIs by providing song names and artists, enabling playlist creation and music management through the Spotify Model Context Protocol.

Instructions

Look up Spotify track URIs for a list of songs.

Args:
    songs: List of dictionaries containing song information.
          Each dictionary should have 'name' and 'artist' keys.
          Example: [{"name": "Yesterday", "artist": "The Beatles"}]

Returns:
    List of Spotify track URIs for the found songs.
    Songs that couldn't be found will be skipped.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
songsYes

Implementation Reference

  • Implementation of the get_track_uris tool handler. This function looks up Spotify track URIs for a list of songs using the SpotifyClient. It handles authentication and token refresh.
    @mcp.tool("get_track_uris")
    def get_track_uris(songs: List[dict]) -> List[str]:
        """
        Look up Spotify track URIs for a list of songs.
    
        Args:
            songs: List of dictionaries containing song information.
                  Each dictionary should have 'name' and 'artist' keys.
                  Example: [{"name": "Yesterday", "artist": "The Beatles"}]
    
        Returns:
            List of Spotify track URIs for the found songs.
            Songs that couldn't be found will be skipped.
        """
        user_id = get_current_user_id()
        tokens = get_user_tokens(user_id)
        if not tokens:
            raise Exception("No tokens found for user")
    
        if tokens["token_expiry"] < time.time():
            tokens = spotify_client.refresh_access_token(tokens["refresh_token"])
            update_access_token(user_id, tokens["access_token"], tokens.get("expires_in", 3600))
        
        track_uris = []
        for song in songs:
            uri = spotify_client.get_track_uri(
                access_token=tokens["access_token"],
                artist=song["artist"],
                song_name=song["name"]
            )
            if uri:
                track_uris.append(uri)
        
        return track_uris
  • spotify.py:62-62 (registration)
    Registration of the get_track_uris tool using the @mcp.tool decorator.
    @mcp.tool("get_track_uris")
  • Input schema defined by type hints (songs: List[dict]) and detailed docstring describing the expected structure.
    def get_track_uris(songs: List[dict]) -> List[str]:
        """
        Look up Spotify track URIs for a list of songs.
    
        Args:
            songs: List of dictionaries containing song information.
                  Each dictionary should have 'name' and 'artist' keys.
                  Example: [{"name": "Yesterday", "artist": "The Beatles"}]
    
        Returns:
            List of Spotify track URIs for the found songs.
            Songs that couldn't be found will be skipped.
        """
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it performs a lookup operation (implied read-only), handles multiple songs via a list, skips unfound songs (partial success behavior), and returns a list of URIs. It doesn't mention rate limits, authentication needs, or error handling details, but covers core functionality adequately.

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 appropriately sized and front-loaded: the first sentence states the purpose, followed by clear sections for Args and Returns with bullet-point-like formatting. Every sentence adds value, with no wasted words, making it easy to scan and understand.

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

Completeness4/5

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

Given 1 parameter with no schema coverage and no output schema, the description is mostly complete: it explains the input format, output format, and behavior (skipping unfound songs). It could improve by mentioning authentication requirements or rate limits, but for a lookup tool with simple parameters, it provides sufficient context for effective use.

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

Parameters5/5

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

The input schema has 0% description coverage, so the description fully compensates by detailing the 'songs' parameter: it's a list of dictionaries with required 'name' and 'artist' keys, includes an example, and explains the structure. This adds significant meaning beyond the bare schema.

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's purpose with a specific verb ('look up') and resource ('Spotify track URIs'), and distinguishes it from sibling tools (create_playlist, update_playlist) by focusing on retrieval rather than playlist manipulation. It explicitly mentions what it does: converting song information into Spotify URIs.

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

Usage Guidelines4/5

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

The description implies usage context by specifying it's for 'a list of songs' and provides an example, but doesn't explicitly state when to use this tool versus alternatives like search or when not to use it. It differentiates from siblings by function, though not with explicit 'use this when...' guidance.

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

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

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