neo4j-mcp-readonly
Enables read-only access to Neo4j databases via the Model Context Protocol, allowing safe Cypher queries, schema exploration, and database statistics.
README
Neo4j MCP Server
A Model Context Protocol (MCP) server that provides read-only access to your Neo4j database. This server allows you to connect Cursor IDE to your Neo4j database and run safe, read-only Cypher queries with comprehensive database exploration tools.
๐ Quick Start
Installation
# Install globally
npm install -g neo4j-mcp-readonly
# Or use with npx (no installation required)
npx neo4j-mcp-readonly --help
Basic Usage
# Start with command line arguments
neo4j-mcp-readonly --neo4j-uri bolt://localhost:7687 --neo4j-username neo4j --neo4j-password mypassword
# Or use environment variables
NEO4J_URI=bolt://localhost:7687 NEO4J_USERNAME=neo4j NEO4J_PASSWORD=mypassword neo4j-mcp-readonly
๐ Features
- ๐ Read-only queries: Only allows safe read operations (MATCH, RETURN, WITH, UNWIND, etc.)
- ๐ก๏ธ Query validation: Automatically blocks dangerous operations like CREATE, DELETE, SET, MERGE
- ๐ Schema exploration: Get database schema information including labels, relationships, and properties
- ๐ Database statistics: Node/relationship counts, property analysis, and more
- ๐งช Connection testing: Built-in connection testing functionality
- โก CLI support: Easy command-line configuration
- ๐ณ Docker ready: Example Docker Compose configuration included
- ๐ง Flexible auth: Support for environment variables and command-line arguments
๐ ๏ธ Configuration Methods
Method 1: Command Line Arguments
neo4j-mcp-readonly \
--neo4j-uri bolt://localhost:7687 \
--neo4j-username neo4j \
--neo4j-password your_password
Method 2: Environment Variables
export NEO4J_URI=bolt://localhost:7687
export NEO4J_USERNAME=neo4j
export NEO4J_PASSWORD=your_password
neo4j-mcp-readonly
Method 3: Mixed Approach
# Environment for sensitive data, CLI for the rest
export NEO4J_PASSWORD=your_secure_password
neo4j-mcp-readonly --neo4j-uri bolt://myserver:7687 --neo4j-username myuser
๐ฏ Usage with Cursor IDE
Option 1: Using npx (Recommended)
Add this to your Cursor MCP settings:
{
"mcpServers": {
"neo4j": {
"command": "npx",
"args": [
"neo4j-mcp-readonly",
"--neo4j-uri", "bolt://localhost:7687",
"--neo4j-username", "neo4j",
"--neo4j-password", "your_password_here"
]
}
}
}
Option 2: Using Environment Variables
{
"mcpServers": {
"neo4j": {
"command": "npx",
"args": ["neo4j-mcp-readonly"],
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your_password_here"
}
}
}
}
Option 3: Minimal Setup (Password Only)
For simple local setups where you only need to specify the password:
{
"mcpServers": {
"neo4j": {
"command": "npx",
"args": ["neo4j-mcp-readonly", "--neo4j-password", "your_password_here"]
}
}
}
This assumes default values: bolt://localhost:7687 and username neo4j.
Configuration Steps
-
Install the package (if not using npx):
npm install -g neo4j-mcp-readonly -
Add MCP server to Cursor:
- Open Cursor IDE
- Go to Cursor Settings (Cmd/Ctrl + ,)
- Search for "MCP" or go to Extensions > MCP
- Add the configuration (see examples above)
-
Restart Cursor for changes to take effect
-
Start querying:
Can you show me the schema of my Neo4j database? How many User nodes do I have? Show me sample data for the Movie label
๐ ๏ธ Available Tools
Core Tools
| Tool | Description | Parameters |
|---|---|---|
neo4j_query |
Execute read-only Cypher queries | query (required), parameters (optional) |
neo4j_schema |
Get database schema (labels, relationships, properties) | None |
neo4j_test_connection |
Test database connectivity | None |
Analysis Tools
| Tool | Description | Parameters |
|---|---|---|
neo4j_node_count |
Count nodes by label or total | label (optional) |
neo4j_relationship_count |
Count relationships by type or total | type (optional) |
neo4j_database_info |
Get Neo4j version, edition, and statistics | None |
neo4j_sample_data |
Get sample data for exploration | label OR relationshipType, limit (optional, max 50) |
Schema Analysis Tools
| Tool | Description | Parameters |
|---|---|---|
neo4j_indexes |
List all database indexes | None |
neo4j_constraints |
List all database constraints | None |
neo4j_node_properties |
Analyze properties of a node label | label (required) |
neo4j_relationship_properties |
Analyze properties of a relationship type | type (required) |
๐ก Example Queries
Basic Data Exploration
MATCH (n:Person) RETURN n.name, n.age LIMIT 10
Relationship Analysis
MATCH (p:Person)-[r:FRIENDS_WITH]->(f:Person)
RETURN p.name, f.name, r.since
Property-based Filtering
MATCH (m:Movie)
WHERE m.year > 2000
RETURN m.title, m.year
ORDER BY m.year DESC
๐ Security Features
Allowed Operations
MATCH- Pattern matchingRETURN- Return resultsWITH- Chain query partsUNWIND- Expand listsSHOW- Show database metadata- Read-only
CALLprocedures (schema, labels, etc.)
Blocked Operations
CREATE- Creating nodes/relationshipsDELETE/DETACH DELETE- Deleting dataMERGE- Creating or matchingSET- Setting propertiesREMOVE- Removing properties/labelsDROP- Dropping indexes/constraintsALTER- Altering schema- Most
CALLprocedures (except read-only ones)
๐ณ Docker Setup
Use the provided Docker Compose example:
# Copy the example
cp examples/docker-compose.yml .
# Edit password in docker-compose.yml
# Then start Neo4j
docker-compose up -d
# Connect with MCP server
neo4j-mcp-readonly --neo4j-password your_password_here
๐ง Development
Local Development
git clone https://github.com/ThisIsVoid/neo4j-mcp-readonly.git
cd neo4j-mcp-readonly
npm install
npm run build
npm run dev
Building
npm run build
Testing
# Test connection
neo4j-mcp-readonly --help
# Test with your database
NEO4J_PASSWORD=test neo4j-mcp-readonly
๐ Advanced Configuration
Custom Neo4j Configurations
# Neo4j Aura
neo4j-mcp-readonly \
--neo4j-uri neo4j+s://xxxx.databases.neo4j.io \
--neo4j-username neo4j \
--neo4j-password your_aura_password
# Neo4j Enterprise with custom port
neo4j-mcp-readonly \
--neo4j-uri bolt://enterprise-server:7687 \
--neo4j-username readonly_user \
--neo4j-password readonly_password
# Local Neo4j with custom database
neo4j-mcp-readonly \
--neo4j-uri bolt://localhost:7687/movies \
--neo4j-username neo4j \
--neo4j-password mypassword
Environment File Setup
Create a .env file:
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_secure_password
Then run:
source .env
neo4j-mcp-readonly
๐จ Troubleshooting
Connection Issues
-
Verify Neo4j is running:
# Check if Neo4j is listening netstat -an | grep 7687 -
Test direct connection:
# Use Neo4j's cypher-shell cypher-shell -u neo4j -p your_password -
Check firewall/network:
- Ensure port 7687 is accessible
- Check if authentication is required
Configuration Issues
-
Invalid credentials:
Configuration error: neo4j.password: Password is requiredSolution: Provide password via
--neo4j-passwordorNEO4J_PASSWORD -
Connection refused:
Failed to connect to Neo4j: ServiceUnavailableSolution: Check URI and ensure Neo4j is running
MCP Issues
-
Server not found in Cursor:
- Verify npx can find the package:
npx neo4j-mcp-readonly --help - Check Cursor MCP configuration syntax
- Restart Cursor after configuration changes
- Verify npx can find the package:
-
Query blocked:
Query contains forbidden operationsSolution: Ensure query only contains allowed read operations
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Publishing to NPM
Publishing to NPM is free for open source packages. Here's how to publish:
First Time Setup
- Create NPM account: Visit npmjs.com and sign up
- Login locally:
npm login - Update package.json: Change repository URLs to your GitHub repo
Publishing
# Build the package
npm run build
# Publish (runs prepublishOnly script automatically)
npm publish
# For beta versions
npm publish --tag beta
Updating
# Update version
npm version patch # or minor, major
# Publish update
npm publish
๐ Star History
If this project helps you, please consider giving it a star on GitHub!
๐ Support
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: This README and inline code comments
- ๐ฏ Examples: Check the
/examplesdirectory
Made with โค๏ธ for the Neo4j and Cursor communities
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.