Skip to main content
Glama
djbriane
by djbriane

get_playlist_items

Retrieve items from a specific Plex playlist by providing the playlist key to access and display its contents.

Instructions

Get the items in a specific playlist.

Parameters: playlist_key: The key of the playlist to retrieve items from.

Returns: A formatted string of playlist items or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_keyYes

Implementation Reference

  • The main handler function for the 'get_playlist_items' tool. It is decorated with @mcp.tool(), takes a playlist_key parameter, connects to the Plex server, fetches the playlist, retrieves its items, and formats them into a numbered list with title, year, and type. Handles errors like not found or connection issues.
    @mcp.tool()
    async def get_playlist_items(playlist_key: str) -> str:
        """
        Get the items in a specific playlist.
        
        Parameters:
            playlist_key: The key of the playlist to retrieve items from.
            
        Returns:
            A formatted string of playlist items 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}."
    
            items = playlist.items()
            if not items:
                return "No items found in this playlist."
    
            formatted_items = []
            for i, item in enumerate(items, 1):
                title = item.title
                year = getattr(item, 'year', '')
                type_str = item.type.capitalize()
                formatted_items.append(f"{i}. {title} ({year}) - {type_str}")
            return "\n".join(formatted_items)
        except NotFound:
            return f"ERROR: Playlist with key {playlist_key} not found."
        except Exception as e:
            logger.exception("Failed to fetch items for playlist key '%s'", playlist_key)
            return f"ERROR: Failed to fetch playlist items. {str(e)}"
  • The __init__.py file re-exports the get_playlist_items function (and others) making it available for import, which is part of the tool registration in the package structure.
    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",
    ]
  • Helper function get_plex_server used by get_playlist_items to obtain the PlexServer instance asynchronously.
    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
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves items and returns a formatted string or error, but lacks details on permissions, rate limits, pagination, or what the formatted string includes (e.g., item names, IDs). For a read operation without annotations, this is insufficient.

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, starting with the core purpose followed by parameter and return details. It avoids unnecessary fluff, though the structure could be slightly improved by integrating the parameter explanation more seamlessly rather than as a separate section.

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 simplicity (one parameter, no output schema, no annotations), the description is incomplete. It doesn't cover behavioral aspects like error conditions or output format details, and with no sibling differentiation, it falls short of providing full context for effective use by an AI agent.

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?

The description adds minimal semantics beyond the input schema, which has 0% description coverage. It explains that 'playlist_key' identifies the playlist to retrieve items from, but doesn't clarify the key's format (e.g., numeric ID, string name) or provide examples. With one parameter, the baseline is 4, but the lack of detail reduces it to 3.

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 tool's purpose with a specific verb ('Get') and resource ('items in a specific playlist'), making it easy to understand what it does. However, it doesn't explicitly differentiate from sibling tools like 'list_playlists' (which might list playlists themselves rather than items within one), leaving room for potential confusion.

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 siblings like 'list_playlists' for listing playlists or 'add_to_playlist' for modifying playlists, nor does it specify prerequisites such as needing an existing playlist key. This lack of context could lead to misuse.

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