hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Integrations
Uses Docker and Docker Compose to manage Neo4j database instances, with preconfigured settings for ports, credentials, plugins, and health checks.
Provides a knowledge graph management interface for storing and retrieving information in Neo4j graph databases, with tools for creating entities and relationships, searching and filtering data, updating entities, and introspecting database schema.
Neo4j MCP Server
This is a Memory Control Protocol (MCP) server implementation that uses Neo4j as the backend storage for knowledge graph management. It provides a stdio-based interface for storing and retrieving knowledge in a graph database format.
Prerequisites
- Python 3.8+
- Neo4j Database (local or remote)
- Poetry (Python package manager)
- Docker and Docker Compose (for running Neo4j)
- Go Task (optional, for task automation)
Installation
- Clone the repository:
- Install Poetry if you haven't already:
- Install dependencies:
Configuration
Claude Desktop Configuration
For Ubuntu users running Claude Desktop, you can configure the MCP server by adding it to your Claude desktop configuration file at:
Before configuring, you need to build the standalone executable:
This will create a binary at dist/neo4j_mcp_server
. Make sure to update the path in your configuration to point to this built executable.
An example configuration is provided in example_mcp_config.json
. You can copy and modify this file:
Then edit the command
path in the configuration file to point to your built executable:
The configuration includes:
- Server name and description
- Command to start the server (path to the built executable)
- Available tools and their parameters
- Required fields and data types
Running the Server
Using Task (Recommended)
If you have Go Task installed, you can use the provided Taskfile to manage the server:
Using Docker Compose directly
- Start the Neo4j container:
- Wait for Neo4j to be ready (the container will show as "healthy" in
docker ps
)
Running the MCP Server directly
Start the server with:
The server will start in stdio mode, ready to accept MCP protocol messages.
Available Tools
1. Create Entities
Creates new entities in the knowledge graph. Each entity must have a type and properties. The ID will be automatically set from the name property if not explicitly provided.
Parameters:
entities
: List of entity objects, each containing:type
: String - The type of entity (e.g., Person, Organization)properties
: Object - Key-value pairs of entity properties (must include either 'id' or 'name')
Example input:
2. Create Relations
Creates relationships between existing entities in the knowledge graph. All referenced entities must exist before creating relations.
Parameters:
relations
: List of relation objects, each containing:type
: String - The type of relation (e.g., KNOWS, WORKS_FOR)from
: String - ID of the source entityto
: String - ID of the target entity
Example input:
3. Search Entities
Searches for entities in the knowledge graph with powerful text matching and filtering capabilities. Can be used to search by text, list entities by type, find entities with specific properties, or any combination of these filters.
Parameters:
search_term
: String (optional) - Text to search for in entity properties. If not provided, returns entities based on other filters.entity_type
: String (optional) - Filter results by entity type (e.g., Person, Organization). If provided alone, returns all entities of that type.properties
: List[String] (optional) - List of property names to filter by:- With search_term: Searches these properties for the term
- Without search_term: Returns entities that have any of these properties defined
include_relationships
: Boolean (optional, default: false) - Whether to include connected entities and relationshipsfuzzy_match
: Boolean (optional, default: true) - Whether to use case-insensitive partial matching when search_term is provided
Example inputs:
Returns:
Notes:
- When no filters are provided, returns all entities
- Entity type filtering is exact match (not fuzzy)
- Property existence check is done with
IS NOT NULL
- Text search supports case-insensitive partial matching when fuzzy_match is true
- Empty results are returned as an empty array, not an error
- Performance considerations:
- Filtering by type is more efficient than text search
- Property existence checks are optimized
- Consider using specific properties instead of searching all properties
- Large result sets may be paginated in future versions
4. Update Entities
Updates existing entities in the knowledge graph. Supports adding/removing properties and labels.
Parameters:
updates
: List of update objects, each containing:id
: String (required) - ID of the entity to updateproperties
: Object (optional) - Properties to update or addremove_properties
: List[String] (optional) - Property names to removeadd_labels
: List[String] (optional) - Labels to add to the entityremove_labels
: List[String] (optional) - Labels to remove from the entity
Example input:
5. Delete Entities
Deletes entities from the knowledge graph with optional cascade deletion of relationships.
Parameters:
entity_ids
: List[String] (required) - List of entity IDs to deletecascade
: Boolean (optional, default: false) - Whether to delete connected relationshipsdry_run
: Boolean (optional, default: false) - Preview deletion impact without making changes
Example input:
Returns:
success
: Boolean - Whether the operation was successfuldeleted_entities
: List of deleted entitiesdeleted_relationships
: List of deleted relationshipserrors
: List of error messages (if any)impacted_entities
: List of entities that would be affected (dry_run only)impacted_relationships
: List of relationships that would be affected (dry_run only)
6. Introspect Schema
Retrieves comprehensive information about the Neo4j database schema, including node labels, relationship types, and their properties.
Parameters: None required
Returns:
schema
: Object containing:node_labels
: List of all node labels in the databaserelationship_types
: List of all relationship typesnode_properties
: Map of label to list of property namesrelationship_properties
: Map of relationship type to list of property names
Example input:
Testing
Test Scripts
The project includes several test scripts for different aspects of the system:
mcp_neo4j_knowledge_graph/test_mcp_client.py
- Tests the MCP client functionality- Verifies server startup
- Tests tool listing
- Tests schema introspection
- Tests entity creation
Copymcp_neo4j_knowledge_graph/test_mcp_config.py
- Tests the MCP configuration- Validates configuration file loading
- Tests server connection using the official MCP SDK
- Verifies all required tools are available
Copymcp_neo4j_knowledge_graph/test_neo4j_connection.py
- Tests the Neo4j database connection- Verifies database connectivity
- Tests basic query functionality
- Checks environment configuration
Copy
Running Tests
You can run the tests in several ways:
- Run all tests together:Copy
- Run individual test types:Copy
- Run tests with pytest directly:Copy
Development
Using Task
The project includes several development tasks:
Running directly
This project uses several development tools that are automatically installed with Poetry:
black
for code formattingisort
for import sortingflake8
for lintingpytest
for testing
You can run these tools using Poetry:
Error Handling
The server includes comprehensive error handling for:
- Database connection issues
- Invalid queries
- Missing nodes
- Invalid request formats
- Schema validation errors
- Relationship creation failures
- Entity update conflicts
All errors are returned with appropriate error messages in the MCP protocol format.
Docker Configuration
The Neo4j container is configured with the following settings:
- Ports: 7474 (HTTP) and 7687 (Bolt)
- Default credentials: neo4j/password
- APOC plugin enabled
- File import/export enabled
- Health check configured
You can modify these settings in the docker-compose.yml
file.
Task Commands Reference
task
- Show available taskstask run
- Start Docker and MCP servertask dev
- Start development environment (Docker + Server + Test)task docker
- Start Neo4j databasetask server
- Run the MCP servertask test
- Run all teststask test-client
- Run MCP client teststask test-config
- Run MCP config teststask test-db
- Run database teststask test-integration
- Run integration teststask down
- Stop all Docker servicestask format
- Format code using black and isorttask lint
- Run flake8 lintertask help
- Show detailed help for all tasks
This server cannot be installed
Enables storage and retrieval of knowledge in a graph database format, allowing users to create, update, search, and delete entities and relationships in a Neo4j-powered knowledge graph through natural language.