Navigation
MCP GraphDB: Secure SPARQL Access & Knowledge Insights - MCP Implementation

MCP GraphDB: Secure SPARQL Access & Knowledge Insights

MCP GraphDB empowers LLMs with secure, read-only access to Ontotext GraphDB repositories, enabling seamless SPARQL query execution for actionable knowledge graph insights.

Research And Data
4.6(129 reviews)
193 saves
90 comments

This tool saved users approximately 7866 hours last month!

About MCP GraphDB

What is MCP GraphDB?

MCP GraphDB is a Model Context Protocol server designed to provide secure read-only access to GraphDB instances. It enables Large Language Models (LLMs) and applications to execute SPARQL queries and analyze knowledge graphs while maintaining strict data integrity. Core features include protocol-compliant query execution, resource discovery tools, and granular access controls to ensure operational safety.

How to Use MCP GraphDB

Configuration Methods

  • Environment Variables: Specify connection parameters via GRAPHDB_URL and AUTH_TOKEN
  • Command-Line Arguments: Override defaults using --endpoint and --timeout flags

Claude Desktop Integration


    # Configure in .config/anthropic/cloudfire.yaml
    mcp_graphdb:
      host: your-instance.graphdb.com
      context: production
  

Deployment Steps

  1. Clone repository: GitHub Source
  2. Install dependencies: go mod tidy
  3. Build executable: go build -o mcp-graphdb

MCP GraphDB Features

Key Features

Core Query Tools

  • SPARQL Query Executor: Supports all SPARQL 1.1 constructs with result format conversion (JSON/XML)
  • Schema Discovery Tool: Automatically generates ontology summaries for new datasets

Resource Views

  • Class Hierarchy Browser: Visualize ontology structures through interactive UI
  • Predicate Analytics Dashboard: Track property usage patterns and cardinality statistics
  • Instance Distribution Viewer: Get real-time entity counts grouped by categories

Common Use Cases

Data Analysis Workflows

  • Ontology Validation: Verify schema compliance using pre-defined SPARQL checks
  • Link Prediction: Identify missing relationships through pattern analysis
  • Query Optimization: Benchmark different query execution plans

Knowledge Graph Management

  • Version Comparison: Track changes between dataset snapshots
  • Access Auditing: Monitor query activity through standardized logging
  • Schema Migration: Safely update ontologies using transactional updates

MCP GraphDB FAQ

FAQ

How does security work?

All interactions use signed JWT tokens with time-based claims. Queries are validated against predefined whitelists to prevent unauthorized operations.

What response formats are supported?

Results can be returned in standard JSON-LD, XML, or native GraphDB format. Tabular results are automatically formatted for spreadsheet compatibility.

Can I use custom authentication?

Yes, supports OAuth2, SAML, and API key authentication via pluggable auth modules. Custom implementations require implementing the Authenticator interface.

What happens during errors?

Queries automatically retry failed operations 3 times before failing. Detailed error reports include SPARQL syntax highlighting and execution stack traces.

Content

GraphDB MCP Server

A Model Context Protocol server that provides read-only access to Ontotext GraphDB. This server enables LLMs to explore RDF graphs and execute SPARQL queries against a GraphDB instance.

Components

Tools

  • sparqlQuery

    • Execute SPARQL queries against the connected GraphDB repository
    • Input:
      • query (string): The SPARQL query to execute
      • graph (string, optional): Specific graph IRI to target
      • format (string, optional): Response format (json, xml, csv)
    • All queries are executed in read-only mode
  • listGraphs

    • Lists all graphs available in the repository
    • No input parameters required

Resources

The server provides multiple views of the repository data:

  • Class List (graphdb:///repository//classes)

    • Lists all RDF classes found in the repository with counts
  • Predicates (graphdb:///repository//predicates)

    • Lists all predicates (properties) with usage counts
  • Statistics (graphdb:///repository//stats)

    • Provides counts of subjects, predicates, objects, and triples
  • Sample Data (graphdb:///repository//sample)

    • Shows a sample of triples from the repository
  • Graph Content (graphdb:///repository//graph/)

    • Provides sample data from specific graphs along with metadata

Configuration

You can configure the server using environment variables by creating a .env file:

GRAPHDB_ENDPOINT=http://localhost:7200 GRAPHDB_REPOSITORY=myRepository GRAPHDB_USERNAME=username GRAPHDB_PASSWORD=password

Alternatively, you can provide the endpoint and repository as command-line arguments:

node dist/index.js http://localhost:7200 myRepository

The command-line arguments take precedence over environment variables.

Usage with Claude Desktop

To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:

json { "mcpServers": { "graphdb": { "command": "node", "args": [ "/path/to/mcp-server-graphdb/dist/index.js" ], "env": { "GRAPHDB_ENDPOINT": "http://localhost:7200", "GRAPHDB_REPOSITORY": "myRepository", "GRAPHDB_USERNAME": "username", "GRAPHDB_PASSWORD": "password" } } } }

Replace the values with your specific GraphDB configuration.

Installation


# Clone the repository

git clone https://github.com/yourname/mcp-server-graphdb.git cd mcp-server-graphdb

# Install dependencies

yarn install

# Build the project

yarn build ```

## Example SPARQL Queries

Here are some example SPARQL queries you can run with this server:

  1. List all classes in the ontology: ```sparql PREFIX rdf: PREFIX rdfs: SELECT DISTINCT ?class ?label WHERE { { ?class a rdfs:Class } UNION { ?class a owl:Class } OPTIONAL { ?class rdfs:label ?label } } ORDER BY ?class ```

  2. List all properties for a specific class: ```sparql PREFIX rdf: PREFIX rdfs: SELECT ?property ?label ?range WHERE { ?property rdfs:domain . OPTIONAL { ?property rdfs:label ?label } OPTIONAL { ?property rdfs:range ?range } } ORDER BY ?property ```

  3. Count instances by class: ```sparql PREFIX rdf: SELECT ?class (COUNT(?instance) AS ?count) WHERE { ?instance a ?class } GROUP BY ?class ORDER BY DESC(?count) ```

## License

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License.

Related MCP Servers & Clients