Skip to main content
Glama
mcp-server-qlever

mcp-server-qlever

by XORwell

mcp-server-qlever

npm version License: MIT MCP

A Model Context Protocol (MCP) server for the QLever SPARQL engine. Connect Claude Code or any MCP-compatible client to knowledge graphs powered by QLever.

Features

  • Execute SPARQL queries with formatted text or raw JSON output

  • Explore dataset schemas by listing predicates ordered by frequency

  • Look up entities by IRI with outgoing and incoming triples

  • Search for entities by label using full-text matching

  • Predicate and class completion from what actually exists in the index

  • Query plan analysis without execution

  • Geographic search (radius / bounding box) via GeoSPARQL functions

  • SPARQL 1.1 Update with dry-run preview and safety guards

  • Input sanitization: IRI validation and SPARQL injection prevention

  • Works with any QLever instance (local Docker, self-hosted, or public)

Related MCP server: RDF4J MCP Server

Quick Start

Pick your scenario:

A) You already have a QLever endpoint

claude mcp add qlever -- npx -y mcp-server-qlever -e http://your-qlever:7019

Done. Claude can now query your knowledge graph.

B) You want everything from scratch (QLever + MCP)

docker compose -f docker-compose.allinone.yml up -d --wait
claude mcp add qlever -- npx -y mcp-server-qlever -e http://localhost:7019

This starts QLever with a small test dataset and connects the MCP server to it.

C) You want real-world data (e.g. German National Library)

cd examples/gnd
docker compose up -d --wait
claude mcp add gnd -- npx -y mcp-server-qlever -e http://localhost:7020

First run downloads and indexes the GND Werk authority data (~90 MB, ~3.5M triples) automatically. See examples/gnd/ for details.

Installation

There are several ways to install and run the server. Pick whichever fits your setup.

npx (no install)

npx mcp-server-qlever --endpoint http://localhost:7019

npm (global)

npm install -g mcp-server-qlever
mcp-server-qlever --endpoint http://localhost:7019

Docker

docker run --rm -i ghcr.io/xorwell/mcp-server-qlever:latest \
  --endpoint http://host.docker.internal:7019

Use --network=host on Linux to reach a QLever instance on localhost:

docker run --rm -i --network=host ghcr.io/xorwell/mcp-server-qlever:latest \
  --endpoint http://localhost:7019

Environment variables work too:

docker run --rm -i --network=host \
  -e QLEVER_ENDPOINT=http://localhost:7019 \
  -e QLEVER_ACCESS_TOKEN=my-token \
  ghcr.io/xorwell/mcp-server-qlever:latest

From source

git clone https://github.com/XORwell/mcp-server-qlever.git
cd mcp-server-qlever
npm install
npm run build
node dist/index.js --endpoint http://localhost:7019

Requirements: Node.js 20+ (all methods), or Docker/Podman (Docker method).

Configuration

Claude Code (CLI)

# Project-scoped
claude mcp add qlever -- npx -y mcp-server-qlever --endpoint http://localhost:7019

# User-scoped (all projects)
claude mcp add -s user qlever -- npx -y mcp-server-qlever --endpoint http://localhost:7019

Using the Docker image instead of npx:

claude mcp add qlever -- docker run --rm -i --network=host \
  ghcr.io/xorwell/mcp-server-qlever:latest --endpoint http://localhost:7019

Verify:

claude mcp list

Claude Code (VS Code / Cursor)

Edit .vscode/settings.json:

{
  "claude-code.mcpServers": {
    "qlever": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "--endpoint", "http://localhost:7019"]
    }
  }
}

Or with Docker:

{
  "claude-code.mcpServers": {
    "qlever": {
      "command": "docker",
      "args": [
        "run", "--rm", "-i", "--network=host",
        "ghcr.io/xorwell/mcp-server-qlever:latest",
        "--endpoint", "http://localhost:7019"
      ]
    }
  }
}

Manual configuration (any MCP client)

Add to ~/.claude.json or .claude/settings.json:

{
  "mcpServers": {
    "qlever": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "--endpoint", "http://localhost:7019"]
    }
  }
}

With access token via env:

{
  "mcpServers": {
    "qlever": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "--endpoint", "http://localhost:7019"],
      "env": {
        "QLEVER_ACCESS_TOKEN": "your-token-here"
      }
    }
  }
}

Multiple endpoints

Register several QLever instances under different names:

{
  "mcpServers": {
    "qlever-wikidata": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "-e", "http://localhost:7019"]
    },
    "qlever-osm": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "-e", "http://localhost:7020"]
    },
    "qlever-dblp": {
      "command": "npx",
      "args": ["-y", "mcp-server-qlever", "-e", "http://localhost:7021"]
    }
  }
}

