返回市场
MCP-图数据库服务器

MCP-图数据库服务器

作者:keonchennl9 星标更新:2025-06-17

项目介绍

技术文档摘要

MseeP.ai 安全评估徽章

GraphDB MCP 服务器

这是一个提供只读访问权限到 Ontotext GraphDB 的模型上下文协议服务器。此服务器使大型语言模型能够探索 RDF 图并针对 GraphDB 实例执行 SPARQL 查询。

组件

工具

  • sparqlQuery

    • 对连接的 GraphDB 存储库执行 SPARQL 查询
    • 输入参数:
      • query (字符串):要执行的 SPARQL 查询
      • graph (字符串,可选):特定图 IRI
      • format (字符串,可选):响应格式 (json, xml, csv)
    • 所有查询均以只读模式执行
  • listGraphs

    • 列出存储库中可用的所有图
    • 不需要输入参数

资源

该服务器提供了存储库数据的多个视图:

  • 类列表 (graphdb://<host>/repository/<repo>/classes)

    • 列出存储库中的所有 RDF 类及其数量
  • 谓词 (graphdb://<host>/repository/<repo>/predicates)

    • 列出所有谓词(属性)及其使用次数
  • 统计信息 (graphdb://<host>/repository/<repo>/stats)

    • 提供主体、谓词、对象和三元组的数量
  • 样本数据 (graphdb://<host>/repository/<repo>/sample)

    • 显示存储库中的三元组样本
  • 图内容 (graphdb://<host>/repository/<repo>/graph/<graphUri>)

    • 提供特定图的样本数据及其元数据

配置

您可以通过创建一个 .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 配置。

安装

# 克隆仓库
git clone https://github.com/keonchennl/mcp-server-graphdb.git
cd mcp-server-graphdb

# 安装依赖
yarn install

# 构建项目
yarn build

示例 SPARQL 查询

这里有一些示例 SPARQL 查询,您可以使用此服务器运行:

  1. 列出本体中的所有类:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w
3.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. 列出特定类的所有属性:
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. 按类计算实例数量:
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 许可证的条款和条件。