Skip to main content
Glama
jamiew

Spotify MCP Server

remove_tracks_from_playlist

Delete specific songs from a Spotify playlist by providing playlist ID and track URIs to manage your music collection.

Instructions

Remove tracks from a playlist.

Args:
    playlist_id: Playlist ID
    track_uris: List of track URIs to remove

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
track_urisYes

Implementation Reference

  • The primary handler function implementing the 'remove_tracks_from_playlist' tool. Decorated with @mcp.tool() for FastMCP registration and @log_tool_execution for logging. Converts input track URIs, calls Spotify API to remove all occurrences of tracks from the playlist, returns success status, and handles Spotify exceptions.
    @mcp.tool()
    @log_tool_execution
    def remove_tracks_from_playlist(
        playlist_id: str, track_uris: list[str]
    ) -> dict[str, str]:
        """Remove tracks from a playlist.
    
        Args:
            playlist_id: Playlist ID
            track_uris: List of track URIs to remove
        """
        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"🚮 Removing {len(uris)} tracks from playlist {playlist_id}")
            spotify_client.playlist_remove_all_occurrences_of_items(playlist_id, uris)
            return {
                "status": "success",
                "message": f"Removed {len(uris)} tracks from playlist",
            }
    
        except SpotifyException as e:
            raise convert_spotify_error(e) from e

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