Skip to main content
Glama
djbriane
by djbriane

delete_playlist

Remove playlists from your Plex Media Server to manage your media library and organize content by deleting unwanted or outdated collections.

Instructions

Delete a playlist from the Plex server.

Parameters: playlist_key: The key of the playlist to delete.

Returns: A success message if deletion is successful, or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_keyYes

Implementation Reference

  • The main handler function for the 'delete_playlist' tool. It connects to the Plex server, finds the playlist by key, deletes it, and returns a success or error message.
    @mcp.tool()
    async def delete_playlist(playlist_key: str) -> str:
        """
        Delete a playlist from the Plex server.
        
        Parameters:
            playlist_key: The key of the playlist to delete.
            
        Returns:
            A success message if deletion is successful, or an error message.
        """
        try:
            plex = await get_plex_server()
        except Exception as e:
            return f"ERROR: Could not connect to Plex server. {str(e)}"
    
        try:
            key = int(playlist_key)
            all_playlists = await asyncio.to_thread(plex.playlists)
            playlist = next((p for p in all_playlists if p.ratingKey == key), None)
            if not playlist:
                return f"No playlist found with key {playlist_key}."
            await asyncio.to_thread(playlist.delete)
            logger.info("Playlist '%s' with key %s successfully deleted.", playlist.title, playlist_key)
            return f"Successfully deleted playlist '{playlist.title}' with key {playlist_key}."
        except NotFound:
            return f"ERROR: Playlist with key {playlist_key} not found."
        except Exception as e:
            logger.exception("Failed to delete playlist with key '%s'", playlist_key)
            return f"ERROR: Failed to delete playlist. {str(e)}"
  • The tool name 'delete_playlist' is included in the __all__ export list, making it available when importing from the package.
    "delete_playlist",
  • Helper function used by delete_playlist to asynchronously obtain the PlexServer instance.
    async def get_plex_server() -> PlexServer:
        """
        Asynchronously get a PlexServer instance via the singleton PlexClient.
        
        Returns:
            A PlexServer instance.
            
        Raises:
            Exception: When the Plex server connection fails.
        """
        try:
            plex_client = get_plex_client()  # Singleton accessor
            plex = await asyncio.to_thread(plex_client.get_server)
            return plex
        except Exception as e:
            logger.exception("Failed to get Plex server instance")
            raise 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/djbriane/plex-mcp'

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