get_playlist_items
Retrieve items from a Plex playlist using the playlist key. This tool outputs a formatted list of playlist items or an error message, simplifying media library management.
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
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_key | Yes |
Implementation Reference
- src/plex_mcp/plex_mcp.py:346-384 (handler)The handler function decorated with @mcp.tool() that implements the logic to retrieve and format items from a specific Plex playlist by its key.@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)}"