GraphDB MCP Server

GraphDB MCP 服务器

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

成分

工具

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

资源

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

  • 类列表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 配置替换这些值。

安装

# 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 查询示例:

  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 服务器遵循 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。

-
security - not tested
-
license - not tested
-
quality - not tested

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

  1. Components
    1. Tools
    2. Resources
  2. Configuration
    1. Usage with Claude Desktop
      1. Installation
        1. Example SPARQL Queries
          1. License
            ID: 0snioofy68