GraphDB MCP 服务器
提供对 Ontotext GraphDB 的只读访问的模型上下文协议 (MCP) 服务器。该服务器使 LLM 能够探索 RDF 图并针对 GraphDB 实例执行 SPARQL 查询。
成分
工具
资源
服务器提供了存储库数据的多个视图:
类列表( graphdb://<host>/repository/<repo>/classes )
谓词( graphdb://<host>/repository/<repo>/predicates )
统计信息( graphdb://<host>/repository/<repo>/stats )
示例数据( graphdb://<host>/repository/<repo>/sample )
图表内容( graphdb://<host>/repository/<repo>/graph/<graphUri> )
Related MCP server: mcp-graphql
配置
您可以通过创建.env文件来使用环境变量配置服务器:
GRAPHDB_ENDPOINT=http://localhost:7200
GRAPHDB_REPOSITORY=myRepository
GRAPHDB_USERNAME=username
GRAPHDB_PASSWORD=password
或者,您可以将端点和存储库作为命令行参数提供:
node dist/index.js http://localhost:7200 myRepository
命令行参数优先于环境变量。
与 Claude Desktop 一起使用
要将此服务器与 Claude Desktop 应用程序一起使用,请将以下配置添加到claude_desktop_config.json的“mcpServers”部分:
{
"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"
}
}
}
}
用您的特定 GraphDB 配置替换这些值。
安装
# 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
SPARQL 查询示例
以下是您可以使用该服务器运行的一些 SPARQL 查询示例:
列出本体中的所有类:
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
列出特定类的所有属性:
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
按类别计数实例:
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)
执照
此 MCP 服务器采用 GPL-3.0 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 GNU GPL-3.0 许可证的条款和条件。