get_metadata
Retrieve English labels and descriptions for Wikidata entities by providing their entity ID and optional language code.
Instructions
Retrieve the English label and description for a given Wikidata entity ID.
Args:
entity_id (str): The entity ID to retrieve metadata for.
language (str): The language code for the label and description (default is "en"). Use ISO 639-1 codes.
Returns:
dict: A dictionary containing the label and description of the entity, if available.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_id | Yes | ||
| language | No | en |
Implementation Reference
- src/server.py:117-149 (handler)The handler function for the 'get_metadata' tool, decorated with @server.tool() for registration. It fetches the label and description of a Wikidata entity using the Wikidata API.@server.tool() async def get_metadata(entity_id: str, language: str = "en") -> Dict[str, str]: """ Retrieve the English label and description for a given Wikidata entity ID. Args: entity_id (str): The entity ID to retrieve metadata for. language (str): The language code for the label and description (default is "en"). Use ISO 639-1 codes. Returns: dict: A dictionary containing the label and description of the entity, if available. """ params = { "action": "wbgetentities", "ids": entity_id, "props": "labels|descriptions", "languages": language, # specify the desired language "format": "json", } async with httpx.AsyncClient() as client: response = await client.get(WIKIDATA_URL, params=params) response.raise_for_status() data = response.json() entity_data = data.get("entities", {}).get(entity_id, {}) label = ( entity_data.get("labels", {}).get(language, {}).get("value", "No label found") ) descriptions = ( entity_data.get("descriptions", {}) .get(language, {}) .get("value", "No label found") ) return {"Label": label, "Descriptions": descriptions}