mcp-sparql
Provides tools for executing SPARQL queries (SELECT, ASK, CONSTRUCT, DESCRIBE) on Wikidata's SPARQL endpoint, enabling AI agents to retrieve structured data, validate queries, list graphs, and get common prefixes.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-sparql query Wikidata for cities in France"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-sparql — MCP server exposing SPARQL query functionalities for LLMs.
mcp-name: io.github.daedalus/mcp-sparql
Install
pip install mcp-sparqlRelated MCP server: RDF Explorer
Usage
As an MCP Server
Add to your MCP configuration (e.g., ~/.config/claude/mcp.json):
{
"mcpServers": {
"mcp-sparql": {
"command": "mcp-sparql"
}
}
}Available Tools
Tool | Description |
| Execute SPARQL SELECT queries (table or JSON output) |
| Execute SPARQL ASK queries (boolean result) |
| Execute SPARQL CONSTRUCT queries (Turtle or JSON-LD) |
| Execute SPARQL DESCRIBE queries (Turtle or JSON-LD) |
| Validate SPARQL query syntax without executing |
| List named graphs on a SPARQL endpoint |
| Get common prefixes for a SPARQL endpoint |
Examples
Query Wikidata:
sparql_query:
endpoint: "https://query.wikidata.org/sparql"
query: "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 . ?item rdfs:label ?itemLabel . FILTER(LANG(?itemLabel) = 'en') } LIMIT 5"Check if an entity exists:
sparql_ask:
endpoint: "https://query.wikidata.org/sparql"
query: "ASK { wd:Q42 wdt:P31 wd:Q5 }"Validate a query:
sparql_validate:
query: "SELECT ?s WHERE { ?s ?p ?o }"List named graphs:
sparql_list_graphs:
endpoint: "https://query.wikidata.org/sparql"Get common prefixes:
sparql_get_prefixes:
endpoint: "https://query.wikidata.org/sparql"Resources
Resource | URI | Description |
Common Prefixes |
| Standard SPARQL namespace prefixes |
API
sparql_query
Execute a SPARQL SELECT query.
Parameters:
endpoint(str): SPARQL endpoint URLquery(str): SPARQL SELECT querytimeout(int, default=30): Query timeout in secondsoutput_format(str, default="table"): "table" for Markdown, "json" for JSONheaders(dict, optional): HTTP headers for authenticationmax_rows(int, default=1000): Maximum result rows
sparql_ask
Execute a SPARQL ASK query. Returns "true" or "false".
sparql_construct
Execute a SPARQL CONSTRUCT query. Returns RDF triples.
Additional parameters:
output_format(str, default="turtle"): "turtle" or "json"
sparql_describe
Execute a SPARQL DESCRIBE query. Returns RDF description.
sparql_validate
Validate SPARQL query syntax without executing.
sparql_list_graphs
List available named graphs on a SPARQL endpoint.
sparql_get_prefixes
Get commonly used prefixes for a SPARQL endpoint.
Development
git clone https://github.com/daedalus/mcp-sparql.git
cd mcp-sparql
pip install -e ".[test]"
# run tests
pytest
# format
ruff format src/ tests/
# lint + type check
prospector --with-tool ruff --with-tool mypy --with-tool pylint src/Available Tools
7 toolssparql_askARead-onlyIdempotent
Execute a SPARQL ASK query and return a boolean result.
ASK queries test whether a pattern exists in the data, returning true or false.
Args: params: Query parameters including endpoint URL, SPARQL ASK query, timeout, and optional headers.
Returns: "true" if the pattern exists, "false" otherwise.
Examples: >>> # Check if a specific item exists >>> sparql_ask(SparqlAskInput( ... endpoint="https://query.wikidata.org/sparql", ... query="ASK { wd:Q42 wdt:P31 wd:Q5 }" ... )) "true"
>>> # Check if a relationship exists
>>> sparql_ask(SparqlAskInput(
... endpoint="https://query.wikidata.org/sparql",
... query="ASK { wd:Q42 wdt:P27 wd:Q142 }"
... ))
"true"
Inputs: params (required). Returns: result
sparql_constructARead-onlyIdempotent
Execute a SPARQL CONSTRUCT query and return RDF triples.
CONSTRUCT queries build an RDF graph from a template pattern. Results are returned as Turtle RDF or JSON-LD. For large-scale graph construction, increase the timeout parameter — default is 30s, maximum is 3600s (1 hour).
Args: params: Query parameters including endpoint URL, SPARQL CONSTRUCT query, timeout, output format, optional headers, and max rows limit.
Returns: RDF triples formatted as Turtle or JSON.
Examples: >>> # Construct a subgraph >>> sparql_construct(SparqlConstructInput( ... endpoint="https://query.wikidata.org/sparql", ... query="CONSTRUCT { wd:Q42 rdfs:label ?name } WHERE { wd:Q42 rdfs:label ?name . FILTER(LANG(?name) = 'en') }" ... )) "@prefix rdfs: http://www.w3.org/2000/01/rdf-schema# .\n..."
Inputs: params (required). Returns: result
sparql_describeARead-onlyIdempotent
Execute a SPARQL DESCRIBE query and return an RDF resource description.
DESCRIBE queries return an RDF graph describing the specified resource(s). For resources with many properties, increase the timeout parameter — default is 30s, maximum is 3600s (1 hour).
Args: params: Query parameters including endpoint URL, SPARQL DESCRIBE query, timeout, output format, optional headers, and max rows limit.
Returns: RDF description formatted as Turtle or JSON.
Examples: >>> # Describe a Wikidata entity >>> sparql_describe(SparqlDescribeInput( ... endpoint="https://query.wikidata.org/sparql", ... query="DESCRIBE wd:Q42" ... )) "@prefix ...> .\n<...> ..."
Inputs: params (required). Returns: result
sparql_get_prefixesARead-onlyIdempotent
Get commonly used prefixes for a SPARQL endpoint.
Returns a combination of well-known standard prefixes (rdf, rdfs, owl, xsd, etc.) and any endpoint-specific prefixes discovered via the data.
Args: params: Parameters including endpoint URL, timeout, and optional headers.
Returns: Formatted list of prefix declarations for use in SPARQL queries.
Examples: >>> sparql_get_prefixes(SparqlGetPrefixesInput( ... endpoint="https://query.wikidata.org/sparql" ... )) "PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#\n..."
Inputs: params (required). Returns: result
sparql_list_graphsARead-onlyIdempotent
List available named graphs on a SPARQL endpoint.
Queries the endpoint for all named graphs (contexts) available for querying.
Args: params: Parameters including endpoint URL, timeout, and optional headers.
Returns: List of named graph URIs.
Examples: >>> sparql_list_graphs(SparqlListGraphsInput( ... endpoint="https://query.wikidata.org/sparql" ... )) "Found 3 named graphs:\n1. http://example.org/graph1\n..."
Inputs: params (required). Returns: result
sparql_queryARead-onlyIdempotent
Execute a SPARQL SELECT query against a SPARQL endpoint.
Runs a SELECT query and returns results as a Markdown table or JSON array.
Supports custom HTTP headers for authenticated endpoints.
For long-running queries (large datasets, complex joins), increase the
timeout parameter — default is 30s, maximum is 3600s (1 hour).
Args:
params: Query parameters including endpoint URL, SPARQL query, timeout,
output format, optional headers, and max rows limit.
Returns:
Query results formatted as a Markdown table or JSON string.
Examples:
>>> # Query Wikidata for items
>>> sparql_query(SparqlQueryInput(
... endpoint="https://query.wikidata.org/sparql",
... query="SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 . ?item rdfs:label ?itemLabel . FILTER(LANG(?itemLabel) = 'en') } LIMIT 5"
... ))
"| `item` | `itemLabel` |
| --- | --- |
| http://www.wikidata.org/entity/Q5 | human |
..."
>>> # Query with authentication
>>> sparql_query(SparqlQueryInput(
... endpoint="https://my-endpoint.example.com/sparql",
... query="SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10",
... headers={"Authorization": "Bearer my-token"}
... ))
Inputs: params (required). Returns: result
sparql_validateARead-onlyIdempotent
Validate SPARQL query syntax without executing it.
Parses the query and reports whether it is syntactically valid. Useful for debugging query errors before running them against an endpoint.
Args: params: Validation parameters containing the SPARQL query string.
Returns: Validation result with status and error details if invalid.
Examples: >>> # Valid query >>> sparql_validate(SparqlValidateInput(query="SELECT ?s WHERE { ?s ?p ?o }")) "Valid SPARQL query."
>>> # Invalid query
>>> sparql_validate(SparqlValidateInput(query="SELECT WHERE { }"))
"Invalid SPARQL query: ..."
Inputs: params (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct SPARQL operation (ASK, CONSTRUCT, DESCRIBE, SELECT, validate, get prefixes, list graphs) with no overlap. An agent can easily distinguish between them.
All tools follow a consistent 'sparql_<verb_or_noun>' pattern, using snake_case throughout. This makes the tool set predictable and easy to navigate.
7 tools is well-scoped for a SPARQL server, covering all major query forms and common utilities without overloading. Each tool serves a clear purpose.
The set covers the four main SPARQL query types (SELECT, CONSTRUCT, ASK, DESCRIBE) plus validation, prefix retrieval, and graph listing. Missing SPARQL UPDATE operations, but read-only coverage is strong for typical use.
Maintenance
Related MCP Connectors
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
MCP server for querying BrainKB, a knowledge base for neuroscience knowledge graphs.
MCP server for AI dialogue using various LLM models via AceDataCloud
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that provides read-only access to Ontotext GraphDB, enabling LLMs to explore RDF graphs and execute SPARQL queries.29 npm17GPL 3.0
- AlicenseNot gradedqualityCmaintenanceThe Model Context Protocol (MCP) server provides a conversational interface for the exploration and analysis of RDF Turtle Knowledge Graph in Local File mode or SPARQL Endpoint.56MIT
- AlicenseAqualityCmaintenanceAn MCP server that enables AI-powered exploration of RDF data and SPARQL querying via RDF4J. It provides tools for executing queries, searching knowledge graph resources, and retrieving schema summaries.131MIT
- AlicenseAqualityAmaintenanceAI-native ontology engineering MCP server for OWL/RDF/SPARQL. Validate, query, diff, lint, version, and govern knowledge graphs via Oxigraph triple store.422,939MIT