Skip to main content
Glama

get_upcoming_releases

Retrieve upcoming movie and TV releases from IMDb for specific countries with pagination support to browse entertainment options.

Instructions

Get the upcoming releases from IMDb with pagination. Args: country_code: The country code to get the upcoming releases for. type: The type of the upcoming releases to get. Possible values: "TV", "MOVIE". start: The starting index (0-based) to retrieve releases from. Returns: JSON object containing 5 upcoming releases starting from the specified index.

Input Schema

NameRequiredDescriptionDefault
country_codeYes
typeYes
startYes

Input Schema (JSON Schema)

{ "properties": { "country_code": { "title": "Country Code", "type": "string" }, "start": { "title": "Start", "type": "integer" }, "type": { "title": "Type", "type": "string" } }, "required": [ "country_code", "type", "start" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'get_upcoming_releases' MCP tool. It fetches upcoming releases from the IMDb API based on country code and type, handles pagination, and returns formatted JSON. Registered via @mcp.tool() decorator.
    @mcp.tool() async def get_upcoming_releases(country_code: str, type: str, start: int, ctx: Context) -> str: """Get the upcoming releases from IMDb with pagination. Args: country_code: The country code to get the upcoming releases for. type: The type of the upcoming releases to get. Possible values: "TV", "MOVIE". start: The starting index (0-based) to retrieve releases from. Returns: JSON object containing 5 upcoming releases starting from the specified index. """ upcoming_releases_url = f"{BASE_URL}/upcoming-releases" upcoming_releases_data = await make_imdb_request(upcoming_releases_url, {"countryCode": country_code, "type": type}, ctx) if not upcoming_releases_data: return "Unable to fetch upcoming releases data." return json.dumps(paginated_response(upcoming_releases_data, start, len(upcoming_releases_data)), indent=4)
  • Core helper function used by get_upcoming_releases to make HTTP requests to the IMDb API, including authentication, caching via cache_manager, and error handling.
    async def make_imdb_request(url: str, querystring: dict[str, Any], ctx: Optional[Context] = None) -> Optional[Dict[str, Any]]: """Make a request to the IMDb API with proper error handling and caching.""" # Check if it's time to clean the cache cache_manager.cleanup_if_needed() # Create a cache key from the URL and querystring cache_key = f"{url}_{str(querystring)}" # Try to get from cache first cached_data = cache_manager.cache.get(cache_key) if cached_data: return cached_data # Get API key from session config or fallback to environment variable api_key = None if ctx and hasattr(ctx, 'session_config') and ctx.session_config: api_key = ctx.session_config.rapidApiKeyImdb if not api_key: api_key = os.getenv("RAPID_API_KEY_IMDB") # Not in cache, make the request headers = { "x-rapidapi-key": api_key, "x-rapidapi-host": "imdb236.p.rapidapi.com", } if not api_key: raise ValueError("API key not found. Please set the RAPID_API_KEY_IMDB environment variable or provide rapidApiKeyImdb in the request.") try: response = requests.get(url, headers=headers, params=querystring, timeout=30.0) response.raise_for_status() data = response.json() # Cache the response cache_manager.cache.set(cache_key, data) return data except Exception as e: raise ValueError(f"Unable to fetch data from IMDb. Please try again later. Error: {e}")
  • Helper function used by get_upcoming_releases to format the API response into a paginated JSON structure with fixed page size of 5 items.
    def paginated_response(items, start, total_count=None): """Format a paginated response with a fixed page size of 5.""" if total_count is None: total_count = len(items) # Validate starting index start = max(0, min(total_count - 1 if total_count > 0 else 0, start)) # Fixed page size of 5 page_size = 5 end = min(start + page_size, total_count) return { "items": items[start:end], "start": start, "count": end - start, "totalCount": total_count, "hasMore": end < total_count, "nextStart": end if end < total_count else None }
  • The call to register_tools(server) in the main server setup, which registers all tools including get_upcoming_releases via the decorators in tools.py.
    # Register all tools with the server register_tools(server)

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/uzaysozen/imdb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server