知识图谱记忆服务器
一种使用本地知识图谱实现持久化记忆的基础方案。它让 Claude 能够在不同对话间记住关于用户的信息。
核心概念
实体 (Entities)
实体是知识图谱中的主要节点。每个实体包含:
唯一名称(标识符)
实体类型(例如:“人”、“组织”、“事件”)
观察列表
示例:
{
"name": "John_Smith",
"entityType": "person",
"observations": ["Speaks fluent Spanish"]
}关系 (Relations)
关系定义了实体之间的有向连接。它们始终以主动语态存储,并描述实体之间如何交互或关联。
示例:
{
"from": "John_Smith",
"to": "Anthropic",
"relationType": "works_at"
}观察 (Observations)
观察是关于实体的离散信息片段。它们:
以字符串形式存储
附加到特定实体
可以独立添加或删除
应该是原子的(每个观察包含一个事实)
示例:
{
"entityName": "John_Smith",
"observations": [
"Speaks fluent Spanish",
"Graduated in 2019",
"Prefers morning meetings"
]
}Related MCP server: Knowledge Graph Memory Server
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 中:
Docker
{
"mcpServers": {
"memory": {
"command": "docker",
"args": ["run", "-i", "-v", "claude-memory:/app/dist", "--rm", "mcp/memory"]
}
}
}NPX
{
"mcpServers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}在 Windows 上,使用 cmd /c 来启动 npx:
{
"mcpServers": {
"memory": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}使用自定义设置的 NPX
可以通过以下环境变量配置服务器:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
],
"env": {
"MEMORY_FILE_PATH": "/path/to/custom/memory.jsonl"
}
}
}
}在 Windows 上,使用:
{
"mcpServers": {
"memory": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-memory"
],
"env": {
"MEMORY_FILE_PATH": "/path/to/custom/memory.jsonl"
}
}
}
}MEMORY_FILE_PATH:记忆存储 JSONL 文件的路径(默认:服务器目录下的memory.jsonl)
VS Code 安装说明
如需快速安装,请使用下方的一键安装按钮:
👁 在 VS Code 中使用 NPX 安装
👁 在 VS Code Insiders 中使用 NPX 安装
👁 在 VS Code 中使用 Docker 安装
👁 在 VS Code Insiders 中使用 Docker 安装
如需手动安装,你可以通过以下方法之一配置 MCP 服务器:
方法 1:用户配置(推荐)
将配置添加到你的用户级 MCP 配置文件中。打开命令面板(Ctrl + Shift + P)并运行 MCP: Open User Configuration。这将打开你的用户 mcp.json 文件,你可以在其中添加服务器配置。
方法 2:工作区配置
或者,你可以将配置添加到工作区中的 .vscode/mcp.json 文件中。这将允许你与他人共享该配置。
有关 VS Code 中 MCP 配置的更多详细信息,请参阅官方 VS Code MCP 文档。
NPX
{
"servers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}在 Windows 上,使用:
{
"servers": {
"memory": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}Docker
{
"servers": {
"memory": {
"command": "docker",
"args": [
"run",
"-i",
"-v",
"claude-memory:/app/dist",
"--rm",
"mcp/memory"
]
}
}
}系统提示词
利用记忆的提示词取决于具体用例。更改提示词将有助于模型确定创建记忆的频率和类型。
以下是用于聊天个性化的示例提示词。你可以在 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
c) Store facts about them as observations构建
Docker:
docker build -t mcp/memory -f src/memory/Dockerfile . 注意:之前的 mcp/memory 卷可能包含一个 index.js 文件,该文件可能会被新容器覆盖。如果你正在使用 docker 卷进行存储,请在启动新容器之前删除旧 docker 卷中的 index.js 文件。
许可证
此 MCP 服务器采用 MIT 许可证授权。这意味着你可以自由使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。有关更多详细信息,请参阅项目仓库中的 LICENSE 文件。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/modelcontextprotocol/knowledge-graph-memory-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
