Skip to main content
Glama
djbriane
by djbriane

create_playlist

Create a new playlist in Plex Media Server by specifying a name and selecting movies from your library to organize your media collection.

Instructions

Create a new playlist with specified movies.

Parameters: name: The desired name for the new playlist. movie_keys: A comma-separated string of movie keys to include.

Returns: A success message with playlist details or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
movie_keysYes

Implementation Reference

  • The core handler function for the 'create_playlist' tool. It is decorated with @mcp.tool() which registers it with FastMCP. The function fetches movies by keys, validates them, and creates a new playlist using the Plex API.
    @mcp.tool()
    async def create_playlist(name: str, movie_keys: str) -> str:
        """
        Create a new playlist with specified movies.
        
        Parameters:
            name: The desired name for the new playlist.
            movie_keys: A comma-separated string of movie keys to include.
            
        Returns:
            A success message with playlist details 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:
            movie_key_list = [int(key.strip()) for key in movie_keys.split(",") if key.strip()]
            if not movie_key_list:
                return "ERROR: No valid movie keys provided."
    
            logger.info("Creating playlist '%s' with movie keys: %s", name, movie_keys)
            all_movies = await asyncio.to_thread(lambda: plex.library.search(libtype="movie"))
            logger.info("Found %d total movies in library", len(all_movies))
            movie_map = {movie.ratingKey: movie for movie in all_movies}
            movies = []
            not_found_keys = []
    
            for key in movie_key_list:
                if key in movie_map:
                    movies.append(movie_map[key])
                    logger.info("Found movie: %s (Key: %d)", movie_map[key].title, key)
                else:
                    not_found_keys.append(key)
                    logger.warning("Could not find movie with key: %d", key)
    
            if not_found_keys:
                return f"ERROR: Some movie keys were not found: {', '.join(str(k) for k in not_found_keys)}"
            if not movies:
                return "ERROR: No valid movies found with the provided keys."
    
            try:
                playlist_future = asyncio.create_task(
                    asyncio.to_thread(lambda: plex.createPlaylist(name, items=movies))
                )
                playlist = await asyncio.wait_for(playlist_future, timeout=15.0)
                logger.info("Playlist created successfully: %s", playlist.title)
                return f"Successfully created playlist '{name}' with {len(movies)} movie(s).\nPlaylist Key: {playlist.ratingKey}"
            except asyncio.TimeoutError:
                logger.warning("Playlist creation is taking longer than expected for '%s'", name)
                return ("PENDING: Playlist creation is taking longer than expected. "
                        "The operation might still complete in the background. "
                        "Please check your Plex server to confirm.")
        except ValueError as e:
            logger.error("Invalid input format for movie keys: %s", e)
            return f"ERROR: Invalid input format. Please check movie keys are valid numbers. {str(e)}"
        except Exception as e:
            logger.exception("Error creating playlist")
            return f"ERROR: Failed to create playlist. {str(e)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool creates a playlist and returns a success/error message, but lacks critical behavioral details: it doesn't specify required permissions, whether movie keys must be valid or exist, if there are rate limits, if the playlist is private/public by default, or what happens on duplicate names. This is a significant gap for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose in the first sentence. The parameter and return sections are structured clearly, with no redundant information. However, the return statement could be more concise (e.g., 'Returns success or error details').

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation with 2 parameters), no annotations, and no output schema, the description is incomplete. It covers basic purpose and parameters but lacks behavioral context (e.g., permissions, error conditions), usage guidelines, and detailed return value explanation. This is inadequate for a tool that creates resources.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaningful semantics: it explains that 'name' is the desired name for the playlist and 'movie_keys' is a comma-separated string of movie keys to include. This clarifies the format and purpose beyond the schema's basic titles, though it doesn't detail constraints like length limits or key validation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create a new playlist') and the resource ('playlist'), specifying it includes movies. It distinguishes from siblings like 'add_to_playlist' (which modifies existing playlists) and 'list_playlists' (which reads playlists). However, it doesn't explicitly differentiate from all siblings (e.g., 'delete_playlist' is clearly different).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing valid movie keys), exclusions (e.g., not for updating existing playlists), or direct alternatives like 'add_to_playlist' for modifying playlists. Usage is implied only by the tool's name and basic purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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