MCP server for interacting with Ontotext GraphDB via SPARQL
npm install mcp-server-graphdb
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.
- 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
The server provides multiple views of the repository data:
- Class List (graphdb://)
- Lists all RDF classes found in the repository with counts
- Predicates (graphdb://)
- Lists all predicates (properties) with usage counts
- Statistics (graphdb://)
- Provides counts of subjects, predicates, objects, and triples
- Sample Data (graphdb://)
- Shows a sample of triples from the repository
- Graph Content (graphdb://)
- Provides sample data from specific graphs along with metadata
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.
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": "mcp-server-graphdb",
"env": {
"GRAPHDB_ENDPOINT": "http://localhost:7200",
"GRAPHDB_REPOSITORY": "myRepository",
"GRAPHDB_USERNAME": "username",
"GRAPHDB_PASSWORD": "password"
}
}
}
}
`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.
`sh`
npm install -g mcp-server-graphdb
Or install locally in your project:
`sh`
npm install mcp-server-graphdb
`shClone the repository
git clone https://github.com/keonchennl/mcp-server-graphdb.git
cd mcp-server-graphdb
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)
``This MCP server is licensed under the GPL-3.0 License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the GNU GPL-3.0 License.