C

Claude知识图谱

@shaneholloman/mcp-knowledge-graph
0 Stars 603 次浏览 shaneholloman 更新于 2026-08-23

一种改进的持久内存实现方法,使用带有可定制 --memory-path 的本地知识图谱。这使得 Claude 能够在多次聊天中记住用户的信息。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "memory": {
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ],
      "command": "npx"
    }
  }
}

可用工具 (9 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

create_entities 1 个参数 需填 1 项

Create multiple new entities in the knowledge graph

必填参数:entities

create_relations 1 个参数 需填 1 项

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

必填参数:relations

add_observations 1 个参数 需填 1 项

Add new observations to existing entities in the knowledge graph

必填参数:observations

delete_entities 1 个参数 需填 1 项

Delete multiple entities and their associated relations from the knowledge graph

必填参数:entityNames

delete_observations 1 个参数 需填 1 项

Delete specific observations from entities in the knowledge graph

必填参数:deletions

delete_relations 1 个参数 需填 1 项

Delete multiple relations from the knowledge graph

必填参数:relations

read_graph

Read the entire knowledge graph

该工具无需必填参数,直接调用即可

search_nodes 1 个参数 需填 1 项

Search for nodes in the knowledge graph based on a query

必填参数:query

open_nodes 1 个参数 需填 1 项

Open specific nodes in the knowledge graph by their names

必填参数:names

服务介绍

知识图谱内存服务器

使用具有可自定义 --memory-path 的本地知识图谱实现持久内存的改进版本。

这使得 Claude 能够在聊天过程中记住关于用户的信息。

[!NOTE]
这是原始 Memory Server 的一个分支,目的是不使用临时内存 npx 安装方法。

服务器名称

mcp-knowledge-graph

screen-of-server-name

read-function

核心概念

实体

实体是知识图谱中的主要节点。每个实体包括:

  • 唯一名字(标识符)
  • 实体类型(例如,“人”、“组织”、“事件”)
  • 观察列表

示例:

{
  "name": "John_Smith",
  "entityType": "person",
  "observations": ["Speaks fluent Spanish"]
}

关系

关系定义了实体之间的有向连接。它们总是以主动语态存储,并描述实体之间如何交互或关联。

示例:

{
  "from": "John_Smith",
  "to": "Anthropic",
  "relationType": "works_at"
}

观察

观察是关于实体的离散信息片段。它们是:

  • 以字符串形式存储
  • 附加到特定实体
  • 可以独立添加或移除
  • 应该是原子性的(每条观察仅包含一个事实)

示例:

{
  "entityName": "John_Smith",
  "observations": [
    "Speaks fluent Spanish",
    "Graduated in 2019",
    "Prefers morning meetings"
  ]
}

API

工具

  • create_entities

    • 在知识图谱中创建多个新实体
    • 输入: entities (对象数组)
      • 每个对象包含:
        • name (字符串): 实体标识符
        • entityType (字符串): 类型分类
        • observations (字符串数组): 相关观察
    • 忽略已存在名称的实体
  • create_relations

    • 在实体之间创建多个新关系
    • 输入: relations (对象数组)
      • 每个对象包含:
        • from (字符串): 源实体名称
        • to (字符串): 目标实体名称
        • relationType (字符串): 主动语态的关系类型
    • 跳过重复的关系
  • add_observations

    • 向现有实体添加新的观察
    • 输入: observations (对象数组)
      • 每个对象包含:
        • entityName (字符串): 目标实体
        • contents (字符串数组): 要添加的新观察
    • 返回每个实体添加的观察
    • 如果实体不存在则失败
  • delete_entities

    • 删除实体及其关系
    • 输入: entityNames (字符串数组)
    • 级联删除相关关系
    • 如果实体不存在则静默操作
  • delete_observations

    • 从实体中删除特定观察
    • 输入: deletions (对象数组)
      • 每个对象包含:
        • entityName (字符串): 目标实体
        • observations (字符串数组): 要删除的观察
    • 如果观察不存在则静默操作
  • delete_relations

    • 从图中删除特定关系
    • 输入: relations (对象数组)
      • 每个对象包含:
        • from (字符串): 源实体名称
        • to (字符串): 目标实体名称
        • relationType (字符串): 关系类型
    • 如果关系不存在则静默操作
  • read_graph

    • 读取整个知识图谱
    • 不需要输入
    • 返回带有所有实体和关系的完整图结构
  • search_nodes

    • 根据查询搜索节点
    • 输入: query (字符串)
    • 搜索范围:
      • 实体名称
      • 实体类型
      • 观察内容
    • 返回匹配的实体及其关系
  • open_nodes

    • 通过名称检索特定节点
    • 输入: names (字符串数组)
    • 返回:
      • 请求的实体
      • 请求实体之间的关系
    • 静默跳过不存在的节点

使用 Claude Desktop

设置

将以下内容添加到您的 claude_desktop_config.json 文件中:

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ]
    }
  }
}

自定义内存路径

您可以指定内存文件的自定义路径:

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory", "--memory-path", "/path/to/your/memory.jsonl"]
    }
  }
}

如果未指定路径,它将默认为服务器安装目录中的 memory.jsonl。

系统提示

利用内存的提示取决于用例。更改提示有助于模型确定创建记忆的频率和类型。

这是一个用于聊天个性化的示例提示。您可以在 Claude.ai 项目 的“自定义指令”字段中使用此提示。

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 retrieve all relevant information from your knowledge graph
   - 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

许可证

此 MCP 服务器采用 MIT 许可证。这意味着您可以根据 MIT 许可证的条款和条件自由使用、修改和分发该软件。更多详情,请参见项目仓库中的 LICENSE 文件。

相关 MCP 服务