MCP Memory Graph Server logo

MCP Memory Graph Server

by santahate

The Memory Graph Server provides a persistent storage layer for knowledge graphs, allowing for storage of entities and their properties, management of relationships, querying, and real-time updates. It utilizes MongoDB for persistent storage and offers graph operations for entity and relationship management.

View on GitHub

Last updated: N/A

MCP Memory Graph Server

Overview

The Memory Graph Server provides a persistent storage layer for knowledge graphs, allowing for:

  • Storage of entities and their properties
  • Management of relationships between entities
  • Querying and traversing the graph structure
  • Real-time updates and modifications

Features

  • MongoDB-based persistent storage
  • Graph operations (create, read, update, delete)
  • Entity management
  • Relationship handling
  • Query capabilities
  • Real-time updates

Getting Started

Prerequisites

  • Python 3.12+
  • MongoDB 4.4+
  • uv (for dependency management)
  • MCP CLI (for connecting as a service)

Installation

  1. Clone the repository

  2. Install uv if you haven't already:

curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Create virtual environment and install dependencies:
uv venv
source .venv/bin/activate  # On Unix-like systems
# or
.venv\Scripts\activate     # On Windows

uv pip install -r requirements.txt
  1. Create a .env file with your MongoDB configuration:
MONGO_USER=your_mongodb_user
MONGO_PASSWORD=your_mongodb_password
MONGO_URI=your_mongodb_uri
  1. Run the server:
python main.py

Using as MCP Service

Configuration

Add the following configuration to your ~/.cursor/mcp.json:

{
  "MongoMemory": {
    "command": "/path/to/.local/bin/uv",
    "args": [
      "run",
      "--with",
      "mcp[cli]",
      "--with",
      "pymongo",
      "mcp",
      "run",
      "/path/to/mongo-memory/main.py"
    ],
    "cwd": "/path/to/mongo-memory"
  }
}

Replace /path/to/ with your actual paths.

Available Operations

Currently implemented operations:

  • create_entities: Create new entities in the graph. Requires name field to be unique.
  • get_entity: Retrieve a single entity by its name.
  • update_entity: Update an existing entity by its name.
  • delete_entity: Delete an entity by its name.
  • find_entities: Find entities matching query criteria. Requires non-empty query dictionary, returns up to 10 matches by default.
  • create_relationship: Create a relationship between two entities with optional properties.
  • get_relationships: Find relationships matching query criteria with pagination support.
  • delete_relationship: Delete a specific relationship between entities.

Example usage in Python with MCP client:

from mcp.client import MCPClient

client = MCPClient()
memory = client.get_service("MongoMemory")

# Create entities
result = memory.create_entities([
    {"name": "Entity1", "type": "Person", "properties": {"age": 30}},
    {"name": "Entity2", "type": "Location", "properties": {"country": "USA"}}
])

# Create relationship
result = memory.create_relationship(
    from_entity="Entity1",
    to_entity="Entity2",
    relationship_type="lives_in:since=2020"
)

# Find relationships
relationships = memory.get_relationships(
    query={"type": "lives_in"},
    limit=5
)

# Delete relationship
result = memory.delete_relationship(
    from_entity="Entity1",
    to_entity="Entity2",
    relationship_type="lives_in:since=2020"
)

# Get single entity
entity = memory.get_entity("Entity1")

# Find entities by type (returns up to 10 matches)
entities = memory.find_entities({"type": "Person"})

# Find entities with custom limit
entities = memory.find_entities({"properties.country": "USA"}, limit=5)

# Update entity
result = memory.update_entity(
    "Entity1",
    {"$set": {"properties.age": 31}},
)

# Delete entity
result = memory.delete_entity("Entity2")

Architecture

The system consists of several key components:

  • MongoDB Connector: Handles all database operations
  • Graph Operations: Manages graph structure and operations
  • API Layer: Provides interface for client interactions

License

[License information to be added]