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.
To set up the MCP server, follow these steps:
python3 -m venv myenv
source myenv/Scripts/activate # For Windows
# Or use: source myenv/bin/activate # For Unix/Linux
pip install -r requirements.txt
You can start the MCP server using Uvicorn:
uvicorn ne04j_mcp_server:app --host 0.0.0.0 --port 8000
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
Before using the MCP server with Neo4j, you'll need to populate your database with data. Here are some examples of common Neo4j operations:
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})
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)
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"
// 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)
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:
The MCP protocol handles the standardized communication between the LLM and your Neo4j database, allowing for rich, context-aware interactions with your graph data.
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.
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 > 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"
]
}
}
}
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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