Neo4j图形数据库服务器

一个MCP服务器,提供Neo4j图形数据库与Claude Desktop的集成,通过自然语言交互实现图形数据库操作。

  • by da-okazaki
  • TypeScript
  • 本地部署
  • 60 星标
  • 更新于
在 GitHub 查看 da-okazaki/mcp-neo4j-server

使用说明

MCP Neo4j服务器

一个MCP服务器,提供Neo4j图形数据库和Claude Desktop之间的集成,通过自然语言交互实现图形数据库操作。

快速开始

您可以使用npx直接运行此MCP服务器:

npx @alanse/mcp-neo4j

或者将其添加到您的Claude Desktop配置中:

{
  "mcpServers": {
    "neo4j": {
      "command": "npx",
      "args": ["@alanse/mcp-neo4j-server"],
      "env": {
        "NEO4J_URI": "bolt://localhost:7687",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": "your-password",
        "NEO4J_DATABASE": "neo4j"
      }
    }
  }
}

特性

此服务器提供与Neo4j数据库交互的工具:

Neo4j企业支持

此服务器现在支持连接到Neo4j Enterprise Edition中的特定数据库。默认情况下,它连接到“neo4j”数据库,但您可以使用 NEO4J_DATABASE 环境变量。

工具

  • execute_query:在Neo4j数据库上执行Cypher查询

    • 支持所有类型的Cypher查询(READ、CREATE、UPDATE、DELETE)
    • 以结构化格式返回查询结果
    • 可以传递参数以防止注射攻击
  • create_node:在图形数据库中创建新节点

    • 指定节点标签和属性
    • 返回创建的节点及其内部ID
    • 支持属性的所有Neo4j数据类型
  • create_relationship:在两个现有节点之间创建关系

    • 定义关系类型和方向
    • 向关系添加属性
    • 需要源节点和目标节点的节点ID

安装

通过Smithery安装

通过以下方式自动安装适用于Claude Desktop的MCP Neo4j服务器 史密瑟里:

npx -y @smithery/cli install @alanse/mcp-neo4j-server --client claude

为了发展

  1. 克隆存储库:
git clone https://github.com/da-okazaki/mcp-neo4j-server.git
cd mcp-neo4j-server
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

配置

服务器需要以下环境变量:

  • NEO4J_URI:Neo 4 J数据库类型(默认值:bolt://localhost:7687)
  • NEO4J_USERNAME:Neo4j用户名(默认:Neo4j)
  • NEO4J_PASSWORD:Neo4j密码(必填)
  • NEO4J_DATABASE:Neo4j数据库名称(默认:Neo4j)-使用此名称连接到Neo4j Enterprise中的特定数据库

使用示例

以下是使用自然语言与Neo4j数据库交互的示例:

连接到特定数据库

对于拥有多个数据库的Neo4j Enterprise用户,您可以指定要连接到哪个数据库:

{
  "env": {
    "NEO4J_URI": "bolt://localhost:7687",
    "NEO4J_USERNAME": "neo4j",
    "NEO4J_PASSWORD": "your-password",
    "NEO4J_DATABASE": "myCustomDatabase"
  }
}

这将连接到“myCustomDatabase”,而不是默认的“neo4j”数据库。

查询数据

你可以问这样的问题:

  • “显示销售部门的所有员工”
  • “查找前5位最老客户”
  • “谁在上个月购买了3件以上的产品?”

例子:

User: "Show me all employees in the Sales department"

Claude: Let me query the database for Sales department employees.

[Executes query internally: MATCH (e:Employee)-[:WORKS_IN]->(d:Department {name: 'Sales'}) RETURN e.name, e.position]

Result:
- John Smith (Sales Manager)
- Sarah Johnson (Sales Representative)
- Mike Brown (Account Executive)

创建数据

您可以给出如下指示:

  • “添加一个名为John Doe的30岁新用户”
  • “创造一款名为‘高级咖啡’的产品,价格为24.99美元”
  • “添加一个名为“研发”的新部门”

例子:

User: "Add a new person named John Doe who is 30 years old"

Claude: I'll create a new Person node with the provided information.

[Creates node internally with label 'Person' and properties {name: 'John Doe', age: 30}]

Result: Created new person node with ID: 123

建立关系

您可以请求以下关系:

  • “让无名氏和简·史密斯成为朋友”
  • “将产品A设置为产品B的组成部分”
  • “将John Doe分配到销售部门”

例子:

User: "Make John Doe friends with Jane Smith"

Claude: I'll create a friendship relationship between these two people.

[Creates relationship internally: MATCH (a:Person {name: 'John Doe'}), (b:Person {name: 'Jane Smith'})
CREATE (a)-[:FRIENDS_WITH {since: '2024-01-05'}]->(b)]

Result: Created friendship relationship between John Doe and Jane Smith

复杂操作

您可以使用自然语言执行更复杂的操作:

  • “查找居住在纽约的客户购买的所有产品”
  • “给我看看无名氏的朋友”
  • “计算每个部门员工的平均年龄”

例子:

User: "Find all products purchased by customers who live in New York"

Claude: I'll query the database for this information.

[Executes query internally:
MATCH (c:Customer {city: 'New York'})-[:PURCHASED]->(p:Product)
RETURN c.name, collect(p.name) as products]

Result:
- Alice Wilson: [Premium Coffee, Tea Set, Cookies]
- Bob Miller: [Premium Coffee, Water Bottle]

测试

运行测试套件:

npm test

许可证

麻省理工学院