get_game_details
Retrieve detailed video game information from IGDB, including ratings, platforms, genres, release dates, and developer details using a game ID.
Instructions
Retrieve detailed information about a specific game from IGDB
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| game_id | Yes | The IGDB ID of the game | |
| fields | No | Comma-separated list of fields to return | id,slug,name,rating,rating_count,hypes,first_release_date,platforms.name,genres.name,status,cover.url,summary,involved_companies.company.name,involved_companies.developer,involved_companies.publisher |
Implementation Reference
- src/igdb_mcp_server/server.py:192-219 (handler)The handler function for the 'get_game_details' tool. It retrieves detailed game information from IGDB by constructing an Apicalypse query with the given game_id and fields, using the IGDBClient, and returns the game data or raises an error if not found.async def get_game_details( game_id: Annotated[int, Field(description="The IGDB ID of the game")], ctx: Context, fields: Annotated[ Optional[str], Field(description="Comma-separated list of fields to return"), ] = "id,slug,name,rating,rating_count,hypes,first_release_date,platforms.name,genres.name,status,cover.url,summary,involved_companies.company.name,involved_companies.developer,involved_companies.publisher", ) -> Dict[str, Any]: """ Get detailed information about a specific game. Args: game_id: The IGDB ID of the game ctx: Context for accessing session configuration fields: Comma-separated list of fields to return (default: all fields) Returns: Detailed information about the game """ igdb_client = get_igdb_client(ctx) query = f"fields {fields}; where id = {game_id};" results = await igdb_client.make_request("games", query) if not results: raise ValueError(f"No game found with ID {game_id}") return results[0]
- src/igdb_mcp_server/server.py:187-191 (registration)The MCP decorator that registers the 'get_game_details' tool, specifying its name, title, and description.@mcp.tool( name="get_game_details", title="Get Game Details", description="Retrieve detailed information about a specific game from IGDB" )
- Helper function to obtain the IGDBClient instance, handling authentication credentials from env vars or context, used by the tool to make API requests.def get_igdb_client(ctx: Optional[Context] = None) -> IGDBClient: """Get or create the IGDB client singleton.""" global _igdb_client if "_igdb_client" not in globals(): # Get credentials from environment variables or Smithery settings # Check if context has session_config (Smithery mode) settings = getattr(ctx, 'session_config', None) if ctx else None client_id = os.getenv("IGDB_CLIENT_ID") or (settings.IGDB_CLIENT_ID if settings else None) client_secret = os.getenv("IGDB_CLIENT_SECRET") or (settings.IGDB_CLIENT_SECRET if settings else None) if not client_id or not client_secret: raise ValueError( "Please set IGDB_CLIENT_ID and IGDB_CLIENT_SECRET. " "You can either set them as environment variables or configure them in Smithery. " "You can obtain these from https://api-docs.igdb.com/#account-creation" ) _igdb_client = IGDBClient(client_id, client_secret) return _igdb_client
- src/igdb_mcp_server/server.py:69-128 (helper)The IGDBClient class provides the core API interaction methods, including OAuth token management and making Apicalypse queries to IGDB endpoints, used by get_game_details via get_igdb_client.class IGDBClient: """Client for interacting with the IGDB API.""" def __init__(self, client_id: str, client_secret: str): self.client_id = client_id self.client_secret = client_secret self.http_client = httpx.AsyncClient() async def get_access_token(self) -> str: """Get or refresh the OAuth access token.""" # Check if we have a valid cached token if token_cache["access_token"] and token_cache["expires_at"]: if datetime.now() < token_cache["expires_at"]: return token_cache["access_token"] # Get a new token from Twitch OAuth response = await self.http_client.post( TWITCH_AUTH_URL, params={ "client_id": self.client_id, "client_secret": self.client_secret, "grant_type": "client_credentials", }, ) response.raise_for_status() data = response.json() token_cache["access_token"] = data["access_token"] # Set expiry slightly before actual expiry for safety token_cache["expires_at"] = datetime.now() + timedelta( seconds=data["expires_in"] - 300 ) return data["access_token"] async def make_request(self, endpoint: str, query: str) -> List[Dict[str, Any]]: """Make a request to the IGDB API.""" token = await self.get_access_token() response = await self.http_client.post( f"{IGDB_BASE_URL}/{endpoint}", headers={ "Client-ID": self.client_id, "Authorization": f"Bearer {token}", "Accept": "application/json", }, content=query, timeout=30.0, ) response.raise_for_status() data = response.json() if isinstance(data, list): return data return [data] async def close(self): """Close the HTTP client.""" await self.http_client.aclose()