The MCP Neo4j Knowledge Graph Memory Server leverages Neo4j's graph database capabilities to store and retrieve information from AI assistant-user interactions. It provides enhanced functionality compared to the official Knowledge Graph Memory Server by offering more powerful graph querying, better performance, and scalability - ideal for complex knowledge graph applications.
# Global installation
npm install -g @jovanhsu/mcp-neo4j-memory-server
# Or as a project dependency
npm install @jovanhsu/mcp-neo4j-memory-server
# Start Neo4j and Memory Server with docker-compose
git clone https://github.com/JovanHsu/mcp-neo4j-memory-server.git
cd mcp-neo4j-memory-server
docker-compose up -d
The server uses the following environment variables:
Variable | Description | Default Value |
---|---|---|
NEO4J_URI | Neo4j database URI | bolt://localhost:7687 |
NEO4J_USER | Neo4j username | neo4j |
NEO4J_PASSWORD | Neo4j password | password |
NEO4J_DATABASE | Neo4j database name | neo4j |
Add the following to your claude_desktop_config.json
:
{
"mcpServers": {
"graph-memory": {
"command": "npx",
"args": [
"-y",
"@izumisy/mcp-neo4j-memory-server"
],
"env": {
"NEO4J_URI": "neo4j://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "password",
"NEO4J_DATABASE": "memory"
}
}
}
}
npx @jovanhsu/mcp-neo4j-memory-server
npx @modelcontextprotocol/inspector npx @jovanhsu/mcp-neo4j-memory-server
Add the following to your Claude custom instructions:
Follow these steps for each interaction:
1. User Identification:
- You should assume that you are interacting with default_user
- If you have not identified default_user, proactively try to do so.
2. Memory Retrieval:
- Always begin your chat by saying only "Remembering..." and search relevant information from your knowledge graph
- Create a search query from user words, and search things from "memory". If nothing matches, try to break down words in the query at first ("A B" to "A" and "B" for example).
- Always refer to your knowledge graph as your "memory"
3. Memory
- While conversing with the user, be attentive to any new information that falls into these categories:
a) Basic Identity (age, gender, location, job title, education level, etc.)
b) Behaviors (interests, habits, etc.)
c) Preferences (communication style, preferred language, etc.)
d) Goals (goals, targets, aspirations, etc.)
e) Relationships (personal and professional relationships up to 3 degrees of separation)
4. Memory Update:
- If any new information was gathered during the interaction, update your memory as follows:
a) Create entities for recurring organizations, people, and significant events
b) Connect them to the current entities using relations
b) Store facts about them as observations
To use this server in your own application via the MCP protocol:
import { McpClient } from '@modelcontextprotocol/sdk/client/mcp.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
// Create client
const transport = new StdioClientTransport({
command: 'npx',
args: ['-y', '@izumisy/mcp-neo4j-memory-server'],
env: {
NEO4J_URI: 'bolt://localhost:7687',
NEO4J_USER: 'neo4j',
NEO4J_PASSWORD: 'password',
NEO4J_DATABASE: 'neo4j'
}
});
const client = new McpClient();
await client.connect(transport);
// Create entities
const result = await client.callTool('create_entities', {
entities: [
{
name: 'User',
entityType: 'Person',
observations: ['Likes programming', 'Uses TypeScript']
}
]
});
console.log(result);
The knowledge graph is stored in Neo4j using the following model:
(Entity:EntityType {name: "Entity Name"})
(Entity)-[:HAS_OBSERVATION]->(Observation {content: "Observation content"})
(Entity1)-[:RELATION_TYPE]->(Entity2)
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.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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.
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.