MCP Neo4j 知识图谱内存服务器是一款强大的工具,它能让你轻松地管理和查询知识图谱数据。通过集成 Neo4j 图数据库,该服务器提供了高效的数据存储和快速查询功能,满足各种知识图谱应用场景的需求。
首先,你需要安装并配置 MCP Neo4j 知识图谱内存服务器,然后就可以开始使用它来管理和查询知识图谱数据了。
npm install mcp-neo4j
git clone https://github.com/your-repository.git
cd mcp-neo4j
npm install
设置以下环境变量以配置服务器行为:
| 变量名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
MCP_PORT |
整数 | 3000 | 服务运行的端口 |
MCP_DB_URI |
字符串 | http://localhost:7474 |
Neo4j 数据库 URI |
MCP_DB_USER |
字符串 | neo4j |
数据库用户名 |
MCP_DB_PASSWORD |
字符串 | password |
数据库密码 |
export MCP_PORT=3001
export MCP_DB_URI=http://localhost:7687
| 命令 | 描述 | 示例 |
|---|---|---|
get_current_database |
返回当前活动数据库 | get_current_database |
switch_database |
切换到不同的数据库,可选创建新数据库 | switch_database my-project true |
list_databases |
列出所有可用数据库 | list_databases |
在 JavaScript 中使用:
const { MemoryKnowledgeGraph } = require('mcp-neo4j');
const graph = new MemoryKnowledgeGraph({
port: 3000,
dbUri: 'http://localhost:7474',
dbUser: 'neo4j',
dbPassword: 'password'
});
// 查询知识图谱
async function queryKnowledgeGraph() {
const results = await graph.search('查找用户信息');
console.log(results);
}
queryKnowledgeGraph();
const results = await graph.fuzzySearch('部分匹配内容');
graphGetCurrentDatabase(): Promise;
graphSwitchDatabase(newDbName: string, createIfNotExists: boolean): Promise<void>;
graphListDatabases(): Promise;
知识图谱存储在 Neo4j 中,以下是架构图:
graph TD
E[实体] -->|HAS_OBSERVATION| O[观察]
E1[实体] -->|RELATES_TO| E2[实体]
P[项目] -->|CONTAINS| F[文件]
F -->|HAS_FUNCTION| Fn[函数]
F -->|HAS_CLASS| C[类]
P -->|HAS_ERROR| Er[错误]
P -->|HAS_REQUIREMENT| R[需求]
classDef entity fill:#f9f,stroke:#333,stroke-width:2px;
classDef observation fill:#bbf,stroke:#333,stroke-width:1px;
classDef project fill:#fdf,stroke:#333,stroke-width:3px;
classDef file fill:#fff,stroke:#333,stroke-width:1px;
classDef function fill:#ffw,stroke:#333,stroke-width:1px;
classDef error fill:#fww,stroke:#333,stroke-width:1px;
classDef requirement fill:#www,stroke:#333,stroke-width:1px;
E, E1, E2 -> entity
O -> observation
P -> project
F -> file
Fn -> function
Er -> error
R -> requirement
pnpm install
npm test
npm run build
MIT License