Skip to content

πŸ”— Comprehensive MCP server for Neo4j - 3x more tools than official, zero dependencies, TypeScript-based server enabling advanced Neo4j interactions through Claude's Model Context Protocol.

License

Notifications You must be signed in to change notification settings

michaelhil/neo4j2llm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

neo4j2LLM

πŸš€ MCP Server for Neo4j Knowledge Graph Integration with Claude Desktop

A TypeScript-based Model Context Protocol (MCP) server that enables Claude Desktop to interact directly with Neo4j knowledge graphs. Built with modern technologies for performance, reliability, and ease of use.

πŸ“‹ Table of Contents

✨ Features

  • πŸ”Œ Universal Neo4j Connectivity - Works with local, Docker, cloud, and AuraDB instances
  • πŸ› οΈ Comprehensive Toolset - 12 essential tools for knowledge graph operations
  • ⚑ High Performance - Built with Bun runtime and optimized TypeScript
  • πŸ”’ Secure by Design - Robust validation, error handling, and connection management
  • πŸ“Š Rich Query Analysis - Query profiling, execution plans, and optimization tips
  • 🎯 Type Safety - 100% TypeScript with comprehensive type definitions
  • πŸ”„ Real-time Operations - Streaming support for large datasets
  • πŸ“ˆ Schema Introspection - Complete database schema analysis and visualization

πŸ“‹ Prerequisites

  • Node.js >= 18.0.0 or Bun >= 1.0.0
  • Neo4j Database (local installation, Docker, or cloud instance)
  • Claude Desktop with MCP support

πŸš€ Installation

Option 1: Using Bun (Recommended)

# Clone the repository
git clone https://github.com/michaelhil/neo4j2llm.git
cd neo4j2llm

# Install dependencies
bun install

# Build the project
bun run build

# Run the MCP server
bun run src/index.ts

Option 2: Using npm

# Clone and install
git clone https://github.com/michaelhil/neo4j2llm.git
cd neo4j2llm
npm install

# Build and run
npm run build
npm start

Option 3: Docker Container

# Pull and run the container
docker run -it --rm \\
  -e NEO4J_URI=bolt://host.docker.internal:7687 \\
  -e NEO4J_USERNAME=neo4j \\
  -e NEO4J_PASSWORD=password \\
  michaelhil/neo4j2llm:latest

βš™οΈ Configuration

Environment Variables

Create a .env file in the root directory:

NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_password
NEO4J_DATABASE=neo4j

Claude Desktop Configuration

Add to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "neo4j2llm": {
      "command": "bun",
      "args": ["run", "/path/to/neo4j2llm/src/index.ts"],
      "env": {
        "NEO4J_URI": "bolt://localhost:7687",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": "your_password"
      }
    }
  }
}

Connection Options

The server supports multiple Neo4j deployment types:

Type URI Format Example
Local Bolt bolt://host:port bolt://localhost:7687
Local HTTP http://host:port http://localhost:7474
Neo4j Cloud neo4j://host:port neo4j://xxx.databases.neo4j.io:7687
AuraDB neo4j+s://host:port neo4j+s://xxx.databases.neo4j.io:7687

πŸ“– Usage

Once configured, you can use natural language with Claude to interact with your Neo4j database:

Basic Connection

Connect to my Neo4j database at bolt://localhost:7687 with username neo4j and password mypassword

Query Execution

Show me all Person nodes in the database

Schema Exploration

What labels and relationship types exist in my database?

Data Creation

Create a new Person node with name "Alice" and age 30

Performance Analysis

Explain the execution plan for: MATCH (p:Person)-[:KNOWS]->(f:Person) RETURN p, f

πŸ› οΈ Available Tools

πŸ”Œ Connection Management

neo4j_connect

Establish connection to Neo4j database instance.

Parameters:

  • uri (required): Neo4j connection URI
  • username (required): Database username
  • password (required): Database password
  • database (optional): Target database name
  • maxConnectionPoolSize (optional): Max connection pool size
  • connectionTimeout (optional): Connection timeout in milliseconds

Example:

{
  "uri": "bolt://localhost:7687",
  "username": "neo4j",
  "password": "password",
  "database": "movies"
}

neo4j_disconnect

Close connection to Neo4j database.

Example:

// No parameters required

neo4j_test_connection

Test connection health and get database information.

Parameters:

  • includePerformanceTest (optional): Include response time measurement

Example:

{
  "includePerformanceTest": true
}

