Skip to main content
Glama
zzaebok

Wikidata MCP Server

by zzaebok

search_entity

Find Wikidata entity IDs by entering search queries to retrieve structured data identifiers for entities like people, places, and concepts.

Instructions

Search for a Wikidata entity ID by its query.

Args:
    query (str): The query to search for. The query should be unambiguous enough to uniquely identify the entity.

Returns:
    str: The Wikidata entity ID corresponding to the given query."

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The handler function for the 'search_entity' tool, decorated with @server.tool() for registration. It invokes the helper function search_wikidata to perform the Wikidata entity search.
    @server.tool()
    async def search_entity(query: str) -> str:
        """
        Search for a Wikidata entity ID by its query.
    
        Args:
            query (str): The query to search for. The query should be unambiguous enough to uniquely identify the entity.
    
        Returns:
            str: The Wikidata entity ID corresponding to the given query."
        """
        return await search_wikidata(query, is_entity=True)
  • Helper function that executes the HTTP request to Wikidata's search API to find entity or property IDs based on the query.
    async def search_wikidata(query: str, is_entity: bool = True) -> str:
        """
        Search for a Wikidata item or property ID by its query.
        """
        params = {
            "action": "query",
            "list": "search",
            "srsearch": query,
            "srnamespace": 0 if is_entity else 120,
            "srlimit": 1,  # TODO: add a parameter to limit the number of results?
            "srqiprofile": "classic_noboostlinks" if is_entity else "classic",
            "srwhat": "text",
            "format": "json",
        }
        async with httpx.AsyncClient() as client:
            response = await client.get(WIKIDATA_URL, headers=HEADER, params=params)
        response.raise_for_status()
        try:
            title = response.json()["query"]["search"][0]["title"]
            title = title.split(":")[-1]
            return title
        except KeyError:
            return "No results found. Consider changing the search term."
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns a Wikidata entity ID as a string, which is basic output information, but lacks details on error handling, rate limits, authentication needs, or what happens if no entity is found. For a search tool with zero annotation coverage, this is insufficient to inform safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the core purpose stated first, followed by structured sections for arguments and returns. Every sentence adds value, and there's no redundant information. It could be slightly more concise by integrating the sections more fluidly, but overall it's efficient and well-organized.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (a single-parameter search function) and the absence of annotations and output schema, the description is minimally adequate. It covers the basic purpose, parameter semantics, and return type, but lacks behavioral details like error cases or performance constraints. This makes it functional but incomplete for robust agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains that the 'query' parameter should be a string that is 'unambiguous enough to uniquely identify the entity,' providing context on how to formulate the query effectively. Since there's only one parameter, this compensates well for the schema's lack of documentation, though it could be more detailed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Search for a Wikidata entity ID by its query.' It specifies the verb ('Search'), resource ('Wikidata entity ID'), and mechanism ('by its query'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'search_property' or 'get_metadata', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions that the query should be 'unambiguous enough to uniquely identify the entity,' which hints at usage context but doesn't specify scenarios, prerequisites, or comparisons to siblings like 'search_property' or 'execute_sparql'. This leaves the agent without clear direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/zzaebok/mcp-wikidata'

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