知识图谱MCP-快速入门
⚡ 快速设置
所有命令都从项目根运行 (knowledge-graph-mcp-v2/),不是从 src/ 文件夹:
# 1. Configure (PROJECT ROOT)
cd /path/to/knowledge-graph-mcp-v2
cp .env-complete .env
# Edit .env: NEO4J_PASSWORD=your_secure_password_here
# 2. Start database (PROJECT ROOT)
docker compose up -d
# 3. Install Python deps (PROJECT ROOT)
uv sync
# 4. Run MCP server (PROJECT ROOT)
uv run knowledge-graph-mcp完成!Docker中的Neo4j,本地运行的MCP服务器,都在同一个网络上。
______________________________________________________________________
⚠️ 重要提示:文件夹结构
knowledge-graph-mcp-v2/ ← PROJECT ROOT (run commands here)
├── .env ← Config file
├── .env-complete
├── docker-compose.yml
├── pyproject.toml
├── README-QUICK.md
├── src/ ← Source code (don't run commands here)
│ └── knowledge_graph_mcp/
│ ├── __init__.py
│ ├── server.py
│ └── ...❌ 错误:
cd knowledge-graph-mcp-v2/src
uv run knowledge-graph-mcp # ❌ Won't work✅ 对的:
cd knowledge-graph-mcp-v2
uv run knowledge-graph-mcp # ✅ Works______________________________________________________________________
🗄️ 数据库访问
| 服务 | URL | 凭据 |
|---|---|---|
| Neo4j浏览器 | http://localhost:7474 | neo4j / ${NEO4J_PASSWORD} |
| 螺栓(代码) | bolt://localhost:7687 | 与上述相同 |
导入到.env:
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_secure_password_here______________________________________________________________________
🔗 连接到克劳德桌面
- 编辑Claude配置 (
~/Library/Application Support/Claude/claude_desktop_config.json在Mac上):
{
"mcpServers": {
"knowledge-graph": {
"command": "uv",
"args": [
"--directory",
"/path/to/knowledge-graph-mcp-v2",
"run",
"knowledge-graph-mcp"
],
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "your_secure_password_here"
}
}
}
}- 重新启动克劳德桌面 → 它连接到本地MCP服务器进程
- 在Claude中使用:
"Remember: API rate limit is 1000 req/min"
"What did I tell you about the API?"______________________________________________________________________
🔗 连接到光标
选项1:通过MCP服务器(推荐)
- 与Claude桌面配置相同
- 编辑光标MCP设置(请参阅光标文档)
方案2:通过克劳德API
- 在Cursor中使用Claude扩展名
- MCP服务器在本地运行,Cursor通过stdio连接
______________________________________________________________________
📊 可视化数据
Neo4j浏览器:
# Open: http://localhost:7474
# Login: neo4j / your_password
# Run Cypher:
MATCH (p:Profile) RETURN p LIMIT 10
MATCH (p:Profile)-[:HAS_CATEGORY]->(c:Category)-[:HAS_FACT]->(f:Fact) RETURN *______________________________________________________________________
🛠️ MCP服务器工具
| 工具 | 输入 | 目的 |
|---|---|---|
store_fact | fact, profile_id, category | 用嵌入存储知识 |
query_knowledge | query, profile_id, top_k | 语义搜索 |
list_profiles | - | 查找所有配置文件 |
list_categories | profile_id | 在个人资料中查找类别 |
______________________________________________________________________
📁 项目文件
knowledge-graph-mcp-v2/
├── .env ← Config (edit this)
├── docker-compose.yml ← DB setup
├── pyproject.toml ← Dependencies
├── src/ ← MCP server code
├── README.md ← Full docs
├── ARCHITECTURE_GUIDE.md ← Deep dive
└── SETUP_GUIDE.md ← Detailed setup______________________________________________________________________
✅ 验证设置
# 1. Neo4j running?
docker ps | grep neo4j
# Should show status: "healthy"
# 2. MCP server running?
# Terminal should show: "Server running on stdio"
# 3. Test in Claude Desktop:
# Try: "Remember: test data 123"
# Then: "What did I tell you?"
# Should work immediately______________________________________________________________________
🔑 重要港口和证书
- Neo4j端口:
7687(代码采用Bolt协议) - Neo4j浏览器:
7474(UI可视化) - 用户名:
neo4j(固定) - 密码:
${NEO4J_PASSWORD}(在.env中设置) - 嵌入模型:
all-MiniLM-L6-v2(自动下载,缓存)
______________________________________________________________________
🚨 常见问题
| 问题 | 解决方案 |
|---|---|
| “连接被拒绝” | 等待30秒,检查: docker logs knowledge-graph-neo4j |
| “身份验证失败” | 验证 NEO4J_PASSWORD 在 .env |
| “端口7687正在使用中” | 更改 docker-compose.yml: "7688:7687" |
| “首次嵌入缓慢” | 正常(约2分钟),模型缓存后 |
______________________________________________________________________
📖 需要更多?
- 完整文档: 看这个 博客
