You signed in with another tab or window. Reload
to refresh your session. You signed out in another tab or window. Reload
to refresh your session. You switched accounts on another tab or window. Reload
to refresh your session. Dismiss alert
JovanHsu / mcp-neo4j-memory-server Public
MCP Memory Server with Neo4j backend for AI knowledge graph storage
2 stars
1 fork
Branches
Tags
Activity
Notifications
You must be signed in to change notification settings
main
Go to file
Code
| Name | | Name | Last commit message | Last commit date |
| --- | --- | --- | --- |
| Latest commit
-------------
JovanHsu
update readme
Mar 15, 2025
80ab27b
· Mar 15, 2025
History
-------
3 Commits
| | |
| .github/workflows | | .github/workflows | init project | Mar 15, 2025 |
| src | | src | init project | Mar 15, 2025 |
| test | | test | init project | Mar 15, 2025 |
| .gitignore | | .gitignore | init project | Mar 15, 2025 |
| .npmignore | | .npmignore | init project | Mar 15, 2025 |
| CHANGELOG.md | | CHANGELOG.md | init project | Mar 15, 2025 |
| CONTRIBUTING.md | | CONTRIBUTING.md | init project | Mar 15, 2025 |
| Dockerfile | | Dockerfile | init project | Mar 15, 2025 |
| LICENSE | | LICENSE | init project | Mar 15, 2025 |
| README.md | | README.md | update readme | Mar 15, 2025 |
| docker-compose.yml | | docker-compose.yml | init project | Mar 15, 2025 |
| package.json | | package.json | init project | Mar 15, 2025 |
| tsconfig.json | | tsconfig.json | init project | Mar 15, 2025 |
| tsup.config.ts | | tsup.config.ts | init project | Mar 15, 2025 |
| View all files | | |
MCP Neo4j Knowledge Graph Memory Server是一个基于Neo4j图数据库的知识图谱记忆服务器,用于存储和检索AI助手与用户交互过程中的信息。该项目是官方Knowledge Graph Memory Server
的增强版本,使用Neo4j作为后端存储引擎。
通过使用Neo4j作为存储后端,本项目提供了更强大的图查询能力、更好的性能和可扩展性,特别适合构建复杂的知识图谱应用。
# 全局安装
npm install -g @jovanhsu/mcp-neo4j-memory-server
# 或作为项目依赖安装
npm install @jovanhsu/mcp-neo4j-memory-server
# 使用docker-compose启动Neo4j和Memory Server
git clone https://github.com/JovanHsu/mcp-neo4j-memory-server.git
cd mcp-neo4j-memory-server
docker-compose up -d
服务器使用以下环境变量进行配置:
环境变量 | 描述 | 默认值 |
---|---|---|
NEO4J_URI | Neo4j数据库URI | bolt://localhost:7687 |
NEO4J_USER | Neo4j用户名 | neo4j |
NEO4J_PASSWORD | Neo4j密码 | password |
NEO4J_DATABASE | Neo4j数据库名称 | neo4j |
在claude_desktop_config.json
中添加以下配置:
{
"mcpServers": {
"graph-memory": {
"command": "npx",
"args": [\
"-y",\
"@izumisy/mcp-neo4j-memory-server"\
],
"env": {
"NEO4J_URI": "neo4j://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "password",
"NEO4J_DATABASE": "memory"
}
}
}
}
启动Neo4j Memory Server:
shell
npx @jovanhsu/mcp-neo4j-memory-server
在另一个终端启动MCP Inspector:
shell
npx @modelcontextprotocol/inspector npx @jovanhsu/mcp-neo4j-memory-server
在浏览器中访问MCP Inspector界面
在Claude的自定义指令中添加以下内容:
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
如果您想在自己的应用程序中使用本服务器,可以通过MCP协议与其通信:
import { McpClient } from '@modelcontextprotocol/sdk/client/mcp.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
// 创建客户端
const transport = new StdioClientTransport({
command: 'npx',
args: ['-y', '@izumisy/mcp-neo4j-memory-server'],
env: {
NEO4J_URI: 'bolt://localhost:7687',
NEO4J_USER: 'neo4j',
NEO4J_PASSWORD: 'password',
NEO4J_DATABASE: 'neo4j'
}
});
const client = new McpClient();
await client.connect(transport);
// 创建实体
const result = await client.callTool('create_entities', {
entities: [\
{\
name: '用户',\
entityType: '人物',\
observations: ['喜欢编程', '使用TypeScript']\
}\
]
});
console.log(result);
相比于原始版本使用的JSON文件存储和DuckDB版本,Neo4j提供了以下优势:
知识图谱在Neo4j中的存储模型如下:
(Entity:EntityType {name: "实体名称"})
(Entity)-[:HAS_OBSERVATION]->(Observation {content: "观察内容"})
(Entity1)-[:RELATION_TYPE]->(Entity2)
本实现结合了Neo4j的全文搜索功能和Fuse.js进行灵活的实体搜索:
# 克隆仓库
git clone https://github.com/JovanHsu/mcp-neo4j-memory-server.git
cd mcp-neo4j-memory-server
# 安装依赖
pnpm install
# 构建项目
pnpm build
# 开发模式(使用MCP Inspector)
pnpm dev
# 运行测试
pnpm test
# 准备发布
npm version [patch|minor|major]
# 发布到NPM
npm publish
欢迎贡献代码、报告问题或提出改进建议!请遵循以下步骤:
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)本项目采用MIT许可证 - 详见LICENSE
文件。
NPM: https://www.npmjs.com/package/@jovanhsu/mcp-neo4j-memory-server
作者: JovanHsu
MCP Memory Server with Neo4j backend for AI knowledge graph storage
No releases published
No packages published
You can’t perform that action at this time.