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
| Name | Required | Description | Default |
|---|---|---|---|
| songs | Yes |
Implementation Reference
- spotify.py:62-95 (handler)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")
- spotify.py:63-75 (schema)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. """