Neo4j Agent Memory Management MCP Server
Optimize AI agent memory with Neo4j knowledge graphs using the MCP server for efficient, scalable memory management and faster agent reasoning.
npx -y @knowall-ai/mcp-neo4j-agent-memoryOverview
This MCP (Model Context Protocol) server connects AI agents to a Neo4j-based knowledge graph to manage agent memory. Instead of keeping memory in opaque vectors or ephemeral caches, the server persists memory as graph nodes and relationships and exposes an MCP-compliant API for storing, retrieving, and pruning context. That enables agents to reason over structured facts and relationships while retaining fast similarity search for recent or semantically related memories.
Using Neo4j for memory gives two main advantages: 1) graph queries let agents answer relational questions (who, what, when, how related) without reconstructing context from raw text; 2) graph-native indices (including vector extensions) support scalable semantic search for relevant memories. The server is intended for developers building multi-turn agents, RAG pipelines, or personalization systems that need both semantic retrieval and structured relationship reasoning.
Features
- MCP-compatible HTTP API for storing and retrieving agent memory
- Persist memory as Neo4j nodes with metadata, timestamps, and namespaces
- Semantic similarity search via embedding vectors (integrates with embedding providers)
- Graph queries to discover relationships between memories, entities, and sessions
- Memory lifecycle controls: time-to-live (TTL), namespace scoping, and pruning
- Lightweight, container-friendly deployment (Docker / Docker Compose)
- Configurable Neo4j connection and embedding provider (OpenAI or other)
- Example client usage and ready-to-integrate endpoints for agents
Installation / Configuration
Quick start using Docker Compose:
# docker-compose.yml
version: "3.8"
services:
neo4j:
image: neo4j:5.11.0
environment:
- NEO4J_AUTH=neo4j/testpassword
ports:
- "7474:7474"
- "7687:7687"
mcp-server:
image: ghcr.io/knowall-ai/mcp-neo4j-agent-memory:latest
environment:
- NEO4J_URI=bolt://neo4j:7687
- NEO4J_USER=neo4j
- NEO4J_PASSWORD=testpassword
- EMBEDDING_PROVIDER=openai
- OPENAI_API_KEY=${OPENAI_API_KEY}
ports:
- "8080:8080"
depends_on:
- neo4j
Environment variables (common)
| Variable | Required | Description | Example |
|---|---|---|---|
| NEO4J_URI | yes | Bolt URI for Neo4j | bolt://localhost:7687 |
| NEO4J_USER | yes | Neo4j username | neo4j |
| NEO4J_PASSWORD | yes | Neo4j password | secret |
| EMBEDDING_PROVIDER | no | Which embeddings to use (openai/none) | openai |
| OPENAI_API_KEY | conditional | API key if using OpenAI embeddings | sk-… |
| MCP_PORT | no | Port to expose MCP server | 8080 |
Run locally:
# start services
# view logs
Available Tools / Resources
- REST API (MCP) endpoints:
- POST /mcp/memory — store a memory item
- POST /mcp/search — semantic search for memories
- GET /mcp/memory/{id} — fetch a memory node by id
- POST /mcp/query — execute a graph query across stored memories
- POST /mcp/prune — run pruning policies (TTL, namespace)
- OpenAPI / Swagger: The server exposes an OpenAPI spec at /openapi.json and Swagger UI at /docs when enabled.
- Example clients: Minimal Python and Node.js snippets (see GitHub repo).
- GitHub: https://github.com/knowall-ai/mcp-neo4j-agent-memory
API Examples
Store a memory (curl):
Semantic search for relevant memories:
Graph query example (find related memories about a topic):
Use Cases
- Multi-turn conversational agents: Persist user-specific memories (preferences, past actions) so subsequent turns can combine semantic retrieval with explicit graph relations (e.g., “When did the user ask about refunds?”).
- Retrieval-Augmented Generation (RAG): Use semantic search to fetch relevant memory nodes, then expand retrieval with graph traversals to include related entities and context for better answers.
- Personalization: Store and query structured profile facts and behavioral memories; use TTL or pruning rules to forget stale data while keeping important long-term items.
- Compliance and auditing: Memory items are stored in Neo4j with metadata and timestamps, enabling traceability and selective removal according to data governance policies.
- Complex reasoning: Leverage relationships (edges) to infer indirect connections (e.g., customer -> product interest -> support tickets) without rebuilding knowledge from raw text each time.
Getting Help and Contributing
Refer to the repository for issues, feature requests, and contribution guidelines: https://github.com/knowall-ai/mcp-neo4j-agent-memory. Look for example agent integrations and community patterns in the repo to speed adoption.