find_by_property
Search Wikidata entities using specific property-value pairs to locate relevant data entries based on defined criteria.
Instructions
Find entities by property and value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| property | Yes | Property ID (P123) | |
| value | Yes | Property value to search for | |
| language | No | Language code (default: en) | en |
| limit | No | Maximum number of results |
Implementation Reference
- mcp_wikidata/wikidata_client.py:246-270 (handler)The core handler function that implements the find_by_property tool logic by constructing and executing a SPARQL query to find Wikidata entities matching the specified property and value.async def find_by_property( self, property: str, value: str, language: str = "en", limit: int = 10 ) -> Dict[str, Any]: query = f""" SELECT ?item ?itemLabel WHERE {{ ?item wdt:{property} "{value}" . SERVICE wikibase:label {{ bd:serviceParam wikibase:language "{language}" . }} }} LIMIT {limit} """ result = await self.sparql_query(query) entities = [] for binding in result.get("results", {}).get("bindings", []): entities.append({ "id": binding.get("item", {}).get("value", "").split("/")[-1], "label": binding.get("itemLabel", {}).get("value", "") }) return {"entities": entities}
- mcp_wikidata/tools.py:137-161 (schema)The JSON schema defining the input parameters for the find_by_property tool, including property, value (required), language, and limit.inputSchema={ "type": "object", "properties": { "property": { "type": "string", "description": "Property ID (P123)" }, "value": { "type": "string", "description": "Property value to search for" }, "language": { "type": "string", "description": "Language code (default: en)", "default": "en" }, "limit": { "type": "integer", "description": "Maximum number of results", "default": 10, "maximum": 100 } }, "required": ["property", "value"] }
- mcp_wikidata/tools.py:134-162 (registration)Registers the find_by_property tool in the MCP tool definitions list, specifying its name, description, and input schema.Tool( name="find_by_property", description="Find entities by property and value", inputSchema={ "type": "object", "properties": { "property": { "type": "string", "description": "Property ID (P123)" }, "value": { "type": "string", "description": "Property value to search for" }, "language": { "type": "string", "description": "Language code (default: en)", "default": "en" }, "limit": { "type": "integer", "description": "Maximum number of results", "default": 10, "maximum": 100 } }, "required": ["property", "value"] } )
- mcp_wikidata/tools.py:175-176 (registration)Dispatches the tool call to the client handler in the WikidataTools.call_tool method.elif name == "find_by_property": result = await self.client.find_by_property(**arguments)