keonchennl_mcp_graphdb

keonchennl_mcp_graphdb

by keonchennl
A Model Context Protocol server enabling LLMs to execute SPARQL queries on Ontotext GraphDB repositories.

GraphDB MCP Server for LLM SPARQL Query Execution

Overview

The GraphDB MCP Server is a Model Context Protocol server designed to provide read-only access to Ontotext GraphDB. It enables Large Language Models (LLMs) to explore RDF graphs and execute SPARQL queries against a GraphDB instance. This server is particularly useful for integrating GraphDB with AI tools like Claude for advanced querying and data exploration.

Tools

SPARQL Query

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

List Graphs

  • Functionality: Lists all graphs available in the repository.
  • Input Parameters: None required.

Resources

The server provides multiple views of the repository data:

  • Class List: Lists all RDF classes found in the repository with counts.
  • Predicates: Lists all predicates (properties) with usage counts.
  • Statistics: Provides counts of subjects, predicates, objects, and triples.
  • Sample Data: Shows a sample of triples from the repository.
  • Graph Content: 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:

{
  "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:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?class ?label
WHERE {
  { ?class a rdfs:Class } UNION { ?class a owl:Class }
  OPTIONAL { ?class rdfs:label ?label }
}
ORDER BY ?class
  1. List all properties for a specific class:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?property ?label ?range
WHERE {
  ?property rdfs:domain <http://example.org/YourClass> .
  OPTIONAL { ?property rdfs:label ?label }
  OPTIONAL { ?property rdfs:range ?range }
}
ORDER BY ?property
  1. Count instances by class:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
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.

About

A Model Context Protocol server that provides read-only access to graphs in a certain repository in Ontotext GraphDB. This server enables LLMs to execute SPARQL queries.

Resources

Stars

1 star

Watchers

1 watching

Forks

0 forks

Features & Capabilities

Categories
mcp_server model_context_protocol graphdb sparql rdf llm typescript docker api_integration claude

Implementation Details

Stats

0 Views
0 Favorites
1 GitHub Stars

Repository Info

keonchennl Organization

Similar Servers

continuedev_continue by continuedev
0
0
0