πŸ” Query Execution

neo4j_execute_query

Execute Cypher query against Neo4j database.

Parameters:

  • cypher (required): Cypher query string
  • parameters (optional): Query parameters
  • timeout (optional): Query timeout in milliseconds
  • includeStats (optional): Include execution statistics
  • limit (optional): Maximum records to return

Example:

{
  "cypher": "MATCH (p:Person {name: $name}) RETURN p",
  "parameters": {"name": "Alice"},
  "limit": 100,
  "includeStats": true
}

neo4j_explain_query

Get execution plan for Cypher query without executing it.

Parameters:

  • cypher (required): Cypher query to explain
  • parameters (optional): Query parameters

Example:

{
  "cypher": "MATCH (p:Person)-[:KNOWS]->(f) RETURN p, f",
  "parameters": {}
}

neo4j_profile_query

Execute and profile Cypher query to analyze performance.

Parameters:

  • cypher (required): Cypher query to profile
  • parameters (optional): Query parameters

Example:

{
  "cypher": "MATCH (p:Person) WHERE p.age > $minAge RETURN count(p)",
  "parameters": {"minAge": 25}
}

πŸ“Š Schema Management

neo4j_get_schema

Retrieve complete database schema including labels, relationships, properties, constraints, and indexes.

Parameters:

  • includeStatistics (optional): Include schema statistics
  • includePropertyInfo (optional): Include detailed property information

Example:

{
  "includeStatistics": true,
  "includePropertyInfo": true
}

neo4j_get_labels

Get all node labels with their counts and sample properties.

Parameters:

  • includeCounts (optional): Include node counts for each label
  • includeSampleProperties (optional): Include sample property names
  • sortBy (optional): Sort by 'name' or 'count'
  • limit (optional): Maximum number of labels to return

Example:

{
  "includeCounts": true,
  "sortBy": "count",
  "limit": 50
}

neo4j_get_relationship_types

Get all relationship types with their counts and sample properties.

Parameters:

  • includeCounts (optional): Include relationship counts
  • includeSampleProperties (optional): Include sample property names
  • sortBy (optional): Sort by 'name' or 'count'
  • limit (optional): Maximum number of types to return

Example:

{
  "includeCounts": true,
  "includeSampleProperties": true,
  "sortBy": "name"
}

πŸ—οΈ Graph Creation

neo4j_create_nodes

Create multiple nodes with specified labels and properties.

neo4j_create_relationships

Create relationships between existing nodes with specified properties.

πŸ“€ Data Export

neo4j_export_data

Export query results in JSON, CSV, or Cypher format.

Parameters:

  • nodes (required): Array of nodes to create
  • returnCreated (optional): Return information about created nodes
  • batchSize (optional): Number of nodes to create per batch

Example - Creating Nodes:

{
  "nodes": [
    {
      "labels": ["Person"],
      "properties": {"name": "Alice", "age": 30}
    },
    {
      "labels": ["Person", "Developer"],
      "properties": {"name": "Bob", "age": 25, "skill": "TypeScript"}
    }
  ],
  "returnCreated": true,
  "batchSize": 100
}

Example - Creating Relationships:

{
  "relationships": [
    {
      "type": "KNOWS",
      "properties": {"since": "2020"},
      "startNode": {
        "labels": ["Person"],
        "properties": {"name": "Alice"}
      },
      "endNode": {
        "labels": ["Person"],
        "properties": {"name": "Bob"}
      }
    }
  ],
  "returnCreated": true
}

Example - Exporting Data:

{
  "query": "MATCH (p:Person) RETURN p.name, p.age",
  "format": "json",
  "limit": 100
}

πŸ’‘ Examples

1. Basic Database Exploration

// Connect to database
await neo4j_connect({
  "uri": "bolt://localhost:7687",
  "username": "neo4j",
  "password": "password"
})

// Get database schema
await neo4j_get_schema({
  "includeStatistics": true
})

// List all labels
await neo4j_get_labels({
  "includeCounts": true,
  "sortBy": "count"
})

2. Query Performance Analysis

// Profile a complex query
await neo4j_profile_query({
  "cypher": `
    MATCH (p:Person)-[:WORKS_FOR]->(c:Company)
    WHERE c.industry = $industry
    RETURN p.name, c.name
    ORDER BY p.name
  `,
  "parameters": {"industry": "Technology"}
})

3. Data Creation and Querying

