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
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_id | Yes | ||
| track_uris | Yes |
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
- src/spotify_mcp/fastmcp_server.py:551-551 (registration)The @mcp.tool() decorator registers the add_tracks_to_playlist function as an MCP tool in the FastMCP server.@mcp.tool()