项目简介
Dgraph MCP Server 是一个实现了 Model Context Protocol (MCP) 的服务器,专门为 Dgraph 图数据库设计。它允许大型语言模型(LLM)应用通过标准化的 MCP 协议与 Dgraph 数据库进行交互,从而扩展 LLM 的上下文信息和功能。
主要功能点
- DQL 查询工具 (dgraph_query): 允许 LLM 执行 Dgraph 查询语言 (DQL) 查询,从 Dgraph 数据库中检索信息。
- 数据变更工具 (dgraph_mutate): 支持 LLM 向 Dgraph 数据库执行数据变更操作(mutation),实现数据的添加、修改和删除。
- Schema 管理工具 (dgraph_alter_schema): 使 LLM 能够动态修改 Dgraph 数据库的 Schema,例如添加新的谓词或修改索引。
- Schema 资源 (dgraph://schema): 提供访问当前 Dgraph 数据库 Schema 的资源,允许 LLM 获取数据库结构信息。
安装步骤
- 克隆仓库:
git clone https://github.com/johnymontana/dgraph-mcp-server.git cd dgraph-mcp-server - 安装依赖:
确保已安装 Go 1.18 或更高版本,然后执行以下命令下载依赖:
go mod download
服务器配置
MCP 客户端需要配置以下信息以连接到 Dgraph MCP Server。服务器通过标准输入/输出 (stdio) 与客户端通信。
{ "serverName": "dgraph-mcp-server", "command": "go", "args": ["run", "main.go"], "env": { "DGRAPH_HOST": "localhost:9080" }, "description": "Dgraph MCP Server 连接配置", "notes": "请确保 Dgraph 数据库已启动并在 DGRAPH_HOST 环境变量中指定的地址可访问。\n默认 DGRAPH_HOST 为 localhost:9080,如果 Dgraph 服务地址不同,请修改 env 中的 DGRAPH_HOST 值。" }
配置参数说明:
- 'serverName': 服务器名称,可以自定义,用于在 MCP 客户端中标识该服务器连接。
- 'command': 启动服务器的命令,这里使用 'go' 命令。
- 'args': 传递给 'command' 的参数,'run main.go' 表示运行 'main.go' 文件。
- 'env': 环境变量配置,用于配置 Dgraph MCP Server 的运行环境。
- 'DGRAPH_HOST': 重要参数。Dgraph 数据库的地址和端口。默认为 'localhost:9080'。如果你的 Dgraph 服务运行在不同的地址,请修改此值。
- 'description': 对该配置的描述,方便用户理解其用途。
- 'notes': 更详细的配置说明和注意事项。
基本使用方法
-
启动 MCP 服务器: 在克隆的仓库目录下,运行以下命令启动 Dgraph MCP Server:
go run main.go服务器将通过标准输入/输出等待接收来自 MCP 客户端的请求。
-
使用 MCP 客户端发送请求: MCP 客户端需要按照 MCP 协议格式构造 JSON-RPC 请求,并通过标准输入发送给 Dgraph MCP Server。以下是一些示例请求:
-
调用 'dgraph_query' 工具执行 DQL 查询:
{ "jsonrpc": "2.0", "method": "call_tool", "params": { "tool_call_id": "query-1", "tool_name": "dgraph_query", "arguments": { "query": "{ me(func: has(name)) { name } }" } }, "id": 1 } -
调用 'dgraph_mutate' 工具执行数据变更:
{ "jsonrpc": "2.0", "method": "call_tool", "params": { "tool_call_id": "mutate-1", "tool_name": "dgraph_mutate", "arguments": { "mutation": "_:person <name> \"John Doe\" .", "commit": true } }, "id": 2 } -
调用 'dgraph_alter_schema' 工具修改 Schema:
{ "jsonrpc": "2.0", "method": "call_tool", "params": { "tool_call_id": "alter-schema-1", "tool_name": "dgraph_alter_schema", "arguments": { "schema": "name: string @index(exact) ." } }, "id": 3 } -
读取 'dgraph://schema' 资源获取 Schema 信息:
{ "jsonrpc": "2.0", "method": "read_resource", "params": { "resource_uri": "dgraph://schema" }, "id": 4 }
MCP 服务器会将处理结果以 JSON-RPC 响应的格式通过标准输出返回给客户端。
-
注意事项
- 确保 Dgraph 数据库服务已正确安装并运行。
- 根据实际 Dgraph 服务地址配置 'DGRAPH_HOST' 环境变量。
- MCP 客户端需要根据 MCP 协议规范发送请求和处理响应。
信息
分类
数据库与文件