get_metadata
Retrieve English labels and descriptions for Wikidata entities using entity IDs. Specify language codes for multi-language support. Simplify metadata extraction from Wikidata.
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. It queries the Wikidata API to retrieve the label and description for a given entity ID in the specified language.@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}
- src/server.py:117-117 (registration)The @server.tool() decorator registers the get_metadata function as an MCP tool.@server.tool()
- src/server.py:119-128 (schema)The docstring and type hints define the input schema (entity_id: str, language: str='en') and output (Dict[str, str]) for the tool.""" 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. """