Neo4j Knowledge Graph Memory
STDIONeo4j graph database MCP server providing persistent memory capabilities with relationship tracking and knowledge storage
Neo4j graph database MCP server providing persistent memory capabilities with relationship tracking and knowledge storage
A Model Context Protocol (MCP) server implementation that provides persistent memory capabilities through Neo4j graph database integration.
By storing information in a graph structure, this server maintains complex relationships between entities as memory nodes and enables long-term retention of knowledge that can be queried and analyzed across multiple conversations or sessions.
With Neo4j Aura you can host your own database server for free or share it with your collaborators. Otherwise you can run your own Neo4j server locally.
The MCP server leverages Neo4j's graph database capabilities to create an interconnected knowledge base that serves as an external memory system. Through Cypher queries, it allows exploration and retrieval of stored information, relationship analysis between different data points, and generation of insights from the accumulated knowledge. This memory can be further enhanced with Claude's capabilities.
Memory - A node representing an entity with a name, type, and observations.Relationship - A relationship between two entities with a type.Let's add some memories 
I, Michael, living in Dresden, Germany work at Neo4j which is headquartered in Sweden with my colleagues Andreas (Cambridge, UK) and Oskar (Gothenburg, Sweden)
I work in Product Management, Oskar in Engineering and Andreas in Developer Relations.
Results in Claude calling the create_entities and create_relations tools.


