by zzaebok
mcp-wikidata is a server implementation for the Wikidata API using the Model Context Protocol (MCP), providing tools to interact with Wikidata for searching, extracting metadata, and executing SPARQL queries.
mcp-wikidata is a server implementation that allows interaction with the Wikidata API through the Model Context Protocol (MCP). It provides a set of tools to programmatically access and retrieve information from Wikidata, making it easier to integrate Wikidata's vast knowledge base into applications.
Via Smithery:
npx -y @smithery/cli install @zzaebok/mcp-wikidata --client claude
Manually:
uv
:$ curl -LsSf https://astral.sh/uv/install.sh | sh
$ 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
$ uv run src/server.py
# in another shell
$ uv run src/client.py
mcp-wikidata provides the following tools for interacting with Wikidata:
search_entity(query: str)
: Search for a Wikidata entity ID using a query string.search_property(query: str)
: Search for a Wikidata property ID using a query string.get_properties(entity_id: str)
: Retrieve all properties associated with a given Wikidata entity ID.execute_sparql(sparql_query: str)
: Execute a SPARQL query directly on Wikidata.get_metadata(entity_id: str, language: str = "en")
: Get the English label and description for a specified Wikidata entity ID.Q: What is the Model Context Protocol (MCP)? A: The Model Context Protocol (MCP) is a framework that allows models (like large language models) to interact with external tools and services. mcp-wikidata implements this protocol to enable seamless communication between AI models and the Wikidata API.
Q: Can I use mcp-wikidata with other AI frameworks?
A: While the example shows integration with langchain-mcp-adapters
, the underlying MCP design aims for broader compatibility, allowing integration with various AI frameworks that support external tool calls.
Q: What kind of queries can I perform with mcp-wikidata? A: You can perform entity and property searches, retrieve associated properties, and execute complex SPARQL queries, giving you extensive control over the data you retrieve from Wikidata.
Q: Is there a client example available?
A: Yes, a simple client example is provided (src/client.py
) that demonstrates how to use the tools to answer questions, such as recommending a movie directed by a specific person, by interacting with an LLM and Wikidata.
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.
To install Wikidata MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @zzaebok/mcp-wikidata --client claude
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 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.
{
"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.',
),
]
}
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. |
MIT License
Reviews feature coming soon
Stay tuned for community discussions and feedback