get_imdb_details
Retrieve comprehensive movie and TV series information from IMDb using the unique IMDb ID to access detailed data including cast, plot, ratings, and release information.
Instructions
Get more in depth details about a movie/series from IMDb. Args: imdbId: The IMDb ID of the movie/series to get details for. Returns: JSON object containing the movie/series details.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| imdb_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"imdb_id": {
"title": "Imdb Id",
"type": "string"
}
},
"required": [
"imdb_id"
],
"type": "object"
}
Implementation Reference
- src/imdb_mcp_server/tools.py:86-98 (handler)The core handler function for the 'get_imdb_details' tool. Decorated with @mcp.tool() which also handles registration. Fetches detailed information for an IMDb ID from the API and returns it as a formatted JSON string.@mcp.tool() async def get_imdb_details(imdb_id: str, ctx: Context) -> str: """Get more in depth details about a movie/series from IMDb. Args: imdbId: The IMDb ID of the movie/series to get details for. Returns: JSON object containing the movie/series details. """ imdb_details_url = f"{BASE_URL}/{imdb_id}" imdb_details_data = await make_imdb_request(imdb_details_url, {}, ctx) if not imdb_details_data: return "Unable to fetch imdb details data for this movie or movie not found." return json.dumps(imdb_details_data, indent=4)
- src/imdb_mcp_server/api.py:14-56 (helper)Key helper function called by the tool to execute HTTP requests to the IMDb API. Manages caching via cache_manager, retrieves API key from context or env, and handles requests with RapidAPI headers.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}")
- src/imdb_mcp_server/api.py:11-11 (helper)BASE_URL constant used to construct the API endpoint URL in the handler (f'{BASE_URL}/{imdb_id}').BASE_URL = "https://imdb236.p.rapidapi.com/api/imdb"
- src/imdb_mcp_server/main.py:22-23 (registration)Call to register_tools(server) which defines and registers all tools including 'get_imdb_details' via decorators inside the function.# Register all tools with the server register_tools(server)
- src/imdb_mcp_server/main.py:11-13 (schema)Pydantic configuration schema for the MCP server session, providing the required rapidApiKeyImdb used for authentication in API requests.class ConfigSchema(BaseModel): rapidApiKeyImdb: str = Field(..., description="RapidAPI API key for accessing the IMDb API")