N

Neo4j Graph Database MCP Server

Connect Claude Code to Neo4j for graph database operations. Explore schemas, run Cypher queries, visualize relationships, and get query optimization advice through the Model Context Protocol.

MCPCommunitydatabasev1.0.0MIT
0 views0 copies

MCP Server Configuration

Add to .claude/settings.json:

{ "mcpServers": { "neo4j": { "command": "npx", "args": ["-y", "@neo4j/mcp-neo4j"], "env": { "NEO4J_URI": "bolt://localhost:7687", "NEO4J_USERNAME": "neo4j", "NEO4J_PASSWORD": "${NEO4J_PASSWORD}", "NEO4J_DATABASE": "neo4j" } } } }

Available Tools

ToolDescription
get-schemaRetrieve the full graph schema (node labels, relationship types, properties)
run-cypherExecute a Cypher query and return results
explain-queryGet the execution plan for a Cypher query
get-node-countCount nodes by label
get-relationship-countCount relationships by type

Common Cypher Patterns

Schema Exploration

// List all node labels with counts CALL db.labels() YIELD label RETURN label, size((:` + label + `)) AS count ORDER BY count DESC; // List all relationship types CALL db.relationshipTypes() YIELD relationshipType RETURN relationshipType; // Show property keys for a label MATCH (n:User) WITH n LIMIT 1 RETURN keys(n) AS properties;

Common Queries

// Find shortest path between two nodes MATCH path = shortestPath( (a:User {name: 'Alice'})-[*..6]-(b:User {name: 'Bob'}) ) RETURN path; // Recommendation engine: users who liked similar items MATCH (user:User {id: $userId})-[:LIKED]->(item:Item)<-[:LIKED]-(other:User) WITH other, count(item) AS commonLikes ORDER BY commonLikes DESC LIMIT 10 MATCH (other)-[:LIKED]->(rec:Item) WHERE NOT (user)-[:LIKED]->(rec) RETURN rec.name, count(other) AS score ORDER BY score DESC LIMIT 5; // Find circular dependencies MATCH path = (n:Module)-[:DEPENDS_ON*2..5]->(n) RETURN path;

Performance Tips

// Create indexes for frequently queried properties CREATE INDEX user_email FOR (u:User) ON (u.email); CREATE INDEX item_name FOR (i:Item) ON (i.name); // Use PROFILE to analyze query performance PROFILE MATCH (u:User)-[:PURCHASED]->(p:Product) WHERE u.country = 'US' RETURN p.category, count(*) AS purchases ORDER BY purchases DESC;

Setup

  1. Install Neo4j: brew install neo4j (macOS) or use Docker:
    docker run -d --name neo4j \ -p 7474:7474 -p 7687:7687 \ -e NEO4J_AUTH=neo4j/your-password \ neo4j:latest
  2. Set the NEO4J_PASSWORD environment variable
  3. Add the MCP configuration to .claude/settings.json
  4. Access Neo4j Browser at http://localhost:7474 for visual exploration

Security Notes

  • Store database credentials in environment variables, never in settings.json directly
  • Use a read-only user for exploration if you want to prevent accidental mutations
  • The MCP server connects over Bolt protocol (encrypted by default in production)
  • Consider using a dedicated database user with limited permissions for MCP access
  • Avoid running DELETE or DETACH DELETE queries through MCP without careful review
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates