Neo4j Graph Database MCP server

Connects AI systems to Neo4j graph databases for executing Cypher queries, exploring database schemas, and performing complex graph analysis tasks like relationship mapping, path discovery, and community detection.
Back to servers
Setup instructions
Provider
Ujjal Chakraborty
Release date
Mar 09, 2025
Language
Python

This MCP server implementation allows you to connect Neo4j graph databases to Large Language Models using the Model Context Protocol. It provides a standardized way to expose graph data and database operations to LLMs.

Installation

To set up the MCP server, follow these steps:

Prerequisites

  • Python 3.x
  • A Neo4j database instance

Setting Up a Virtual Environment

python3 -m venv myenv
source myenv/Scripts/activate  # For Windows
# Or use: source myenv/bin/activate  # For Unix/Linux

Installing Dependencies

pip install -r requirements.txt

Server Configuration

Running the Server

You can start the MCP server using Uvicorn:

uvicorn ne04j_mcp_server:app --host 0.0.0.0 --port 8000

Client Configuration

To run the client, you'll need to create a .env file with your OpenAI API key:

OPENAI_API_KEY=your_api_key_here

Then you can start the client with:

python fast_mcp_server.py

Data Preparation

Before using the MCP server with Neo4j, you'll need to populate your database with data. Here are some examples of common Neo4j operations:

Creating Nodes

CREATE (p1:Person {name: "Tom Hanks", birthYear: 1956})
CREATE (p2:Person {name: "Kevin Bacon", birthYear: 1958})
CREATE (m1:Movie {title: "Forrest Gump", releaseYear: 1994})
CREATE (m2:Movie {title: "Apollo 13", releaseYear: 1995})

Creating Relationships

MATCH (p:Person {name: "Tom Hanks"}), (m:Movie {title: "Forrest Gump"})
CREATE (p)-[:ACTED_IN]->(m)

MATCH (p:Person {name: "Tom Hanks"}), (m:Movie {title: "Apollo 13"})
CREATE (p)-[:ACTED_IN]->(m)

MATCH (p1:Person {name: "Tom Hanks"}), (p2:Person {name: "Kevin Bacon"})
CREATE (p1)-[:FRIENDS_WITH]->(p2)

Adding Properties

MATCH (p:Person {name: "Tom Hanks"})
SET p.oscarsWon = 2

MATCH (m:Movie {title: "Forrest Gump"})
SET m.genre = "Drama"

MATCH (p:Person {name: "Tom Hanks"})-[r:ACTED_IN]->(m:Movie {title: "Forrest Gump"})
SET r.role = "Forrest Gump"

Creating Complex Structures

// Create a community and then match persons to add them to the community
CREATE (c1:Community {name: "Hollywood Stars"})
WITH c1
MATCH (p:Person)
WHERE p.name IN ["Tom Hanks", "Kevin Bacon"]
CREATE (p)-[:MEMBER_OF]->(c1)

Using the MCP Server

Once your Neo4j database is populated and the MCP server is running, LLMs can interact with your graph data through the Model Context Protocol. This enables AI models to:

  1. Query graph data for context
  2. Run graph analytics
  3. Modify the graph based on user instructions
  4. Visualize relationships between entities

The MCP protocol handles the standardized communication between the LLM and your Neo4j database, allowing for rich, context-aware interactions with your graph data.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "neo4j-graph-database" '{"command":"uvicorn","args":["ne04j_mcp_server:app","--host","0.0.0.0","--port","8000"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "neo4j-graph-database": {
            "command": "uvicorn",
            "args": [
                "ne04j_mcp_server:app",
                "--host",
                "0.0.0.0",
                "--port",
                "8000"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "neo4j-graph-database": {
            "command": "uvicorn",
            "args": [
                "ne04j_mcp_server:app",
                "--host",
                "0.0.0.0",
                "--port",
                "8000"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later