Databases·
advanced
·14 min read·Jul 9, 2026·Updated Oct 10, 2026
By Rad Tome·Lead AI Systems Architect·How we verify this

Neo4j Knowledge Graph MCP Server Guide

Connect Neo4j knowledge graphs to AI agents via MCP. Run Cypher queries, traverse entity relationships, and build structured GraphRAG pipelines.

neo4jgraph databasecypherknowledge graphgraphragmodel context protocoldatabases
Config Target: claude_desktop_config.json
{
  "mcpServers": {
    "neo4j": {
      "command": "uvx",
      "args": [
        "mcp-neo4j"
      ],
      "env": {
        "NEO4J_URI": "bolt://",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": ""
      }
    }
  }
}
Interactive Tool
1-Click Export

Generate & Test Neo4j Graph MCP Server Config

One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.

Open in Generator

Neo4j Knowledge Graph MCP Server Guide

Vector search and lexical matching are foundational primitives in modern artificial intelligence development. However, vector distance functions compute similarity across isolated chunks of text. When an autonomous software engineering agent needs to deduce multi-hop relational dependencies—such as "Which microservices will experience breaking API contracts if team Payments deprecates the BillingAccount entity?"—vector search frequently fails.

Graph databases like Neo4j excel at modeling complex interconnected networks using discrete Nodes, labeled Edges, and structured properties. By connecting Neo4j to artificial intelligence hosts through a Model Context Protocol (MCP) server, agents operating in Claude Desktop, Cursor, and OpenAI Codex CLI gain native graph traversal capabilities. Agents can execute Cypher queries, discover transitive entity relationships, and maintain enterprise architectural graphs in real time.


1. Problem Statement and Architecture

Implementing ad-hoc GraphRAG pipelines directly inside prompting loops presents several critical engineering hurdles:

  1. ▸Hallucinatory Cypher Syntax: Frontier models frequently hallucinate non-existent node labels, relationship types, or unsupported Cypher syntax when writing freeform database queries.
  2. ▸Unbounded Graph Scans: Naive queries such as MATCH (n)-[r]->(m) RETURN * can inadvertently traverse millions of graph edges, locking database threads and exhausting client memory buffers.
  3. ▸Session State Isolation: Engineering agents working across different terminals require a centralized, transactional source of truth for organizational facts and system component taxonomies.
code
+-----------------------------------------------------------------------------------+
|                              Host Boundary                                        |
|                                                                                   |
|  +--------------------+        JSON-RPC 2.0 (stdio)        +-------------------+  |
|  |  Claude / Cursor   | <================================> |  neo4j-graph-mcp  |  |
|  +--------------------+                                    +---------+---------+  |
+----------------------------------------------------------------------|------------+
                                                                       | Bolt Protocol
                                                                       | (bolt://7687)
                                                                       v
                                                             +-------------------+
                                                             | Neo4j Aura / DBMS |
                                                             | (Nodes and Edges) |
                                                             +-------------------+

The Neo4j MCP server wraps the official neo4j-driver using the Model Context Protocol TypeScript SDK. Instead of exposing raw database handles, it provides schema-constrained tools for executing read-only Cypher queries, inspecting database schemas, and upserting parameterized entity relationships with transactional safety.


2. Prerequisites and Environment Matrix

Running the Neo4j MCP server requires Node.js 18 or later and access to a running Neo4j instance (local Docker container or cloud-managed Neo4j AuraDB).

ComponentMinimum VersionRecommendedNotes
Node.js18.18.0+20.x LTS or 22.xRuntime for the MCP daemon
Neo4j DBMS5.15.0+5.25+ or AuraDBNative graph database engine
Bolt Protocol5.xLatestBinary transport between driver and Neo4j
Claude Desktop0.7.0+LatestSupported desktop client
Cursor IDE0.42.0+LatestAgent composer tool runner
OpenAI Codex CLI0.1.0+LatestTerminal-driven workflow harness

Launch a local Neo4j Community instance via Docker:

bash
docker run -d --name neo4j \
  -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/DevelopmentSecretPass123 \
  neo4j:5.25.0

Verify connection readiness using the Bolt port:

bash
curl -I 

3. Server Implementation and Configuration

Below is a complete, production-ready TypeScript implementation of the Neo4j MCP server using @modelcontextprotocol/sdk and neo4j-driver.

typescript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
  CallToolRequestSchema,
  ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import neo4j from "neo4j-driver";

const uri = process.env.NEO4J_URI || "bolt://";
const user = process.env.NEO4J_USER || "neo4j";
const password = process.env.NEO4J_PASSWORD || "DevelopmentSecretPass123";

const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));

const server = new Server(
  { name: "neo4j-graph-mcp", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: "read_cypher",
      description: "Execute a read-only Cypher query against the Neo4j database.",
      inputSchema: {
        type: "object",
        properties: {
          query: { type: "string", description: "The MATCH Cypher query to execute" },
          params: { type: "object", description: "Optional key-value query parameters", default: {} }
        },
        required: ["query"]
      }
    },
    {
      name: "get_schema",
      description: "Inspect active Node labels, Relationship types, and database property keys.",
      inputSchema: { type: "object", properties: {} }
    }
  ]
}));

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;

  if (name === "get_schema") {
    const session = driver.session({ defaultAccessMode: neo4j.session.READ });
    try {
      const result = await session.run("CALL db.schema.visualization()");
      return {
        content: [{ type: "text", text: JSON.stringify(result.records.map(r => r.toObject()), null, 2) }]
      };
    } finally {
      await session.close();
    }
  }

  if (name === "read_cypher") {
    const { query, params = {} } = args as any;
    if (!query.trim().toUpperCase().startsWith("MATCH")) {
      throw new Error("Only read-only MATCH queries are permitted through this tool.");
    }
    const session = driver.session({ defaultAccessMode: neo4j.session.READ });
    try {
      const result = await session.run(query, params);
      const rows = result.records.map(r => r.toObject());
      return {
        content: [{ type: "text", text: JSON.stringify(rows, null, 2) }]
      };
    } finally {
      await session.close();
    }
  }

  throw new Error(`Tool not found: ${name}`);
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch(console.error);