The server offers these core tools:
read_graph
search_nodes
query (string): Search query matching names, types, observationsfind_nodes
names (array of strings): Entity names to retrievecreate_entities
entities: Array of objects with:
name (string): Name of the entitytype (string): Type of the entityobservations (array of strings): Initial observations about the entitydelete_entities
entityNames (array of strings): Names of entities to deletecreate_relations
relations: Array of objects with:
source (string): Name of source entitytarget (string): Name of target entityrelationType (string): Type of relationdelete_relations
relations: Array of objects with same schema as create_relationsadd_observations
observations: Array of objects with:
entityName (string): Entity to add tocontents (array of strings): Observations to adddelete_observations
deletions: Array of objects with:
entityName (string): Entity to delete fromobservations (array of strings): Observations to removepip install mcp-neo4j-memory
Add the server to your claude_desktop_config.json with configuration of:
"mcpServers": { "neo4j": { "command": "uvx", "args": [ "[email protected]", "--db-url", "neo4j+s://xxxx.databases.neo4j.io", "--username", "<your-username>", "--password", "<your-password>" ] } }
Alternatively, you can set environment variables:
"mcpServers": { "neo4j": { "command": "uvx", "args": [ "[email protected]" ], "env": { "NEO4J_URL": "neo4j+s://xxxx.databases.neo4j.io", "NEO4J_USERNAME": "<your-username>", "NEO4J_PASSWORD": "<your-password>" } } }
For multi-tenant deployments, add --namespace to prefix tool names:
"args": [ "[email protected]", "--namespace", "myapp", "--db-url", "..." ]
Tools become: myapp-read_graph, myapp-create_entities, etc.
Can also use NEO4J_NAMESPACE environment variable.
The server supports HTTP transport for web-based deployments and microservices:
# Basic HTTP mode (defaults: host=127.0.0.1, port=8000, path=/mcp/) mcp-neo4j-memory --transport http # Custom HTTP configuration mcp-neo4j-memory --transport http --host 127.0.0.1 --port 8080 --path /api/mcp/
Environment variables for HTTP configuration:
export NEO4J_TRANSPORT=http export NEO4J_MCP_SERVER_HOST=127.0.0.1 export NEO4J_MCP_SERVER_PORT=8080 export NEO4J_MCP_SERVER_PATH=/api/mcp/ export NEO4J_NAMESPACE=myapp mcp-neo4j-memory
The server supports three transport modes:
"mcpServers": { "neo4j": { "command": "docker", "args": [ "run", "--rm", "-e", "NEO4J_URL=neo4j+s://xxxx.databases.neo4j.io", "-e", "NEO4J_USERNAME=<your-username>", "-e", "NEO4J_PASSWORD=<your-password>", "mcp/neo4j-memory:0.4.1" ] } }
The server includes comprehensive security protection with secure defaults that protect against common web-based attacks while preserving full MCP functionality when using HTTP transport.
TrustedHost Middleware validates Host headers to prevent DNS rebinding attacks:
Secure by Default:
localhost and 127.0.0.1 hosts are allowed by defaultEnvironment Variable:
export NEO4J_MCP_SERVER_ALLOWED_HOSTS="example.com,www.example.com"
Cross-Origin Resource Sharing (CORS) protection blocks browser-based requests by default:
Environment Variable:
export NEO4J_MCP_SERVER_ALLOW_ORIGINS="https://example.com,https://app.example.com"
Development Setup:
mcp-neo4j-memory --transport http \ --allowed-hosts "localhost,127.0.0.1" \ --allow-origins "http://localhost:3000"
Production Setup:
mcp-neo4j-memory --transport http \ --allowed-hosts "example.com,www.example.com" \ --allow-origins "https://example.com,https://app.example.com"
For allow_origins:
["https://example.com", "https://example.com"]"*" in production with credentialsFor allowed_hosts:
["example.com", "www.example.com"]"*" unless you understand the risksThe Neo4j Memory MCP server can be deployed using Docker for remote deployments. Docker deployment should use HTTP transport for web accessibility. In order to integrate this deployment with applications like Claude Desktop, you will have to use a proxy in your MCP configuration such as mcp-remote.
After building locally with docker build -t mcp-neo4j-memory:latest .:
# Run with http transport (default for Docker) docker run --rm -p 8000:8000 \ -e NEO4J_URI="bolt://host.docker.internal:7687" \ -e NEO4J_USERNAME="neo4j" \ -e NEO4J_PASSWORD="password" \ -e NEO4J_DATABASE="neo4j" \ -e NEO4J_TRANSPORT="http" \ -e NEO4J_MCP_SERVER_HOST="0.0.0.0" \ -e NEO4J_MCP_SERVER_PORT="8000" \ -e NEO4J_MCP_SERVER_PATH="/mcp/" \ mcp/neo4j-memory:latest # Run with security middleware for production docker run --rm -p 8000:8000 \ -e NEO4J_URI="bolt://host.docker.internal:7687" \ -e NEO4J_USERNAME="neo4j" \ -e NEO4J_PASSWORD="password" \ -e NEO4J_DATABASE="neo4j" \ -e NEO4J_TRANSPORT="http" \ -e NEO4J_MCP_SERVER_HOST="0.0.0.0" \ -e NEO4J_MCP_SERVER_PORT="8000" \ -e NEO4J_MCP_SERVER_PATH="/mcp/" \ -e NEO4J_MCP_SERVER_ALLOWED_HOSTS="example.com,www.example.com" \ -e NEO4J_MCP_SERVER_ALLOW_ORIGINS="https://example.com" \ mcp/neo4j-memory:latest
| Variable | Default | Description | 
|---|---|---|
NEO4J_URI | bolt://localhost:7687 | Neo4j connection URI | 
NEO4J_USERNAME | neo4j | Neo4j username | 
NEO4J_PASSWORD | password | Neo4j password | 
NEO4J_DATABASE | neo4j | Neo4j database name | 
NEO4J_TRANSPORT | stdio (local), http (remote) | Transport protocol (stdio, http, or sse) | 
NEO4J_MCP_SERVER_HOST | 127.0.0.1 (local) | Host to bind to | 
NEO4J_MCP_SERVER_PORT | 8000 | Port for HTTP/SSE transport | 
NEO4J_MCP_SERVER_PATH | /mcp/ | Path for accessing MCP server | 
NEO4J_MCP_SERVER_ALLOW_ORIGINS | (empty - secure by default) | Comma-separated list of allowed CORS origins | 
NEO4J_MCP_SERVER_ALLOWED_HOSTS | localhost,127.0.0.1 | Comma-separated list of allowed hosts (DNS rebinding protection) | 
NEO4J_NAMESPACE | (empty - no prefix) | Namespace prefix for tool names (e.g., myapp-read_graph) | 
When using SSE transport (for legacy web clients), the server exposes an HTTP endpoint:
# Start the server with SSE transport docker run -d -p 8000:8000 \ -e NEO4J_URI="neo4j+s://demo.neo4jlabs.com" \ -e NEO4J_USERNAME="recommendations" \ -e NEO4J_PASSWORD="recommendations" \ -e NEO4J_DATABASE="neo4j" \ -e NEO4J_TRANSPORT="sse" \ -e NEO4J_MCP_SERVER_HOST="0.0.0.0" \ -e NEO4J_MCP_SERVER_PORT="8000" \ --name neo4j-memory-mcp-server \ mcp-neo4j-memory:latest # Test the SSE endpoint curl http://localhost:8000/sse # Use with MCP Inspector npx @modelcontextprotocol/inspector http://localhost:8000/sse
uv (Universal Virtualenv):# Using pip pip install uv # Using Homebrew on macOS brew install uv # Using cargo (Rust package manager) cargo install uv
# Clone the repository git clone https://github.com/yourusername/mcp-neo4j-memory.git cd mcp-neo4j-memory # Create and activate virtual environment using uv uv venv source .venv/bin/activate # On Unix/macOS .venv\Scripts\activate # On Windows # Install dependencies including dev dependencies uv pip install -e ".[dev]"
Build and run the Docker container:
# Build the image docker build -t mcp/neo4j-memory:latest . # Run the container docker run -e NEO4J_URL="neo4j+s://xxxx.databases.neo4j.io" \ -e NEO4J_USERNAME="your-username" \ -e NEO4J_PASSWORD="your-password" \ mcp/neo4j-memory:latest
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.