find_by_property
Search Wikidata entities using specific property values to retrieve relevant results, with options to filter by language and limit the number of outputs.
Instructions
Find entities by property and value
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language code (default: en) | en |
| limit | No | Maximum number of results | |
| property | Yes | Property ID (P123) | |
| value | Yes | Property value to search for |
Input Schema (JSON Schema)
{
"properties": {
"language": {
"default": "en",
"description": "Language code (default: en)",
"type": "string"
},
"limit": {
"default": 10,
"description": "Maximum number of results",
"maximum": 100,
"type": "integer"
},
"property": {
"description": "Property ID (P123)",
"type": "string"
},
"value": {
"description": "Property value to search for",
"type": "string"
}
},
"required": [
"property",
"value"
],
"type": "object"
}
Implementation Reference
- mcp_wikidata/wikidata_client.py:246-270 (handler)The core handler function implementing the find_by_property tool logic. Constructs a SPARQL query to find entities matching the given property and value, executes it via sparql_query, and formats the results.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:134-162 (registration)Registers the 'find_by_property' tool in get_tool_definitions, defining 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 (handler)MCP tool dispatcher in call_tool method that invokes the client handler for find_by_property.elif name == "find_by_property": result = await self.client.find_by_property(**arguments)
- mcp_wikidata/tools.py:137-161 (schema)Input schema definition for the find_by_property tool.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"] }