Neo4j代理内存MCP服务器
一个专门的MCP服务器,将Neo4j图形数据库与AI代理连接起来,提供以内存为中心的工具,用于存储、调用和连接知识图中的信息。
快速开始🚀
您可以使用npx直接运行此MCP服务器:
npx @knowall-ai/mcp-neo4j-agent-memory或者将其添加到您的Claude Desktop配置中:
{
"mcpServers": {
"neo4j-memory": {
"command": "npx",
"args": ["@knowall-ai/mcp-neo4j-agent-memory"],
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your-password",
"NEO4J_DATABASE": "neo4j"
}
}
}
}特性
- 🧠 持久内存存储 -存储和检索对话中的记忆
- 🔗 语义关系 -在记忆之间建立有意义的联系(已知、工作、创造等)
- 🔍 智能搜索 -跨所有内存属性和关系的自然语言搜索
- 🏷️ 灵活的标签 -使用任何标签来标记记忆(人、地点、项目、想法等)
- ⏰ 时间跟踪 -自动时间戳和基于日期的查询
- 🌐 图形探索 -遍历关系以发现相关信息
- 🎯 上下文感知 -深度搜索以包含相关记忆
- 🔧 LLM优化 -让人工智能处理复杂性的简单工具
- 🏢 企业就绪 -支持多个Neo4j数据库
- 📚 内置导航 -获取有关最佳实践和使用模式的帮助
哲学:LLM驱动的智能
与在工具中嵌入复杂逻辑的传统方法不同,此服务器提供简单的原子操作,并让LLM处理所有智能:
- 无隐藏逻辑:工具完全按照他们说的去做——没有自动消歧或智能匹配
- LLM决定一切:实体识别、关系推理和冲突解决
- 透明操作:每个动作都是明确和可预测的
- 最大的灵活性LLM可以实施任何策略,不受工具限制
搜索行为
这 search_memories 该工具使用单词标记化:
- 查询“John Smith”找到包含“John”或“Smith”的记忆
- 这将返回更多结果,让LLM选择最相关的结果
- 名称和多词查询的子字符串匹配优于精确匹配
这种方法使系统更加强大和适应性更强,因为LLM功能的改进直接转化为更好的内存管理。
Neo4j企业支持
此服务器现在支持连接到Neo4j Enterprise Edition中的特定数据库。默认情况下,它连接到“neo4j”数据库,但您可以使用 NEO4J_DATABASE 环境变量。
内存工具
search_memories:从知识图谱中搜索和检索记忆
- 基于单词的搜索:在查询中搜索任何单词(例如,“Ben Weeks”查找包含“Ben”或“Weeks”的记忆) - 跨所有内存属性进行自然语言搜索(或留空以获取全部) - 按记忆类型(人、地点、项目等)筛选 - 按日期筛选 since_date 参数(ISO格式) - 控制关系深度和结果限制 - 按任何字段排序(created_at、name等)
create_memory:在知识图谱中创建新的记忆
- 灵活的类型系统-使用小写的任何标签(人、地点、项目、技能等) - 将任何属性存储为键值对 - 用于时间跟踪的自动时间戳
create_connection:在记忆之间建立关系
- 使用语义关系类型(KNOWS、WORKS_AT、LIVES_IN等)链接记忆 - 为关系添加属性(自、角色、状态等) - 构建复杂的知识网络
update_memory:更新现有内存的属性
- 添加或修改任何属性 - 将属性设置为null以将其删除
update_connection:更新关系属性
- 修改关系元数据 - 跟踪随时间的变化
delete_memory:删除记忆及其所有连接
- 谨慎使用-永久删除 - 自动删除所有关系
delete_connection:删除特定关系
- 精确关系删除 - 保持记忆完整
list_memory_labels:列出所有正在使用的唯一内存标签
- 显示所有计数标签 - 有助于保持一致性 - 防止重复的标签变化
get_guidance:获得有效使用记忆工具的帮助
- 主题:标签、关系、最佳实践、示例 - 返回LLM的全面指导 - 当不确定标签/关系命名时使用
先决条件
- Neo4j数据库 (v4.4+或v5.x)
- 安装Neo4j社区版或企业版 - 下载自 neo4j.com/下载 - 或者使用Docker: docker run -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=neo4j/password neo4j
- Node.js (v18或更高版本)
- 需要运行MCP服务器 - 下载自
- 克劳德桌面 (用于MCP集成)
- 下载自 claude.ai/下载
安装
通过Smithery安装
](https://smithery.ai/server/@knowall-ai/mcp-neo4j-agent-memory)
通过以下方式自动安装Claude Desktop的Neo4j代理内存MCP服务器 史密瑟里:
npx -y @smithery/cli install @knowall-ai/mcp-neo4j-agent-memory --client claude为了发展
- 克隆存储库:
git clone https://github.com/KnowAll-AI/mcp-neo4j-agent-memory.git
cd mcp-neo4j-agent-memory- 安装依赖项:
npm install- 构建项目:
npm run build配置
环境变量
服务器需要以下环境变量:
NEO4J_URI:Neo4j数据库URI(例如。,bolt://localhost:7687)NEO4J_USERNAME:Neo4j用户名(必填)NEO4J_PASSWORD:Neo4j密码(必填)NEO4J_DATABASE:Neo4j数据库名称(可选)-适用于具有多个数据库的Neo4j Enterprise
设置环境变量
为了发展
复制 .env.example 向 .env 并更新您的凭据:
cp .env.example .env
# Edit .env with your Neo4j credentials适用于克劳德桌面
将环境变量添加到Claude Desktop配置中(请参阅上面的快速入门)。
使用示例
LLM处理决定存储什么以及如何连接内存的所有复杂性:
存储信息
User: "Remember that John works at Google as a software engineer"
Assistant: I'll remember that John works at Google as a software engineer.
[Behind the scenes, the LLM does:
1. search_memories({"query": "John"}) - Check if John exists
2. search_memories({"query": "Google"}) - Check if Google exists
3. create_memory({"label": "Person", "properties": {"name": "John", "occupation": "software engineer"}})
4. create_memory({"label": "Organization", "properties": {"name": "Google"}})
5. create_connection({"fromMemoryId": 123, "toMemoryId": 456, "type": "WORKS_AT"})]
User: "Remember that Sarah is John's manager and she started in 2019"
Assistant: I'll add that information about Sarah.
[The LLM searches for John, creates Sarah, and connects them with a MANAGES relationship including the start date]检索信息
User: "Who works at Google?"
Assistant: Let me search for people who work at Google.
[LLM uses: search_memories({"query": "Google", "depth": 2})]
Based on my memory:
- John - Software Engineer at Google
- Sarah - Manager at Google (manages John, started 2019)
User: "What do you remember about John?"
Assistant: Here's what I know about John:
[LLM uses: search_memories({"query": "John", "depth": 2})]
- Works at Google as a Software Engineer
- Sarah is his manager
- [Any other connected memories found in the search]建立关系
User: "John and Sarah are working on Project Atlas together"
Assistant: I'll connect John and Sarah to Project Atlas.
[The LLM:
1. Searches for John and Sarah to get their IDs
2. Creates Project Atlas: create_memory({"label": "Project", "properties": {"name": "Project Atlas"}})
3. Connects them: create_connection({"fromMemoryId": johnId, "toMemoryId": projectId, "type": "WORKS_ON"})
4. create_connection({"fromMemoryId": sarahId, "toMemoryId": projectId, "type": "WORKS_ON"})]连接到特定数据库
对于拥有多个数据库的Neo4j Enterprise用户,您可以指定要连接到哪个数据库:
{
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your-password",
"NEO4J_DATABASE": "myCustomDatabase"
}
}这将连接到“myCustomDatabase”,而不是默认的“neo4j”数据库。
更复杂的示例
查找相关信息
User: "Show me all employees in the Sales department"
Assistant: Let me search for employees in the Sales department.
[LLM uses: search_memories({"query": "Sales department", "depth": 2})]
I found these employees in the Sales department:
- John Smith (Sales Manager)
- Sarah Johnson (Sales Representative)
- Mike Brown (Account Executive)创建特定领域的内存
User: "Create a product called 'Premium Coffee' with price $24.99"
Assistant: I'll create that product for you.
[LLM uses: create_memory({"label": "Product", "properties": {"name": "Premium Coffee", "price": 24.99}})]
Created Premium Coffee product with ID: 456管理关系
User: "The Premium Coffee uses beans from our Colombian Supplier"
Assistant: I'll connect Premium Coffee to the Colombian Supplier.
[LLM:
1. search_memories({"query": "Premium Coffee"})
2. search_memories({"query": "Colombian Supplier"})
3. create_connection({"fromMemoryId": 456, "toMemoryId": 789, "type": "SUPPLIED_BY"})]
Connected Premium Coffee to Colombian Supplier高级查询
LLM可以通过智能地使用搜索工具来处理复杂的查询:
基于单词的搜索
User: "Find Ben Weeks"
Assistant: I'll search for memories containing "Ben" or "Weeks".
[LLM uses: search_memories({"query": "Ben Weeks"})]
I found several people matching your search:
- Ben Weeks - Software Engineer at TechCorp (exact match)
- Sarah Ben - Data Scientist at DataCo (contains "Ben")
- John Weeks - Project Manager (contains "Weeks")
The most likely match appears to be Ben Weeks, the Software Engineer.注意:搜索会从您的查询中找到任何单词,使LLM能够呈现所有潜在的相关结果,并根据上下文确定最佳匹配。
最近的回忆(过去7天)
User: "What new people have I met in the last week?"
Assistant: I'll search for people added to your memory in the last 7 days.
[LLM calculates the date 7 days ago and uses:
search_memories({
"query": "",
"label": "person",
"since_date": "2024-01-20T00:00:00Z",
"order_by": "created_at DESC"
})]
Here are the new people you've met in the last week:
- Sarah Chen - Met at tech conference on Monday
- Dr. Michael Roberts - New physician, first appointment Tuesday
- Emma Wilson - Joined your project team on Wednesday
- James Park - Coffee meeting about potential collaboration Thursday消歧
User: "What does John do?"
Assistant: I found multiple people named John. Let me show you what I know:
[LLM uses: search_memories({"query": "John", "type": "Person", "depth": 1})]
1. John Doe - Software Engineer at Google
2. John Smith - Sales Manager in Sales Department
3. John Brown - Project Manager on Project Atlas
Which John were you asking about?时态查询
User: "What events did I attend last month?"
Assistant: I'll search for event memories and check their dates.
[LLM uses: search_memories({"query": "", "label": "event", "sort_by": "created_at", "sort_order": "desc"})]
[Filters results to last month based on created_at or date properties]
Here are the events you attended last month:
- Tech Innovation Summit (March 5-6) - Keynote speaker
- Team Building Workshop (March 12) - With engineering team
- Client Dinner Meeting (March 18) - Project kickoff with ABC Corp
- WebDev Conference (March 25-27) - Attended 5 sessions on React灵活的内存类型
该系统不强制执行严格类型-您可以创建任何有意义的内存类型:
常见类型 (小写):人、地点、组织、项目、事件、主题、对象、动物、植物、食物、活动、媒体、技能、文件、会议、任务、习惯、健康、车辆、工具、想法、目标
但你可以使用任何类型 (小写):食谱、梦境、记忆、引文、书籍、电影、情感、关系、约会、药物、运动、症状、付款、合同等。
LLM将在适当的时候智能地重用现有类型以保持一致性。
连接的力量
这种记忆系统的真正价值不仅在于存储个人记忆,还在于 在它们之间建立联系当你建立关系时,知识图的用处呈指数级增长:
为什么连接很重要
- 上下文发现:相互关联的记忆提供了孤立事实无法提供的丰富背景
- 关系模式:通过关系分析揭示隐藏的模式和见解
- 时间理解:跟踪关系如何随时间演变
- 网络效应:每个新连接都会增加现有记忆的价值
建立连接的最佳实践
- 始终寻找人际关系 当存储新信息时:
Bad: Just store "John is a developer"
Good: Store John AND connect him to his company, projects, skills, and colleagues- 使用语义关系类型 捕捉意义:
WORKS_AT, MANAGES, KNOWS, LIVES_IN, CREATED, USES, LEARNED_FROM- 添加关系属性 为了获得更丰富的上下文:
create_connection({
"fromMemoryId": 123,
"toMemoryId": 456,
"type": "WORKS_ON",
"properties": {"role": "Lead", "since": "2023-01", "hours_per_week": 20}
})- 用图表思考:在回忆信息时,使用深度>1来探索网络:
search_memories({"query": "John", "depth": 3}) // Explores connections up to 3 hops away记住:没有连接的内存就像图书馆里没有目录的书——它存在,但它的实用性有限。你连接记忆的次数越多,你的知识图谱就越智能、越有用。
测试
运行测试套件:
npm test使用MCP检查器进行交互式测试
对于交互式测试和调试,请使用MCP检查器:
# Quick start with environment variables from .env
./run-inspector.sh
# Or manually with specific environment variables
NEO4J_URI=bolt://localhost:7687 \
NEO4J_USERNAME=neo4j \
NEO4J_PASSWORD=your-password \
npx @modelcontextprotocol/inspector build/index.js检查器提供web UI以:
- 交互式测试所有可用工具
- 查看实时请求/响应数据
- 验证您的Neo4j连接
- 调试工具参数和响应
许可证
麻省理工学院
