Query Wikidata Knowledge Graph via SPARQL
Wikidata SPARQL MCP Server runs SPARQL queries against Wikidata's knowledge graph via a single unified tool on Cloudflare Workers.
1.0.0Add to Favorites
Why it matters
Access and query the vast Wikidata knowledge graph using SPARQL. This asset enables complex data retrieval and analysis from one of the world's largest open knowledge bases.
Outcomes
What it gets done
Execute SPARQL queries against Wikidata.
Retrieve data in multiple formats (JSON, XML, Turtle, CSV).
Deploy globally on Cloudflare Workers for high availability.
Handle query timeouts and network resilience.
Source
Get it from source
Spark does not host a copy of it.
Open sourceReports
Agent outcome reports
No reports yet
Capabilities
Tools your agent gets
Execute SPARQL queries against the Wikidata knowledge graph with multiple output formats.
Overview
Wikidata SPARQL MCP Server
Wikidata SPARQL MCP Server exposes a single sparql_query tool that runs introspection and data queries against Wikidata's knowledge graph, deployed on Cloudflare Workers with SSE and HTTP transport. Use it when a question needs structured facts from Wikidata expressed as SPARQL, such as research, geography, or fact-checking queries.
What it does
Wikidata SPARQL MCP Server gives an AI assistant access to the Wikidata knowledge graph through SPARQL queries, running as a remote MCP server on Cloudflare Workers. It exposes a single unified tool, sparql_query, that handles both introspection (discovering what properties or structure exist for an entity) and data retrieval (running actual SPARQL SELECT, ASK, or DESCRIBE queries) against Wikidata's public endpoint, returning results in JSON, XML, Turtle, or CSV format.
When to use - and when NOT to
Use this when a question needs structured facts from Wikidata - finding Nobel Prize winners by year, countries and their capitals, software companies founded after a given date, or checking a boolean fact like whether a specific entity exists - expressed as a SPARQL query rather than free-text search. It requires the caller to construct valid SPARQL, so it suits users or agents comfortable writing or generating SPARQL, and it is not a natural-language question-answering layer on top of Wikidata by itself, though the tool's introspection mode helps discover available properties before writing a data query.
Inputs and outputs
sparql_query takes a required query string (the SPARQL query itself), an optional format (json default, xml, turtle, or csv), and an optional timeout in seconds (1-60, default 30) to bound how long a query can run. Example query patterns cover introspection (DESCRIBE wd:Q5, listing all properties available for humans), data retrieval (selecting scientists by birth date, or programming languages and their creators), and boolean checks (ASK queries testing whether a relationship or entity exists).
Integrations
Deployed to Cloudflare Workers either via the one-click "Deploy to Workers" button, or manually by cloning the repository and running npm install followed by npm run deploy, producing a URL like wikidata-sparql-mcp-server.<account>.workers.dev. It supports both SSE and standard HTTP transport for remote MCP clients, configured in Claude Desktop by pointing mcp-remote at the deployed /sse endpoint, and it can also be tested directly through the Cloudflare AI Playground by entering the deployed server URL. The architecture runs on Cloudflare Workers with Durable Objects, using the MCP SDK with Cloudflare Agents for the transport layer. The project is released under the MIT License.
Who it's for
Researchers, developers, and analysts who want an AI assistant to query Wikidata's structured knowledge graph directly via SPARQL - for research, geography, technology history, or general fact-checking - without leaving the conversation to run queries elsewhere.
npm install
npm run deploy
Source README
Wikidata SPARQL MCP Server
A Model Context Protocol (MCP) server providing access to the Wikidata knowledge graph via SPARQL queries. This server runs on Cloudflare Workers and supports both Server-Sent Events (SSE) and standard HTTP transport for remote MCP deployments.
Features
- Single Unified Tool: One powerful
sparql_querytool that handles both introspection and data queries - Comprehensive SPARQL Support: Execute any SPARQL query against Wikidata's knowledge graph
- Multiple Output Formats: JSON, XML, Turtle, and CSV result formats
- Timeout Protection: Configurable query timeouts (1-60 seconds) to prevent runaway queries
- Remote Deployment: Deployed on Cloudflare Workers for global accessibility
- Dual Transport Support: Both SSE and HTTP endpoints for maximum compatibility
Quick Start
Deploy to Cloudflare Workers
This will deploy your MCP server to a URL like: wikidata-sparql-mcp-server.<your-account>.workers.dev/sse
Alternatively, clone and deploy manually:
git clone https://github.com/QuentinCody/wikidata-sparql-mcp-server.git
cd wikidata-sparql-mcp-server
npm install
npm run deploy
Local Development
npm install
npm start # Runs on http://localhost:8787
MCP Tool Reference
sparql_query
Execute SPARQL queries against the Wikidata knowledge graph with support for both introspection and data retrieval.
Parameters:
query(string, required): The SPARQL query to executeformat(enum, optional): Output format - "json" (default), "xml", "turtle", or "csv"timeout(number, optional): Query timeout in seconds (1-60, default: 30)
Example Queries:
Introspection Examples
# Describe what a human is in Wikidata
DESCRIBE wd:Q5
# Get all properties available for humans
SELECT DISTINCT ?property ?propertyLabel WHERE {
wd:Q5 ?property ?value .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
Data Query Examples
# Get 10 famous scientists
SELECT ?scientist ?scientistLabel ?birthDate WHERE {
?scientist wdt:P31 wd:Q5 ; # instance of human
wdt:P106 wd:Q901 ; # occupation: scientist
wdt:P569 ?birthDate . # birth date
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?birthDate
LIMIT 10
# Find all programming languages and their creators
SELECT ?language ?languageLabel ?creator ?creatorLabel WHERE {
?language wdt:P31 wd:Q9143 ; # instance of programming language
wdt:P178 ?creator . # developer
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
LIMIT 20
Boolean Check Examples
# Check if humans are living beings
ASK { wd:Q5 wdt:P279 wd:Q35120 }
# Check if a specific person exists
ASK { wd:Q937 ?p ?o } # Albert Einstein
Client Configuration
Claude Desktop
Add this configuration to Claude Desktop's MCP settings:
{
"mcpServers": {
"wikidata-sparql": {
"command": "npx",
"args": [
"mcp-remote",
"https://wikidata-sparql-mcp-server.<your-account>.workers.dev/sse"
]
}
}
}
Cloudflare AI Playground
- Go to https://playground.ai.cloudflare.com/
- Enter your deployed server URL:
wikidata-sparql-mcp-server.<your-account>.workers.dev/sse - Start querying the Wikidata knowledge graph!
Generic MCP Client
For any MCP client supporting HTTP/SSE transport:
- SSE Endpoint:
https://your-domain.workers.dev/sse - HTTP Endpoint:
https://your-domain.workers.dev/mcp
SPARQL Query Examples by Use Case
Research & Academia
# Find Nobel Prize winners in Physics
SELECT ?winner ?winnerLabel ?year WHERE {
?award wdt:P31 wd:Q7191 ; # Nobel Prize in Physics
wdt:P585 ?year ; # point in time
wdt:P1346 ?winner . # winner
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY DESC(?year)
LIMIT 10
Geography & Demographics
# Countries and their capitals
SELECT ?country ?countryLabel ?capital ?capitalLabel WHERE {
?country wdt:P31 wd:Q3624078 ; # sovereign state
wdt:P36 ?capital . # capital
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
LIMIT 50
Technology & Innovation
# Software companies founded after 2000
SELECT ?company ?companyLabel ?founded WHERE {
?company wdt:P31 wd:Q936518 ; # software company
wdt:P571 ?founded . # inception
FILTER(YEAR(?founded) > 2000)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY DESC(?founded)
LIMIT 20
Error Handling
The server provides comprehensive error handling:
- Timeout Protection: Queries exceeding the timeout limit are automatically aborted
- SPARQL Validation: Invalid queries return descriptive error messages
- Network Resilience: Handles Wikidata endpoint unavailability gracefully
- Format Validation: Ensures output format compatibility
Architecture
- Base: Cloudflare Workers with Durable Objects
- MCP Framework: Model Context Protocol SDK with Cloudflare Agents
- Transport: SSE (Server-Sent Events) and HTTP support
- Query Engine: Direct integration with Wikidata's SPARQL endpoint
Related Resources
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.