Skip to main content
Glama

Wikidata MCP

TypeScript License: MIT

Model Context Protocol (MCP) server for local Wikidata Truthy knowledge grounding, entity resolution, and Executive Intelligence Brief (EIB) enrichment.

Designed as an MCP companion to the MacronX OSINT pipeline and the self-hosted local-wikidata QLever instance (~2.93B best-rank triples on localhost:7001/sparql).


What It Does

wikidata-mcp transitions the manual, prompt-heavy wikidata-brief-enrich skill into a fast, deterministic, batch-oriented knowledge graph server:

  • Single-Shot Brief Grounding (ground_entities): Resolves all named entity mentions in an article or SITREP, retrieves curated outbound triples, discovers direct and shared connections (alliances, conflicts, water bodies), and pulls inbound rosters in a single composite call.

  • Layered Deterministic Disambiguation (resolve_entities): Matches exact labels, short names (P1813), and official names (P1448), filters against curated P31 domain class presets and 1-hop P279 subclasses, filters Wikimedia noise (disambiguation pages, taxa, scholarly articles, songs), and computes disambiguation fingerprints (head of state, inception, HQ, country) to resolve homonyms deterministically without LLM hallucination.

  • Batched Label Hydration & @en/@mul Deduplication: Structural graph queries never join multiple OPTIONAL { ?x rdfs:label ?label } clauses inline. A dedicated LabelHydrator batch-resolves QIDs into clean English labels with an in-memory TTL cache, prioritizing @en over @mul and eliminating row duplication.

  • Sports & Entertainment Hub Filtering: Strips recurring athletic tournaments, curling championships, and cups when discovering shared P710 conflict/event hubs so sovereign states and leaders cross-reference only geopolitical summits, treaties, and conflicts.

  • Guarded SPARQL Escape Hatch (query_sparql): Allows agents to run custom read-only SELECT/ASK queries with auto-injected standard prefixes (wd:, wdt:, rdfs:, xsd:), enforced row limits (max 500), and automated QID/PID label hydration.

  • Editorial Prompts & Schema Resources: Includes MCP prompts (enrich_brief, verify_claims, extract_and_ground_entities) and resources (wikidata://schema/predicates, wikidata://schema/domains, wikidata://entities/{qid}) that instruct any connected agent to produce MacronX-compliant flat-bullet executive briefs with inline `QID` tags and ▸ Wikidata grounding: lines.


Related MCP server: utopia-mcp

Installation & Build

cd /Users/leonid/src/wikidata-mcp
npm install
npm run build
npm test

Environment Configuration

Variable

Required

Default

Description

WIKIDATA_SPARQL_URL

No

http://localhost:7001/sparql

URL of the local QLever SPARQL endpoint (e.g. http://localhost:7001/sparql or Tailscale host http://100.96.219.81:7001/sparql).

WIKIDATA_TIMEOUT_MS

No

30000

Per-query HTTP timeout in milliseconds.

WIKIDATA_ALLOW_RAW_SPARQL

No

true

When false or 0, disables the query_sparql escape hatch tool.

WIKIDATA_CACHE_TTL_MS

No

300000

In-memory label cache TTL in milliseconds (5 minutes). Set to 0 to disable caching.


MCP Client Configuration

1. Antigravity IDE / Claude Desktop / Cursor

Add to your mcpServers configuration:

{
  "mcpServers": {
    "wikidata": {
      "command": "node",
      "args": ["/Users/leonid/src/wikidata-mcp/dist/index.js"],
      "env": {
        "WIKIDATA_SPARQL_URL": "http://100.96.219.81:7001/sparql"
      }
    }
  }
}

2. Claude Code CLI

claude mcp add wikidata \
  -e WIKIDATA_SPARQL_URL=http://100.96.219.81:7001/sparql \
  -- node /Users/leonid/src/wikidata-mcp/dist/index.js

3. OpenCode (opencode.json)

{
  "mcp": {
    "wikidata": {
      "command": "node",
      "args": ["/Users/leonid/src/wikidata-mcp/dist/index.js"],
      "env": {
        "WIKIDATA_SPARQL_URL": "http://100.96.219.81:7001/sparql"
      }
    }
  }
}

MCP Surface Reference

Tools (7 Domain Tools)

  • check_health: Verifies connectivity to the local QLever SPARQL endpoint and reports total indexed triples (~2.93B) and query latency.

  • ground_entities: Single composite tool for brief enrichment: resolves a batch of entity mentions, retrieves curated outbound triples, discovers direct links and shared alliances/conflicts, and pulls inbound rosters.

  • resolve_entities: Resolves free-text mentions to Wikidata QIDs using label matching (rdfs:label, P1813, P1448), domain class filtering (country, person, company, conflict, geographic_feature, infrastructure, military, organization, etc.), and disambiguation fingerprints.

  • get_entity_triples: Retrieves curated outbound triples for one or more entity QIDs with human-readable property and object labels (covering 48 OSINT predicates across all MacronX sectors).

  • find_cross_links: Identifies direct edges (A -> P -> B) and shared group/conflict hubs between a set of resolved entities while filtering out sports and entertainment competitions.

  • get_inbound_relations: Retrieves inbound rosters (e.g. member countries via P463, conflict participants via P710, basin countries via P205) with accurate total counts and truncation flags.

  • query_sparql: Executes arbitrary read-only SPARQL SELECT or ASK queries with auto-injected prefixes, row limit clamping (max 500), and automated QID/PID label annotation.

Resources (wikidata://)

  • wikidata://schema/predicates — JSON catalog of all 48 default OSINT predicates and the ~200-property static English label dictionary.

  • wikidata://schema/domains — JSON catalog of supported domain presets and their mapped root Wikidata class QIDs.

  • wikidata://guidelines/brief-enrichment — Full editorial guidelines and formatting rules for grounding executive intelligence briefs.

  • wikidata://entities/{qid} — Live outbound triple profile for any Wikidata entity QID.

Guided Workflow Prompts

  • enrich_brief (brief_text, eib_flat_bullets) — Guides the agent through extracting mentions, calling ground_entities, preserving wording verbatim, tagging first mentions inline (Russia `Q159` ), and placing ▸ Wikidata grounding: lines following MacronX flat-bullet rules.

  • extract_and_ground_entities (text) — Generates a structured knowledge catalog (entities, outbound triples, cross-links, unmapped items) from a source document.

  • verify_claims (claims_text) — Fact-checks specific claims (memberships, alliances, borders, leadership, ownership) against the local Wikidata knowledge store.


Development & Testing

# Typecheck
npm run typecheck

# Run unit and end-to-end test suite (vitest)
npm test

# Build production bundles (tsup)
npm run build

License

MIT © 2026 Leonid Medovyy leonid@macron1.io

Available Tools

7 tools
check_healthA

Verify connectivity to the local QLever Wikidata Truthy SPARQL endpoint and return the total indexed triple count and query latency.

Inputs: no named parameters.

get_entity_triplesB

Retrieve curated outbound Wikidata triples for one or more entity QIDs. Returns grouped, deduplicated facts with human-readable predicate and object labels.

Inputs: qids (required), predicates, include_unwhitelisted, max_values_per_predicate.

get_inbound_relationsA

Retrieve inbound relations for target entities (e.g. alliance members via P463, conflict participants via P710, basin countries via P205, corporate owners via P127). Includes accurate total counts and truncation flags.

Inputs: target_qids (required), predicates, subject_domain, limit_per_relation, +2 more.

ground_entitiesB

Single composite tool to ground a brief: resolves all mentions to Wikidata QIDs, retrieves curated outbound triples, discovers inter-entity cross-links and shared hubs, and retrieves key inbound rosters.

Inputs: entities (required), predicates.

query_sparqlA

Execute an arbitrary read-only SPARQL SELECT or ASK query against the local QLever Wikidata endpoint. Auto-declares standard prefixes (wd:, wdt:, rdfs:, xsd:) and enforces query limits.

Inputs: query (required), limit, hydrate_labels.

resolve_entitiesB

Resolve a batch of named entity mentions to Wikidata QIDs using deterministic label matching, domain P31/P279 class filtering, homonym scoring, and disambiguation fingerprints.

Inputs: entities (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 7 tools

    Disambiguation4/5

    Most tools clearly target distinct actions or resource views, but ground_entities is a composite that deliberately overlaps resolve_entities, get_entity_triples, find_cross_links, and get_inbound_relations. That overlap is explicitly described, though an agent still has to decide between the composite and granular tools.

    Naming Consistency5/5

    All seven tools use snake_case with a predictable verb_noun or verb-object pattern (check_health, resolve_entities, get_entity_triples, query_sparql). The conventions are consistent throughout the set.

    Tool Count5/5

    Seven tools is well within the appropriate range for a focused Wikidata access server and each tool covers a meaningful operation. The composite ground_entities adds redundancy, but the overall count remains well-scoped rather than bloated.

    Completeness4/5

    The set covers the read-only research lifecycle well: health checking, entity resolution, outbound facts, inbound relations, cross-links, composite grounding, and arbitrary SPARQL. Minor gaps such as dedicated property/class metadata lookup or explicit pagination are largely mitigated by query_sparql and truncation flags.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables MCP-compatible clients to search and query a team knowledge graph, retrieve document context, upload files for indexing, explore entities and connections, and monitor workspace usage and server health.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables agents to query a single-source ontology of types, entities, statements, evidence, and controlled vocabulary, including bitemporal "as of" and "as recorded" fact lookups. Supports writing by letting agents propose candidate statements while keeping approval, review transitions, and authoritative reasoning restricted to approved facts.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables agents to perform federated cited search and heuristic grounding across a governed versioned wiki and indexed files, inspect citation spans, and read or write scoped knowledge through HTTP or stdio MCP.
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables LLM hosts to query the WikiPathways and AOP-Wiki SPARQL endpoints without guessing their vocabulary, by serving live schema cards, entity resolution, curated example queries, and guarded read-only query execution with repair advice. Each response reports the dataset's release version, date, and licence.
      5
      MIT