get_languages
Retrieve all available languages from the IMDb database to support content localization and language filtering for movies and TV shows.
Instructions
Get all languages. Returns: JSON object containing all languages.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/imdb_mcp_server/tools.py:186-196 (handler)The handler function implementing the 'get_languages' tool logic. It makes an API request to fetch all spoken languages from IMDb and returns them as formatted JSON.@mcp.tool() async def get_languages(ctx: Context) -> str: """Get all languages. Returns: JSON object containing all languages. """ languages_url = f"{BASE_URL}/languages" languages_data = await make_imdb_request(languages_url, {}, ctx) if not languages_data: return "Unable to fetch languages data." return json.dumps(languages_data, indent=4)
- src/imdb_mcp_server/main.py:22-24 (registration)The call to register_tools(server) which registers the get_languages tool (among others) with the MCP server instance.# Register all tools with the server register_tools(server)
- src/imdb_mcp_server/api.py:14-56 (helper)The helper function make_imdb_request used by get_languages to perform the actual API call to IMDb with caching 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}")