Skip to main content
Glama
MCP DuckDB Knowledge Graph Memory Server

MCP DuckDB Knowledge Graph Memory Server

by IzumiSy

MCP DuckDB 知识图谱内存服务器

测试 铁匠徽章 NPM 版本NPM 许可证

官方知识图谱内存服务器的分叉版本。

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 DuckDB 知识图谱内存服务器:

npx -y @smithery/cli install @IzumiSy/mcp-duckdb-memory-server --client claude

手动安装

否则,请在claude_desktop_config.json中手动添加@IzumiSy/mcp-duckdb-memory-server ( MEMORY_FILE_PATH是可选的)

{
  "mcpServers": {
    "graph-memory": {
      "command": "npx",
      "args": [
        "-y",
        "@izumisy/mcp-duckdb-memory-server"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/path/to/your/memory.data"
      }
    }
  }
}

该路径上存储的数据是 DuckDB 数据库文件。

Docker

建造

docker build -t mcp-duckdb-graph-memory .

跑步

docker run -dit mcp-duckdb-graph-memory

Related MCP server: Knowledge Graph Memory Server

用法

使用下面的示例指令

Follow these steps for each interaction:

1. User Identification:
   - You should assume that you are interacting with default_user
   - If you have not identified default_user, proactively try to do so.

2. Memory Retrieval:
   - Always begin your chat by saying only "Remembering..." and search relevant information from your knowledge graph
   - Create a search query from user words, and search things from "memory". If nothing matches, try to break down words in the query at first ("A B" to "A" and "B" for example).
   - Always refer to your knowledge graph as your "memory"

3. Memory
   - While conversing with the user, be attentive to any new information that falls into these categories:
     a) Basic Identity (age, gender, location, job title, education level, etc.)
     b) Behaviors (interests, habits, etc.)
     c) Preferences (communication style, preferred language, etc.)
     d) Goals (goals, targets, aspirations, etc.)
     e) Relationships (personal and professional relationships up to 3 degrees of separation)

4. Memory Update:
   - If any new information was gathered during the interaction, update your memory as follows:
     a) Create entities for recurring organizations, people, and significant events
     b) Connect them to the current entities using relations
     b) Store facts about them as observations

动机

该项目通过用 DuckDB 替换其后端来增强原始 MCP 知识图谱内存服务器。

为什么选择 DuckDB?

最初的 MCP 知识图谱内存服务器使用 JSON 文件作为数据存储,并执行内存搜索。虽然这种方法对于小型数据集非常有效,但也带来了一些挑战:

  1. 性能:随着数据集的增长,内存搜索性能会下降

  2. 可扩展性:处理大量实体和关系时,内存使用量会显著增加

  3. 查询灵活性:复杂查询和条件搜索难以实现

  4. 数据完整性:确保事务和 CRUD 操作的原子性具有挑战性

选择 DuckDB 来解决以下挑战:

  • 快速查询处理:DuckDB 针对分析查询进行了优化,即使处理大型数据集也能表现良好

  • SQL 接口:标准 SQL 可用于轻松执行复杂查询

  • 事务支持:支持事务处理以维护数据完整性

  • 索引功能:允许创建索引以提高搜索性能

  • 嵌入式数据库:在应用程序内工作,无需外部数据库服务器

实现细节

本实现采用DuckDB作为后端存储系统,重点关注两个方面:

数据库结构

知识图谱存储在关系数据库结构中如下图所示:

erDiagram
    ENTITIES {
        string name PK
        string entityType
    }
    OBSERVATIONS {
        string entityName FK
        string content
    }
    RELATIONS {
        string from_entity FK
        string to_entity FK
        string relationType
    }

    ENTITIES ||--o{ OBSERVATIONS : "has"
    ENTITIES ||--o{ RELATIONS : "from"
    ENTITIES ||--o{ RELATIONS : "to"

这种模式设计允许有效地存储和检索知识图谱组件,同时维护实体、观察和关系之间的关系。

模糊搜索实现

该实现将 SQL 查询与 Fuse.js 结合起来,实现灵活的实体搜索:

  • DuckDB SQL 查询从数据库中检索基础数据

  • Fuse.js 在检索到的数据上提供模糊匹配功能

  • 这种混合方法允许结构化查询和灵活的文本匹配

  • 搜索结果包括完全匹配和部分匹配,按相关性排序

发展

设置

pnpm install

测试

pnpm test

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

Available Tools

8 tools
add_observationsC

Add new observations to existing entities in the knowledge graph

Inputs: observations (required).

create_entitiesC

Create multiple new entities in the knowledge graph

Inputs: entities (required).

create_relationsC

Create multiple new relations between entities in the knowledge graph. Relations should be in active voice

Inputs: relations (required).

delete_entitiesC

Delete multiple entities and their associated relations from the knowledge graph

Inputs: entityNames (required).

delete_observationsC

Delete specific observations from entities in the knowledge graph

Inputs: deletions (required).

delete_relationsC

Delete multiple relations from the knowledge graph

Inputs: relations (required).

open_nodesC

Open specific nodes in the knowledge graph by their names

Inputs: names (required).

search_nodesC

Search for nodes in the knowledge graph based on a query

Inputs: query (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 8 tools

    Disambiguation4/5

    Most tools have distinct purposes targeting different aspects of the knowledge graph (entities, relations, observations, nodes), though 'open_nodes' and 'search_nodes' could potentially overlap in functionality if opening involves searching. The descriptions clarify that 'open_nodes' accesses specific named nodes while 'search_nodes' performs query-based lookup, but agents might still confuse them in some scenarios.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern with snake_case naming (e.g., add_observations, create_entities, delete_relations). The verbs are clear and appropriate for the actions (add, create, delete, open, search), and there are no deviations in style or convention throughout the set.

    Tool Count5/5

    With 8 tools, this server is well-scoped for a knowledge graph memory system. Each tool appears to serve a specific and necessary function for managing entities, relations, observations, and nodes, without being overly sparse or bloated. The count aligns well with the domain's typical CRUD and query operations.

    Completeness4/5

    The tool set provides strong coverage for core knowledge graph operations, including creation, deletion, and querying of entities, relations, and observations. A minor gap is the lack of update tools (e.g., update_entities or update_relations), which might require workarounds like delete-and-recreate, but the surface is otherwise comprehensive for the stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A persistent memory system using a local knowledge graph that enables Claude to remember information about users across chats, with advanced search, graph traversal, and filtering capabilities for entities, relations, and observations.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A persistent memory server for Claude Code that captures session context and tool outputs to inject relevant history into future sessions. It enables long-term recall through semantic search and automatic context management, allowing for more consistent and context-aware coding interactions.
      253
      AGPL 3.0