Skip to main content
Glama
Wikidata MCP Server

Wikidata MCP Server

by zzaebok

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.

{
  "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.


License

MIT License

Available Tools

5 tools
execute_sparqlA
Execute a SPARQL query on Wikidata.

You may assume the following prefixes:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>

Args:
    sparql_query (str): The SPARQL query to execute.

Returns:
    str: The JSON-formatted result of the SPARQL query execution. If there are no results, an empty JSON object will be returned.

Inputs: sparql_query (required).

get_metadataA
Retrieve the English label and description for a given Wikidata entity ID.

Args:
    entity_id (str): The entity ID to retrieve metadata for.
    language (str): The language code for the label and description (default is "en"). Use ISO 639-1 codes.

Returns:
    dict: A dictionary containing the label and description of the entity, if available.

Inputs: entity_id (required), language.

get_propertiesA
Get the properties associated with a given Wikidata entity ID.

Args:
    entity_id (str): The entity ID to retrieve properties for. This should be a valid Wikidata entity ID.

Returns:
    list: A list of property IDs associated with the given entity ID. If no properties are found, an empty list is returned.

Inputs: entity_id (required).

search_entityB
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."

Inputs: query (required).

search_propertyB
Search for a Wikidata property ID by its query.

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

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

Inputs: query (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap: execute_sparql runs queries, get_metadata retrieves labels/descriptions, get_properties lists properties, search_entity finds entities, and search_property finds properties. The descriptions reinforce these distinct roles, making misselection unlikely.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern (e.g., execute_sparql, get_metadata, search_entity) with clear, descriptive names. There are no deviations in style or convention, making the set predictable and easy to understand.

    Tool Count5/5

    With 5 tools, this server is well-scoped for interacting with Wikidata. Each tool serves a specific, necessary function (querying, metadata retrieval, property listing, and searching for entities/properties), and none feel redundant or out of place for the domain.

    Completeness4/5

    The toolset covers core Wikidata operations well, including querying, metadata access, and searching. A minor gap is the lack of update/create/delete tools, but this is reasonable for a read-focused Wikidata interface, and agents can still perform comprehensive queries and retrievals without dead ends.

    Maintenance

    ActivityNo data
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A Model Context Protocol server that retrieves information from Wikipedia to provide context to LLMs, allowing users to search articles, get summaries, full content, sections, and links from Wikipedia.
      22
      310
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Provides access to Wikidata for Large Language Models through the Model Context Protocol, offering tools for entity search, detailed retrieval, SPARQL queries, relation exploration, and property-based searches.
      5
      4
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A production-ready server that provides Wikipedia search and content retrieval tools through the Model Context Protocol, enabling AI assistants to search for articles, list sections, and retrieve specific content.
      -