mcp-knowledge-graph

by shaneholloman
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

mcp-knowledge-graph

知识图谱内存服务器

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

这使得 AI 模型能够在聊天过程中记住用户的信息。它适用于任何支持模型上下文协议 (MCP) 或函数调用功能的 AI 模型。

[!NOTE] 这是原始内存服务器的一个分支,旨在不使用临时内存 npx 安装方法。

服务器名称

mcp-knowledge-graph

核心概念

实体

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

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

例子:

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

关系

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

例子:

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

观察

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

  • 存储为字符串
  • 附加到特定实体
  • 可以独立添加或删除
  • 应该是原子的(每个观察一个事实)

例子:

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

API

工具

  • 创建实体
    • 在知识图谱中创建多个新实体
    • 输入: entities (对象数组)
      • 每个对象包含:
        • name (字符串):实体标识符
        • entityType (字符串):类型分类
        • observations (string[]):相关观察
    • 忽略具有现有名称的实体
  • 创建关系
    • 在实体之间创建多个新关系
    • 输入: relations (对象数组)
      • 每个对象包含:
        • from (字符串):源实体名称
        • to (字符串):目标实体名称
        • relationType (字符串):主动语态的关系类型
    • 跳过重复关系
  • 添加观察结果
    • 向现有实体添加新观察
    • 输入: observations (对象数组)
      • 每个对象包含:
        • entityName (字符串):目标实体
        • contents (string[]):要添加的新观察结果
    • 返回每个实体添加的观察值
    • 如果实体不存在则失败
  • 删除实体
    • 删除实体及其关系
    • 输入: entityNames (string[])
    • 级联删除关联关系
    • 如果实体不存在则静默操作
  • 删除观察结果
    • 从实体中删除特定观察结果
    • 输入: deletions (对象数组)
      • 每个对象包含:
        • entityName (字符串):目标实体
        • observations (string[]):要删除的观察结果
    • 如果不存在观察,则静默运行
  • 删除关系
    • 从图中删除特定关系
    • 输入: relations (对象数组)
      • 每个对象包含:
        • from (字符串):源实体名称
        • to (字符串):目标实体名称
        • relationType (字符串):关系类型
    • 如果关系不存在则静默操作
  • 读取图
    • 阅读整个知识图谱
    • 无需输入
    • 返回包含所有实体和关系的完整图形结构
  • 搜索节点
    • 根据查询搜索节点
    • 输入: query (字符串)
    • 搜索范围:
      • 实体名称
      • 实体类型
      • 观察内容
    • 返回匹配的实体及其关系
  • 打开节点
    • 按名称检索特定节点
    • 输入: names (string[])
    • 返回:
      • 请求的实体
      • 被请求实体之间的关系
    • 默默跳过不存在的节点

与 MCP 兼容平台一起使用

该服务器可与任何支持模型上下文协议 (MCP) 或函数调用功能的 AI 平台一起使用,包括 Claude、GPT、Llama 等。

使用 Claude Desktop 进行设置

将其添加到您的 claude_desktop_config.json 中:

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

与其他 AI 平台的设置

任何支持函数调用或 MCP 标准的 AI 平台都可以连接到此服务器。具体配置取决于平台,但服务器会通过 MCP 接口公开标准工具。

自定义内存路径

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

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

如果没有指定路径,则默认为服务器安装目录中的memory.jsonl。

系统提示

使用记忆的提示取决于用例和你正在使用的AI模型。更改提示将有助于模型确定创建记忆的频率和类型。

以下是一个聊天个性化提示示例,可适用于任何 AI 模型。对于 Claude 用户,您可以在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 Gathering: - 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 c) Store facts about them as observations

与其他AI模型的集成

该服务器实现了模型上下文协议 (MCP) 标准,使其兼容任何支持函数调用的 AI 模型。其知识图谱结构和 API 与模型无关,可灵活地与各种 AI 平台集成。

与其他模型集成:

  1. 配置模型访问MCP服务器
  2. 确保模型可以对公开的工具进行函数调用
  3. 使系统提示适应特定型号的指令格式
  4. 无论模型如何,使用相同的知识图谱操作

执照

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

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

持久内存的改进实现,使用具有可自定义 --memory-path 的本地知识图谱。这使得 Claude 能够在聊天过程中记住用户的相关信息。

  1. Server Name
    1. Core Concepts
      1. Entities
      2. Relations
      3. Observations
    2. API
      1. Tools
    3. Usage with MCP-Compatible Platforms
      1. Setup with Claude Desktop
      2. Setup with Other AI Platforms
      3. Custom Memory Path
      4. System Prompt
    4. Integration with Other AI Models
      1. License
        ID: zn6gf7sxjs