Skip to main content
Glama
djbriane
by djbriane

add_to_playlist

Add movies to existing Plex playlists by specifying playlist and movie keys to organize your media library.

Instructions

Add a movie to an existing playlist.

Parameters: playlist_key: The key of the playlist. movie_key: The key of the movie to add.

Returns: A success message if the movie is added, or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_keyYes
movie_keyYes

Implementation Reference

  • The core implementation of the 'add_to_playlist' tool. This async function, decorated with @mcp.tool(), handles adding a movie to a playlist using the Plex API. It includes input validation, playlist and movie lookup, and error handling.
    @mcp.tool()
    async def add_to_playlist(playlist_key: str, movie_key: str) -> str:
        """
        Add a movie to an existing playlist.
        
        Parameters:
            playlist_key: The key of the playlist.
            movie_key: The key of the movie to add.
            
        Returns:
            A success message if the movie is added, 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:
            p_key = int(playlist_key)
            m_key = int(movie_key)
    
            # Find the playlist
            all_playlists = await asyncio.to_thread(plex.playlists)
            playlist = next((p for p in all_playlists if p.ratingKey == p_key), None)
            if not playlist:
                return f"No playlist found with key {playlist_key}."
    
            # Perform a global search for the movie
            movies = await asyncio.to_thread(lambda: plex.library.search(libtype="movie", ratingKey=m_key))
            if not movies:
                return f"No movie found with key {movie_key}."
    
            movie = movies[0]  # Since the search is scoped to the ratingKey, there should be at most one result
    
            # Add the movie to the playlist
            await asyncio.to_thread(lambda p=playlist, m=movie: p.addItems([m]))
            logger.info("Added movie '%s' to playlist '%s'", movie.title, playlist.title)
            return f"Successfully added '{movie.title}' to playlist '{playlist.title}'."
        except ValueError:
            return "ERROR: Invalid playlist or movie key. Please provide valid numbers."
        except Exception as e:
            logger.exception("Failed to add movie to playlist")
            return f"ERROR: Failed to add movie to playlist. {str(e)}"
  • Package __init__.py re-exports the add_to_playlist function, making it available when importing from the plex_mcp package.
    from .plex_mcp import (
        search_movies,
        get_movie_details,
        list_playlists,
        get_playlist_items,
        create_playlist,
        delete_playlist,
        add_to_playlist,
        recent_movies,
        get_movie_genres,
        get_plex_server,
        MovieSearchParams,
    )
    
    __all__ = [
        "search_movies",
        "get_movie_details",
        "list_playlists",
        "get_playlist_items",
        "create_playlist",
        "delete_playlist",
        "add_to_playlist",
        "recent_movies",
        "get_movie_genres",
        "get_plex_server",
        "MovieSearchParams",
    ]
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral disclosure. It states the tool adds a movie and mentions success/error messages, but doesn't address permissions, rate limits, whether duplicates are allowed, or what happens if the playlist/movie doesn't exist. For a mutation tool with zero annotation coverage, this is inadequate.

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 with clear sections (purpose, parameters, returns). The first sentence states the core function, followed by structured details. No wasted words, though the 'Returns' section could be more specific.

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?

For a mutation tool with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It covers basic purpose and parameters but lacks crucial context about error conditions, prerequisites, behavioral details, and relationships with sibling tools.

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

Parameters3/5

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

Schema description coverage is 0%, but the description explicitly lists both parameters with brief explanations ('key of the playlist', 'key of the movie'). This adds meaningful semantics beyond the bare schema, though it doesn't explain what constitutes a valid key format or where to obtain these keys.

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 ('Add a movie') and target resource ('to an existing playlist'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'create_playlist' or 'get_playlist_items' beyond the obvious functional difference.

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., playlist must exist), exclusions, or clarify relationships with sibling tools like 'create_playlist' or 'get_playlist_items'.

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