Skip to main content
Glama
joelgombin

MCP Wikidata Server

by joelgombin

search_entities

Find Wikidata entities by text query to retrieve structured data for items or properties using language-specific searches with configurable result limits.

Instructions

Search for entities in Wikidata by text query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch term
languageNoLanguage code (default: en)en
limitNoMaximum number of results (default: 10, max: 50)
typeNoEntity type filter (item, property)

Implementation Reference

  • Core handler function that performs the Wikidata entity search using the wbsearchentities API action, processes results into a structured format.
    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}
  • Registers the search_entities tool with MCP framework, including name, description, and input schema.
    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"]
        }
    ),
  • Defines the input schema for the search_entities tool, specifying parameters like query, language, limit, and type.
    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"]
    }
  • Dispatch handler in the MCP tools class that calls the WikidataClient's search_entities method with tool arguments.
    if name == "search_entities":
        result = await self.client.search_entities(**arguments)

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/joelgombin/mcp-wikidata'

If you have feedback or need assistance with the MCP directory API, please join our Discord server