Multi-Host Configuration Snippets

Claude Desktop

In claude_desktop_config.json:

json
{
  "mcpServers": {
    "neo4j": {
      "command": "node",
      "args": ["/absolute/path/to/neo4j-mcp/dist/index.js"],
      "env": {
        "NEO4J_URI": "bolt://",
        "NEO4J_USER": "neo4j",
        "NEO4J_PASSWORD": "DevelopmentSecretPass123"
      }
    }
  }
}

Cursor IDE

In .cursor/mcp.json:

json
{
  "mcpServers": {
    "neo4j": {
      "command": "node",
      "args": ["/absolute/path/to/neo4j-mcp/dist/index.js"],
      "env": {
        "NEO4J_URI": "bolt://",
        "NEO4J_USER": "neo4j",
        "NEO4J_PASSWORD": "DevelopmentSecretPass123"
      }
    }
  }
}

OpenAI Codex CLI

In ~/.codex/config.toml:

toml
[mcp_servers.neo4j]
command = "node"
args = ["/absolute/path/to/neo4j-mcp/dist/index.js"]
env = { NEO4J_URI = "bolt://", NEO4J_USER = "neo4j", NEO4J_PASSWORD = "DevelopmentSecretPass123" }

4. Step-by-Step Tool Discovery and Invocation

When prompted: "Find all upstream microservices that depend on the AuthGateway service", the host invokes:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "read_cypher",
    "arguments": {
      "query": "MATCH (s:Service)-[:DEPENDS_ON]->(target:Service {name: $targetName}) RETURN s.name AS dependentService LIMIT 10",
      "params": {
        "targetName": "AuthGateway"
      }
    }
  }
}

The server queries Neo4j via Bolt and returns relational matches:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "[\n  { \"dependentService\": \"OrderProcessingService\" },\n  { \"dependentService\": \"UserProfileService\" }\n]"
      }
    ],
    "isError": false
  }
}

5. Common Errors and Production Troubleshooting

1. Neo.ClientError.Security.Unauthorized

  • ▸Symptom: Server initialization throws authorization failures.
  • ▸Root Cause: Invalid credentials or initial password expiration. Neo4j requires changing default passwords on first startup.
  • ▸Solution: Set the password via environment variable during Docker launch (NEO4J_AUTH=neo4j/new_password) or connect to the Neo4j browser at to complete initial setup.

2. Transaction Lock Timeouts on Cypher Updates

  • ▸Symptom: Concurrent agent tool calls hang and throw lock acquisition timeouts.
  • ▸Root Cause: Unindexed MERGE queries create full table locks across dense nodes.
  • ▸Solution: Create unique constraints on entity keys before loading large relational datasets:
cypher
CREATE CONSTRAINT service_name_unique FOR (s:Service) REQUIRE s.name IS UNIQUE;

3. Out-of-Memory Errors on Cartesian Product Queries

  • ▸Symptom: Database crashes when executing complex nested relationship lookups.
  • ▸Root Cause: Unbounded Cartesian products (MATCH (a), (b) without explicit edge relationships).
  • ▸Solution: Enforce strict query validation in your server layer to require directed edge patterns and mandatory LIMIT clauses on all agent queries.

6. External Citations and Security Guardrails

Operating graph databases alongside autonomous agents requires strong isolation:

  1. ▸Read-Only Session Enforcement: Always set defaultAccessMode: neo4j.session.READ on exploratory query sessions to prevent accidental DETACH DELETE commands.
  2. ▸Parameterized Cypher: Always use $param injection syntax rather than string interpolation to eliminate Cypher injection vulnerabilities.
  3. ▸Connection Pooling: Re-use the neo4j-driver instance across tool calls to avoid exhausting socket descriptors.
Technical Changelog

Weekly Protocol Diffs & Verified Drops

New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.

Zero marketing spam. 1-click unsubscribe anytime.

Ready to Deploy?

Build your full agent toolstack in the Visual Generator

Combine Neo4j Knowledge Graph with databases, search APIs, and memory graphs in a single configuration file.

Customize in Generator
Developer Verification & Feedback
0 reports

Did this setup guide work with your AI host?

Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:

Neo4j Knowledge Graph MCP Server Guide FAQ

What is the Neo4j Knowledge Graph MCP Server Guide?

Connect Neo4j knowledge graphs to AI agents via MCP. Run Cypher queries, traverse entity relationships, and build structured GraphRAG pipelines.

How do I configure Neo4j Knowledge Graph MCP Server Guide in Claude Desktop or Cursor?

You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.

Can I use Neo4j Knowledge Graph MCP Server Guide with the OpenAI Codex CLI?

Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.

RT

Written by Rad Tome

Lead AI Systems Architect & Maintainer, MCP Codex

@RadTome

Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.

Editorial Integrity: Package names are checked against the npm registry and repositories against the GitHub API. Where a package could not be verified, the guide says so instead of giving you a command to run.

Related Guides