search_entities
Find Wikidata entities using text queries, filter by type (item/property), and control results with language codes and limits via the MCP Wikidata Server.
Instructions
Search for entities in Wikidata by text query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language code (default: en) | en |
| limit | No | Maximum number of results (default: 10, max: 50) | |
| query | Yes | Search term | |
| type | No | Entity type filter (item, property) |
Input Schema (JSON Schema)
{
"properties": {
"language": {
"default": "en",
"description": "Language code (default: en)",
"type": "string"
},
"limit": {
"default": 10,
"description": "Maximum number of results (default: 10, max: 50)",
"maximum": 50,
"type": "integer"
},
"query": {
"description": "Search term",
"type": "string"
},
"type": {
"description": "Entity type filter (item, property)",
"enum": [
"item",
"property"
],
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- mcp_wikidata/wikidata_client.py:46-75 (handler)Core handler function that executes the search_entities tool by querying Wikidata's wbsearchentities API endpoint, processing the response, and returning formatted entity results.async def search_entities( self, query: str, language: str = "en", limit: int = 10, type: Optional[str] = None ) -> Dict[str, Any]: params = { "action": "wbsearchentities", "search": query, "language": language, "limit": min(limit, self.config.max_results), "format": "json", } if type: params["type"] = type data = await self._make_request(self.config.wikibase_api_url, params) entities = [] for item in data.get("search", []): entities.append({ "id": item.get("id"), "label": item.get("label"), "description": item.get("description", ""), "url": f"https://www.wikidata.org/entity/{item.get('id')}" }) return {"entities": entities}
- mcp_wikidata/tools.py:18-46 (registration)Registers the search_entities tool with MCP framework, defining its name, description, and input schema for validation.Tool( name="search_entities", description="Search for entities in Wikidata by text query", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "Search term" }, "language": { "type": "string", "description": "Language code (default: en)", "default": "en" }, "limit": { "type": "integer", "description": "Maximum number of results (default: 10, max: 50)", "default": 10, "maximum": 50 }, "type": { "type": "string", "description": "Entity type filter (item, property)", "enum": ["item", "property"] } }, "required": ["query"] }
- mcp_wikidata/tools.py:21-46 (schema)Defines the input schema for the search_entities tool, specifying parameters like query (required), language, limit, and type with types, descriptions, defaults, and constraints.inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "Search term" }, "language": { "type": "string", "description": "Language code (default: en)", "default": "en" }, "limit": { "type": "integer", "description": "Maximum number of results (default: 10, max: 50)", "default": 10, "maximum": 50 }, "type": { "type": "string", "description": "Entity type filter (item, property)", "enum": ["item", "property"] } }, "required": ["query"] }
- mcp_wikidata/tools.py:167-169 (handler)MCP tool dispatcher/handler that receives tool calls and delegates search_entities execution to the WikidataClient instance.if name == "search_entities": result = await self.client.search_entities(**arguments) elif name == "get_entity":