GraphDB MCP服务器

一个提供对Ontotext GraphDB只读访问的模型上下文协议服务器,使LLM能够探索RDF图并执行SPARQL查询。

  • by keonchennl
  • JavaScript
  • 本地部署
  • 17 星标
  • 更新于
在 GitHub 查看 keonchennl/mcp-graphdb

使用说明

GraphDB MCP服务器

一个模型上下文协议服务器,提供对Ontotext GraphDB的只读访问。此服务器使LLM能够探索RDF图,并对GraphDB实例执行SPARQL查询。

组件

工具

  • sparqlQuery

    • 对连接的GraphDB存储库执行SPARQL查询
    • 输入:
      • query (string):要执行的SPARQL查询
      • graph (字符串,可选):目标的特定图形IRI
      • format (字符串,可选):响应格式(json、xml、csv)
    • 所有查询都以只读模式执行
  • list图表

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

资源

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

  • 类别列表 (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应用程序一起使用,请将以下配置添加到您的“mcpServers”部分 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"
      }
    }
  }
}

用您的特定GraphDB配置替换这些值。

安装

# Clone the repository
git clone https://github.com/keonchennl/mcp-server-graphdb.git
cd mcp-server-graphdb

# Install dependencies
yarn install

# Build the project
yarn build

SPARQL查询示例

以下是您可以使用此服务器运行的一些SPARQL查询示例:

  1. 列出本体中的所有类:
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. 列出特定类的所有属性:
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许可证的条款和条件自由使用、修改和分发软件。