get_movie_genres
Retrieve genre details for a specific movie by providing its unique key, using integration with the Plex Media Server API.
Instructions
Get genres for a specific movie.
Parameters: movie_key: The key of the movie.
Returns: A formatted string of movie genres or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| movie_key | Yes |
Implementation Reference
- src/plex_mcp/plex_mcp.py:559-594 (handler)The handler function for the 'get_movie_genres' tool. It is decorated with @mcp.tool(), fetches the Plex server, searches for the movie by key, extracts its genres, and returns a formatted string or error message.@mcp.tool() async def get_movie_genres(movie_key: str) -> str: """ Get genres for a specific movie. Parameters: movie_key: The key of the movie. Returns: A formatted string of movie genres 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(movie_key) # Perform a global search for the movie all_movies = await asyncio.to_thread(lambda: plex.library.search(libtype="movie")) movie = next((m for m in all_movies if m.ratingKey == key), None) if not movie: return f"No movie found with key {movie_key}." # Extract genres genres = [genre.tag for genre in movie.genres] if hasattr(movie, 'genres') else [] if not genres: return f"No genres found for movie '{movie.title}'." return f"Genres for '{movie.title}':\n{', '.join(genres)}" except ValueError: return f"ERROR: Invalid movie key '{movie_key}'. Please provide a valid number." except Exception as e: logger.exception("Failed to fetch genres for movie with key '%s'", movie_key) return f"ERROR: Failed to fetch movie genres. {str(e)}"