// Create nodes
await neo4j_create_nodes({
  "nodes": [
    {
      "labels": ["Company"],
      "properties": {"name": "TechCorp", "industry": "Technology"}
    },
    {
      "labels": ["Person"],
      "properties": {"name": "Alice", "role": "Engineer"}
    }
  ],
  "returnCreated": true
})

// Query the created data
await neo4j_execute_query({
  "cypher": "MATCH (p:Person {name: 'Alice'}) RETURN p",
  "includeStats": true
})

πŸ—οΈ Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β”‚  Claude Desktop │◄──►│   neo4j2LLM      │◄──►│   Neo4j         β”‚
β”‚                 β”‚    β”‚   MCP Server     β”‚    β”‚   Database      β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technology Stack

  • πŸ”§ Runtime: Bun (primary) / Node.js (compatible)
  • πŸ“ Language: TypeScript (100%)
  • πŸ”Œ Protocol: Model Context Protocol (MCP)
  • πŸ—„οΈ Database: Neo4j (all versions)
  • πŸ§ͺ Testing: Bun test runner
  • πŸ“¦ Building: Vite
  • πŸ” Linting: ESLint + TypeScript rules

Project Structure

neo4j2LLM/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/              # Core types, errors, validation
β”‚   β”œβ”€β”€ connection/        # Neo4j connection management
β”‚   β”œβ”€β”€ services/          # Business logic services
β”‚   β”œβ”€β”€ tools/             # MCP tool implementations
β”‚   β”‚   β”œβ”€β”€ connection/    # Connection management tools
β”‚   β”‚   β”œβ”€β”€ query/         # Query execution tools
β”‚   β”‚   β”œβ”€β”€ schema/        # Schema introspection tools
β”‚   β”‚   └── creation/      # Data creation tools
β”‚   └── index.ts          # MCP server entry point
β”œβ”€β”€ docs/                 # Documentation
β”œβ”€β”€ tests/                # Test suites
└── docker/               # Docker configuration

Key Design Principles

  • πŸ—οΈ Factory Pattern: All services use factory functions for clean instantiation
  • πŸ›‘οΈ Type Safety: Comprehensive TypeScript interfaces and validation
  • πŸ”„ Functional Programming: Immutable data structures and pure functions
  • 🚦 Error Handling: Robust error categorization and recovery
  • ⚑ Performance: Connection pooling, query optimization, and streaming support

πŸ§ͺ Development

Setup Development Environment

# Clone and install
git clone https://github.com/michaelhil/neo4j2llm.git
cd neo4j2llm
bun install

# Start development server
bun run dev

# Run tests
bun test

# Type checking
bun run type-check

# Linting
bun run lint

Project Scripts

bun run dev          # Development server with hot reload
bun run build        # Build for production
bun test             # Run test suite
bun test:watch       # Run tests in watch mode
bun run lint         # Lint code
bun run lint:fix     # Fix linting issues
bun run type-check   # TypeScript type checking

Testing

# Run all tests
bun test

# Run specific test file
bun test src/tools/connection/connect.test.ts

# Run tests with coverage
bun test --coverage

🐳 Docker

Building the Container

# Build the Docker image
docker build -t neo4j2llm .

# Run the container
docker run -it --rm \\
  -e NEO4J_URI=bolt://host.docker.internal:7687 \\
  -e NEO4J_USERNAME=neo4j \\
  -e NEO4J_PASSWORD=password \\
  neo4j2llm

Docker Compose

version: '3.8'
services:
  neo4j:
    image: neo4j:latest
    environment:
      NEO4J_AUTH: neo4j/password
    ports:
      - "7474:7474"
      - "7687:7687"

  neo4j2llm:
    build: .
    environment:
      NEO4J_URI: bolt://neo4j:7687
      NEO4J_USERNAME: neo4j
      NEO4J_PASSWORD: password
    depends_on:
      - neo4j

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Standards

  • TypeScript for all code (no JavaScript files)
  • ESLint for code quality
  • Prettier for formatting
  • Comprehensive tests for new features
  • Documentation for all public APIs

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Neo4j Team for the excellent graph database
  • Anthropic for Claude and the MCP protocol
  • Bun Team for the blazing fast runtime
  • TypeScript Team for type safety excellence

πŸ“ž Support


Made with ❀️ for the Knowledge Graph community

About

πŸ”— Comprehensive MCP server for Neo4j - 3x more tools than official, zero dependencies, TypeScript-based server enabling advanced Neo4j interactions through Claude's Model Context Protocol.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •