Skip to main content
Glama

add_tracks_to_playlist

Add multiple songs to a Spotify playlist using track URIs. Specify playlist ID and up to 100 track URIs to expand your music collection.

Instructions

Add tracks to a playlist.

Args: playlist_id: Playlist ID track_uris: List of track URIs (up to 100)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
track_urisYes

Implementation Reference

  • The core handler function for the 'add_tracks_to_playlist' tool. It is registered via the @mcp.tool() decorator and implements adding tracks to a Spotify playlist by converting IDs to URIs if necessary and calling the Spotify API's playlist_add_items method. Includes logging and proper error handling.
    @mcp.tool() @log_tool_execution def add_tracks_to_playlist(playlist_id: str, track_uris: list[str]) -> dict[str, str]: """Add tracks to a playlist. Args: playlist_id: Playlist ID track_uris: List of track URIs (up to 100) """ try: # Convert track IDs to URIs if needed uris = [ uri if uri.startswith("spotify:track:") else f"spotify:track:{uri}" for uri in track_uris ] logger.info(f"🎧 Adding {len(uris)} tracks to playlist {playlist_id}") spotify_client.playlist_add_items(playlist_id, uris) return {"status": "success", "message": f"Added {len(uris)} tracks to playlist"} except SpotifyException as e: raise convert_spotify_error(e) from e
  • The @mcp.tool() decorator registers the add_tracks_to_playlist function as an MCP tool in the FastMCP server.
    @mcp.tool()

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

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