recent_movies
Retrieve a list of recently added movies from your Plex library by specifying the number of entries. Integrates with Plex Media Server API for streamlined library updates.
Instructions
Get recently added movies from the Plex library.
Parameters: count: The maximum number of recent movies to return.
Returns: A formatted string of recent movies or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No |
Implementation Reference
- src/plex_mcp/plex_mcp.py:522-558 (handler)The main asynchronous handler function for the 'recent_movies' tool. It is decorated with @mcp.tool() for automatic registration in FastMCP. Fetches recently added movies from the Plex library sorted by 'addedAt:desc', limits to the specified count, formats each using format_movie helper, and returns a delimited string or error message.@mcp.tool() async def recent_movies(count: int = 5) -> str: """ Get recently added movies from the Plex library. Parameters: count: The maximum number of recent movies to return. Returns: A formatted string of recent movies or an error message. """ if count <= 0: return "ERROR: Count must be a positive integer." try: plex = await get_plex_server() except Exception as e: return f"ERROR: Could not connect to Plex server. {str(e)}" try: # Perform a global search for recently added movies all_recent = await asyncio.to_thread(lambda: plex.library.search(libtype="movie", sort="addedAt:desc")) recent_movies_list = all_recent[:count] if not recent_movies_list: return "No recent movies found in your Plex library." formatted_movies = [] for i, movie in enumerate(recent_movies_list, 1): formatted_movies.append( f"Recent Movie #{i}:\nKey: {movie.ratingKey}\nAdded: {movie.addedAt.strftime('%Y-%m-%d')}\n{format_movie(movie)}" ) return "\n---\n".join(formatted_movies) except Exception as e: logger.exception("Failed to fetch recent movies") return f"ERROR: Failed to fetch recent movies. {str(e)}"