Skip to content

Repository files navigation

Wikibase MCP

The Wikibase MCP (Model Context Protocol) provides standardized tools that allow large language models (LLMs) to explore and query a registered Wikibase programmatically. It is designed for agentic AI and AI workflows that need to search, inspect, and query a Wikibase without relying on hardcoded assumptions about its structure, identifiers, or content.

The Wikibase MCP service is available at https://wb-mcp.wmcloud.org/. Register a Wikibase there to receive an instance-specific MCP endpoint. The registration API can be explored at https://wb-mcp.wmcloud.org/docs.

For Wikidata, use the dedicated Wikidata MCP instead. Its MCP endpoint is https://wd-mcp.wmcloud.org/mcp.


Register a Wikibase

Open wb-mcp.wmcloud.org and provide:

  • a name and optional description;
  • its MediaWiki Action API endpoint, such as https://example.org/w/api.php;
  • its Wikibase Query Service endpoint, such as https://query.example.org/sparql.

The service returns a stable mcp_endpoint slug. For a returned value of example-wikibase, use:

  • MCP: https://wb-mcp.wmcloud.org/example-wikibase/mcp/
  • Interactive tool API: https://wb-mcp.wmcloud.org/example-wikibase/docs

You can also register through the API:

curl -X POST https://wb-mcp.wmcloud.org/wikibases \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Example Wikibase",
    "description": "An example structured knowledge base.",
    "action_api_endpoint": "https://example.org/w/api.php",
    "query_service_endpoint": "https://query.example.org/sparql"
  }'

🧰 Tools

  1. get_wikibase_info() -> str Returns the registered Wikibase name and description.

    Use When: Starting work with an instance, to confirm its context.

  2. search_items(query: str, lang: str = "en") -> str Searches Wikibase items (QIDs) using its Action API. Returns matching QIDs with labels and descriptions.

    Use When: Starting exploration from a concept or natural-language description.

  3. search_properties(query: str, lang: str = "en") -> str Searches Wikibase properties (PIDs) using its Action API. Returns matching PIDs with labels and descriptions.

    Use When: Finding the property that represents a relationship for a statement or SPARQL query.

  4. get_statements(entity_id: str, include_external_ids: bool = False, lang: str = "en") -> str Returns direct statements for an entity in triplet-like text form. It excludes qualifiers, references, and deprecated values.

    Use When: Getting a fast structural overview of an entity.

  5. get_statement_values(entity_id: str, property_id: str, lang: str = "en") -> str Returns all statement values for an entity-property pair, including qualifiers, references, and all ranks.

    Use When: Full statement detail is needed for auditing, fact-checking, or provenance-sensitive tasks.

  6. get_property_hierarchy(entity_id: str, property_id: str, max_depth: int = 5, lang: str = "en") -> str Retrieves a JSON-formatted hierarchy by traversing a specified Wikibase property.

    Use When: Validating a relationship path before using it in SPARQL.

  7. execute_sparql(sparql: str, K: int = 10) -> str Executes a SPARQL query against the registered Wikibase Query Service and returns up to K rows as CSV text.

    Use When: Structured retrieval and verification are needed.


🚀 Running locally

Set the database environment variables in .env, then run:

uv run python main.py

Then open:

  • http://localhost:8000/ to register and manage Wikibases;
  • http://localhost:8000/docs for the registration API;
  • http://localhost:8000/<mcp_endpoint>/docs to test an instance's tools;
  • http://localhost:8000/<mcp_endpoint>/mcp/ to connect an MCP client.

With Docker:

docker compose up --build

🌐 Services

Each registration supplies the Wikibase Action API and Query Service that its tools use. Statement and hierarchy responses are rendered through the configurable Textifier service, which defaults to wd-textify.wmcloud.org.

About

An MCP server for Wikibase instances.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages