Query and Extract Data from Wikidata
Wikidata MCP Server lets AI assistants search entities and properties, run SPARQL queries, and fetch Wikidata metadata.
Why it matters
Leverage Wikidata's vast knowledge graph to retrieve entity information, property details, and execute complex SPARQL queries. This asset enables sophisticated data extraction and analysis for research and application development.
Outcomes
What it gets done
Search for Wikidata entity and property identifiers.
Retrieve metadata like English names and descriptions for entities.
Execute custom SPARQL queries against the Wikidata knowledge base.
Extract specific properties associated with given Wikidata entities.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-wikidata-mcp | bash Capabilities
Tools your agent gets
Search for an entity ID in Wikidata by query
Search for a property ID in Wikidata by query
Get properties associated with a specified entity ID in Wikidata
Execute a SPARQL query against Wikidata
Extract the English name and description for a specified entity ID in Wikidata
Overview
Wikidata MCP Server
An MCP server on top of the Wikidata API: search entity and property identifiers, retrieve properties, run SPARQL queries, and fetch entity metadata. Use it when an assistant needs precise, structured factual answers Wikidata can resolve - not general web search.
What it does
Wikidata MCP Server implements the Model Context Protocol on top of the Wikidata API, giving an AI assistant tools to search for entity and property identifiers, retrieve an entity's associated properties, execute SPARQL queries directly against Wikidata, and pull an entity's label and description. This lets a model chain together identifier lookups and a SPARQL query to answer factual questions grounded in Wikidata's structured knowledge graph. The project's own example walks through exactly this chain: asked for a movie directed by Bong Joon-ho, the model calls search_entity("Bong Joon-ho") to get entity ID Q495980, search_property("director") to get property ID P57, then runs a SPARQL query joining the two (?film wdt:P57 wd:Q495980) and gets back the film "Mother" - which it then presents as its recommendation.
When to use - and when NOT to
Use this when you want an assistant to answer questions that Wikidata's structured data can resolve precisely - for example, finding a film directed by a specific person by looking up the person's entity ID, the "director" property ID, and running a SPARQL query joining the two. It shines for structured factual lookups rather than general web search. It is not useful for information outside Wikidata's coverage, and writing a correct SPARQL query still requires the model (or the SPARQL execution) to get the property and entity IDs right first.
Capabilities
search_entity(query): searches for a Wikidata entity ID matching a query string.search_property(query): searches for a Wikidata property ID matching a query string.get_properties(entity_id): gets the properties associated with a given entity ID.execute_sparql(sparql_query): executes a SPARQL query against Wikidata.get_metadata(entity_id, language="en"): retrieves the label and description for an entity ID in a given language.
How to install
Install via Smithery for Claude Desktop:
npx -y @smithery/cli install @zzaebok/mcp-wikidata --client claude
Or install manually with uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/zzaebok/mcp-wikidata.git
cd mcp-wikidata
uv sync
Run the server with:
uv run src/server.py
A sample client (using langchain-mcp-adapters) is included and can be run with uv run src/client.py after syncing the example extra with uv sync --extra example.
Who it's for
Developers and researchers who want an AI assistant to answer structured factual questions by querying Wikidata directly - chaining entity and property lookups into a SPARQL query rather than relying on the model's own knowledge. The project is released under the MIT License.
Source README
Wikidata MCP Server
A server implementation for Wikidata API using the Model Context Protocol (MCP).
This project provides tools to interact with Wikidata, such as searching identifiers (entity and property), extracting metadata (label and description) and executing sparql query.
Installation
Installing via Smithery
To install Wikidata MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @zzaebok/mcp-wikidata --client claude
Installing Manually
Install uv if it is not installed yet.
$ curl -LsSf https://astral.sh/uv/install.sh | sh
Then, install dependencies.
$ git clone https://github.com/zzaebok/mcp-wikidata.git
$ cd mcp-wikidata
$ uv sync
# if you want to run client example together
$ uv sync --extra example
Run
Run the server with:
$ uv run src/server.py
If you want to test it with a simple client code (with langchain-mcp-adapters), run the client with:
# in another shell
$ uv run src/client.py
The LLM extracts valid entity and property identifiers, executes a sparql query, and finally recommend a movie directed by Bong Joon-ho.
See the execution output
{
"messages": [
HumanMessage(
content="Can you recommend me a movie directed by Bong Joonho?",
),
AIMessage(
tool_calls=[
{
"name": "search_entity",
"args": {"query": "Bong Joon-ho"},
}
],
),
ToolMessage(
content="Q495980",
name="search_entity",
),
AIMessage(
tool_calls=[
{
"name": "get_properties",
"args": {"entity_id": "Q495980"},
}
],
),
ToolMessage(
content='["P345", "P244", "P214", "P227", ...]',
name="get_properties",
),
AIMessage(
tool_calls=[
{
"name": "search_property",
"args": {"query": "director"},
}
],
),
ToolMessage(
content="P57",
name="search_property",
),
AIMessage(
tool_calls=[
{
"name": "execute_sparql",
"args": {
"sparql_query": 'SELECT ?film ?filmLabel WHERE {\n ?film wdt:P57 wd:Q495980.\n SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }\n} LIMIT 1'
},
}
],
),
ToolMessage(
content='[{"film": {"type": "uri", "value": "http://www.wikidata.org/entity/Q483761"}, "filmLabel": {"xml:lang": "en", "type": "literal", "value": "Mother"}}]',
name="execute_sparql",
),
AIMessage(
content='I recommend the movie "Mother," which was directed by Bong Joon-ho.',
),
]
}
Wikidata MCP Tools
The following tools are implemented in the server:
| Tool | Description |
|---|---|
search_entity(query: str) |
Search for a Wikidata entity ID by its query. |
search_property(query: str) |
Search for a Wikidata property ID by its query. |
get_properties(entity_id: str) |
Get the properties associated with a given Wikidata entity ID. |
execute_sparql(sparql_query: str) |
Execute a SPARQL query on Wikidata. |
get_metadata(entity_id: str, language: str = "en") |
Retrieve the English label and description for a given Wikidata entity ID. |
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.