Tool Reference

Tool

Description

Key Parameters

sparql_query

Execute SPARQL and get formatted text results

query, timeout, max_rows

sparql_query_json

Execute SPARQL and get raw JSON response

query, timeout, max_rows

get_index_stats

Retrieve dataset metadata (triple count, predicates, etc.)

--

describe_entity

Look up all triples for an entity by IRI

iri, limit

search_entities

Full-text search for entities by label

search_term, label_predicate, limit

get_predicates

List available predicates ordered by frequency

limit, timeout

sparql_autocomplete

Suggest predicate or class IRIs containing a search term, ordered by usage

search_term, kind, limit

analyze_query

Run a query without returning rows and show its execution tree (sizes, timings)

query, timeout

list_named_graphs

List all named graphs with triple counts

limit

search_fulltext

Search QLever's text index for entity-keyword co-occurrence

keywords, filter_type, limit

spatial_query

Geographic search (radius or bounding box) via GeoSPARQL geof: functions

mode, lat, lon, radius_km / bbox params, limit

sparql_update

Execute SPARQL 1.1 Update (requires access token)

update, graph_uri, dry_run, confirm

Prompts

Prompt

Description

explore_dataset

Step-by-step workflow for discovering an unknown QLever dataset

safe_update_workflow

Validated workflow for SPARQL Update operations with dry-run preview

QLever-Specific Features

This server goes beyond generic SPARQL access by exposing QLever's unique capabilities:

  • Predicate and class completion -- The sparql_autocomplete tool uses QLever's ql:has-predicate pattern to suggest predicates (or classes) that actually exist in the index, ordered by usage.

  • Query plan analysis -- The analyze_query tool returns QLever's runtime information (execution tree with estimated vs. actual sizes and per-operation timings). QLever has no plan-only mode, so the query is executed, but no rows are returned.

  • Full-text search -- The search_fulltext tool uses QLever's SPARQL+Text extension to find entities co-occurring with keywords in the text corpus.

  • Spatial queries -- The spatial_query tool uses QLever's geof:distance, geof:latitude and geof:longitude functions on WKT point literals; radius results include the distance in km.

  • Safe SPARQL Update -- The sparql_update tool includes a dry run that echoes the statement without sending it, a confirm requirement for every DROP and CLEAR, and access token enforcement.

Security

