Skip to main content

MCP Wikidata Server

Project description

Wikidata MCP Server

smithery badge

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.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mseep_mcp_wikidata-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mseep_mcp_wikidata-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file mseep_mcp_wikidata-0.1.1.tar.gz.

File metadata

  • Download URL: mseep_mcp_wikidata-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for mseep_mcp_wikidata-0.1.1.tar.gz
Algorithm Hash digest
SHA256 09732b430b43d9694b0198321cbd9c27700b1fec03d41ea29ba60eb6bd09369a
MD5 c4119c2ae8f22eaa4295a2b30777c53c
BLAKE2b-256 3c8a575bcd768735e58877a05f18175f02dd15f838b94e4b0dbbe21ea9e6e388

See more details on using hashes here.

File details

Details for the file mseep_mcp_wikidata-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mseep_mcp_wikidata-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c95460813edafb6360993f1403d4c2f14276d518e4089a369eb0c3ac8c56d04b
MD5 564ad2d0fad7999f366bed2fff50f74f
BLAKE2b-256 25bddb29f1221c719110438cbb6d5b96285acf473d1d4e2a7716b8588cf39a59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page