All user-controlled inputs are sanitized before interpolation into SPARQL:

  • String literals are escaped for \ " \n \r \t to prevent SPARQL injection

  • IRIs are validated against RFC 3987 (rejects <>"{}|\^ ` and control characters)

  • Predicates are validated with a strict regex matching prefixed names or safe full IRIs

  • SPARQL Update requires explicit access token and flags destructive operations

Environment Variables

Variable

Description

Default

QLEVER_ENDPOINT

QLever API URL (fallback if --endpoint not given)

--

QLEVER_ACCESS_TOKEN

Access token for privileged operations

--

QLEVER_TIMEOUT

Default query timeout (e.g. 30s, 2min)

30s

CLI flags take precedence over environment variables.

CLI Usage

mcp-server-qlever --endpoint <url> [options]

Options:
  -e, --endpoint <url>      QLever API endpoint URL (required)
  -t, --access-token <tok>  Access token for privileged operations
      --timeout <duration>   Default query timeout (default: 30s)
  -h, --help                Show help message
  -v, --version             Show version

Running QLever with Docker

QLever requires a two-step process: build an index from RDF data, then serve it.

Preconfigured dataset

docker run -it --name qlever-wikidata -p 7019:7019 adfreiburg/qlever:latest bash

# Inside the container:
qlever setup-config wikidata    # or: olympics, dblp, osm-planet, uniprot, ...
qlever get-data                 # downloads the dataset
qlever index                    # builds the index (may take minutes to hours)
qlever start                    # starts the SPARQL server on port 7019

Custom RDF data

docker run -it --name qlever-custom -p 7019:7019 \
  -v /path/to/your/data:/data \
  adfreiburg/qlever:latest bash

# Inside the container:
qlever-index -i /data/myindex -f /data/mydata.nt -F nt -s /data/settings.json
qlever-server -i /data/myindex -p 7019 -m 4GB

See the QLever documentation for details on dataset configuration, index settings, and performance tuning.

Examples

The examples/ directory contains ready-to-use setups for specific datasets:

Example

Dataset

Triples

Setup

examples/gnd/

GND Werk (Deutsche Nationalbibliothek)

~3.5M

cd examples/gnd && docker compose up

Each example includes a docker-compose.yml that downloads, converts, and indexes the data automatically on first run. Subsequent starts are instant (index persisted in Docker volume).

Want to add your own dataset? Copy any example directory and adjust the data source URL.

Development

git clone https://github.com/XORwell/mcp-server-qlever.git
cd mcp-server-qlever
npm install
npm run build

Testing

The project has 336 tests across three layers:

# Unit tests only (no Docker needed)
npm run test:unit

# Integration tests against real QLever (scientists dataset)
docker compose -f docker-compose.test.yml up -d --wait
npm run test:integration
docker compose -f docker-compose.test.yml down -v

# E2E tests over real MCP stdio transport (GND dataset, 390K triples)
# First, generate the test fixture from DNB open data:
pip install ijson
curl -o /tmp/gnd-werk.jsonld.gz https://data.dnb.de/opendata/authorities-gnd-werk_lds_20260217.jsonld.gz
python3 scripts/jsonld-to-nt.py -i /tmp/gnd-werk.jsonld.gz --limit 50000 > test/fixtures/gnd/gnd-werk-sample.nt
docker compose -f docker-compose.gnd.yml up -d --wait
npm run build
npm run test:e2e
docker compose -f docker-compose.gnd.yml down -v

# Everything at once
npm run test:ci       # unit + integration (scientists)
npm run test:ci:gnd   # all tests including E2E (GND)

Layer

Tests

What it covers

Unit

291

All tools, client, security (SPARQL injection, IRI validation, bounds, timeouts)

Integration

31

Real QLever queries against scientists and GND authority data

E2E

29

Real MCP server process over stdio, all 12 tools + 2 prompts against live QLever

Building the Docker image

docker build -t mcp-server-qlever:local .
docker run --rm mcp-server-qlever:local --help

License

MIT

Available Tools

12 tools
analyze_query

Analyze how QLever evaluates a SPARQL query. The query IS executed (QLever has no plan-only mode) but no result rows are returned. Shows the query execution tree with estimated vs. actual sizes, per-operation timings and the total result size. Use a short timeout for potentially expensive queries.

Inputs: query (required), timeout.

describe_entity

Look up all triples where a given IRI appears as subject or object. Returns both outgoing properties (where the entity is the subject) and incoming references (where it is the object). Accepts full IRIs (e.g. 'http://www.wikidata.org/entity/Q42') or prefixed names if the dataset supports them.

Inputs: iri (required), limit.

get_index_stats

Retrieve metadata about the QLever index: dataset name, number of triples, predicates, subjects, and objects. Useful for understanding the scope of the knowledge graph before querying.

Inputs: no named parameters.

get_predicates

List the predicates (properties) available in the dataset, ordered by frequency. Useful for exploring an unfamiliar knowledge graph and understanding its schema before writing queries.

Inputs: limit, timeout.

list_named_graphs

List named graphs in the dataset. Call this before graph-scoped queries or updates.

Inputs: limit.

search_entities

Search for entities by name or label using SPARQL text matching. Works with datasets that have rdfs:label or schema:name predicates. Returns matching entities with their labels.

Inputs: search_term (required), limit, label_predicate.

search_fulltext

Search QLever's text index for entities co-occurring with keywords. Different from search_entities which matches labels. Requires text index.

Inputs: keywords (required), limit, filter_type.

sparql_autocomplete

Use this BEFORE sparql_query when unsure which predicates or classes exist. Suggests predicate or class IRIs from the dataset that contain the given text, ordered by how often they are used. For entities, use search_entities.

Inputs: search_term (required), kind, limit.

sparql_query

Execute a SPARQL query against the configured QLever endpoint. Supports SELECT, ASK, CONSTRUCT, and DESCRIBE query forms. Returns results as a formatted table with timing information.

Inputs: query (required), timeout, max_rows.

sparql_query_json

Execute a SPARQL query and return the raw QLever JSON response. Useful when you need structured data for further processing (result arrays, timing breakdown, total result count).

Inputs: query (required), timeout, max_rows.

sparql_update

Execute a SPARQL 1.1 Update. REQUIRES access token. Use dry_run:true to preview. dry_run:true only echoes the statement without contacting QLever. Any DROP or CLEAR requires confirm:true.

Inputs: update (required), confirm, dry_run, graph_uri.

spatial_query

Find entities within a geographic area (GeoSPARQL geof: functions on WKT point literals). Supports radius and bounding box modes.

Inputs: params (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      The 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.
      56
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      An 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.
      13
      1
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      MCP server exposing SPARQL query functionalities for LLMs, enabling query execution, validation, and graph exploration across SPARQL endpoints.
      7
      22 PyPI
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Read-only MCP server for querying an evidence-aware knowledge vault with temporal and provenance-aware data, supporting agent memory and semantic graph projections.
      -