Memento MCP

repository·main·Indexed 19 days ago

https://github.com/gannonh/memento-mcp

A knowledge graph memory system for LLMs providing long-term, persistent, and adaptive ontological memory using Neo4j 5.13+. It enables LLM clients like Claude Desktop and Cursor to perform semantic retrieval, track temporal changes via version history, and manage relationship confidence with time-based decay. The system supports hybrid search combining vector embeddings (via OpenAI) and keyword search, and provides tools for managing entities, relations, and historical graph states.

Tokens
18.3K
Snippets
61
Records
78
Agent score
64%

What's inside @gannonh/memento-mcp

  1. Understand Semantic Search and Temporal Awareness

    main

    Memento MCP uses OpenAI embedding models (e.g., text-embedding-3-small/large) to enable meaning-based retrieval.

    • Hybrid Search: Combines semantic (vector) and keyword search.
    • Adaptive Search: Automatically chooses between vector-only, keyword-only, or hybrid search based on query complexity.
    • Thresholds: Uses a default 0.6 similarity threshold to balance precision and recall.

    Temporal Awareness

    The system tracks the evolution of knowledge over time.

    • Version History: Every change to an entity or relation is preserved with timestamps.
    • Point-in-Time Queries: Retrieve the state of the graph at any specific moment.
    • Non-Destructive Updates: Updates create new versions rather than overwriting existing data.

    Confidence Decay

    Relations include a configurable half-life (default: 30 days). If a relation is not reinforced by new observations, its confidence naturally decreases over time.

  2. Enable Debug mode and diagnostic tools

    main

    When DEBUG=true is set in your environment variables or Claude Desktop configuration, Memento MCP exposes additional diagnostic tools via the MCP API and includes detailed metadata in semantic search responses.

    Available Debug Tools (DEBUG=true only):

    • diagnose_vector_search: Directly queries Neo4j for entity embeddings and index status.
    • force_generate_embedding: Forces generation of an embedding for a specific entity (e.g., {"entity_name": "EntityName"}).
    • debug_embedding_config: Shows current embedding model, dimensions, and service status.

    Diagnostic Response Format: Responses will include a diagnostics object containing the original query, timestamps, and a stepsTaken array detailing the execution flow (e.g., embeddingServiceCheck, vectorSearch).

    {
      "entities": [...],
      "relations": [...],
      "diagnostics": {
        "query": "original search query",
        "startTime": 1743279841982,
        "stepsTaken": [
          { "step": "embeddingServiceCheck", "status": "available", ... },
          { "step": "vectorSearch", "status": "started", ... },
          { "step": "vectorSearch", "status": "completed", "resultsCount": 3 }
        ],
        "endTime": 1743279842014,
        "totalTimeTaken": 32
      }
    }
  3. What are Entities and Relations in Memento MCP?

    main

    Memento MCP uses a knowledge graph model composed of two primary abstractions:

    Entities

    Entities are the nodes in the graph. Each entity contains:

    • A unique name (identifier).
    • An entityType (e.g., person, organization).
    • A list of observations.
    • Vector embeddings for semantic search.
    • Complete version history.

    Relations

    Relations are directed connections between entities. They include:

    • strength (0.0-1.0) and confidence (0.0-1.0) indicators.
    • Rich metadata (source, timestamps, tags).
    • Temporal awareness with version history and time-based confidence decay.

    Example Entity:

    {
      "name": "John_Smith",
      "entityType": "person",
      "observations": ["Speaks fluent Spanish"]
    }

    Example Relation:

    {
      "from": "John_Smith",
      "to": "Anthropic",
      "relationType": "works_at",
      "strength": 0.9,
      "confidence": 0.95,
      "metadata": {
        "source": "linkedin_profile",
        "last_verified": "2025-03-21"
      }
    }
    {
      "name": "John_Smith",
      "entityType": "person",
      "observations": ["Speaks fluent Spanish"]
    }
  4. Set up Neo4j using Docker

    main

    Memento MCP requires Neo4j 5.13+ for vector search capabilities. You can use the provided Docker Compose configuration to manage the database.

    Prerequisites:

    • Docker and Docker Compose
    • Neo4j 5.13+

    Default Connection Details:

    • Bolt URI: bolt://localhost:7687
    • HTTP (Browser UI): http://localhost:7474
    • Username: neo4j
    • Password: memento_password
    # Start Neo4j container
    docker-compose up -d neo4j
    
    # Stop Neo4j container
    docker-compose stop neo4j
    
    # Remove Neo4j container (preserves data)
    docker-compose rm neo4j
  5. Build and develop Memento MCP

    main

    To work on the project from source, use the following standard development commands:

    • npm install: Install dependencies.
    • npm run build: Build the project.
    • npm test: Run the test suite.
    • npm run test:coverage: Check test coverage.
    git clone https://github.com/gannonh/memento-mcp.git
    cd memento-mcp
    npm install
    npm run build
    npm test
  6. Set up Neo4j for Memento MCP

    main

    Memento MCP requires Neo4j 5.13+ for vector search capabilities. You can set it up using Neo4j Desktop or Docker.

    1. Download and install Neo4j Desktop.
    2. Create a new project and add a new database.
    3. Set the password to memento_password (or your preferred password).
    4. Start the database.

    Connection Details:

    • Bolt URI: bolt://127.0.0.1:7687
    • HTTP: http://127.0.0.1:7474
    • Default Credentials: neo4j / memento_password

    Option 2: Docker Compose

    Use Docker Compose to run Neo4j. Ensure your docker-compose.yml includes volume mappings to persist data:

    volumes:
      - ./neo4j-data:/data
      - ./neo4j-logs:/logs
      - ./neo4j-import:/import

    Commands:

    # Start Neo4j container
    docker-compose up -d neo4j
    
    # Stop Neo4j container
    docker-compose stop neo4j
    
    # Remove Neo4j container (preserves data via volumes)
    docker-compose rm neo4j
    docker-compose up -d neo4j
  7. Integrate Memento MCP with Claude Desktop

    main

    To use Memento MCP with Claude Desktop, add the server configuration to your claude_desktop_config.json.

    Using npx (Recommended for most users):

    {
      "mcpServers": {
        "memento": {
          "command": "npx",
          "args": ["-y", "@gannonh/memento-mcp"],
          "env": {
            "MEMORY_STORAGE_TYPE": "neo4j",
            "NEO4J_URI": "bolt://127.0.0.1:7687",
            "NEO4J_USERNAME": "neo4j",
            "NEO4J_PASSWORD": "memento_password",
            "NEO4J_DATABASE": "neo4j",
            "NEO4J_VECTOR_INDEX": "entity_embeddings",
            "NEO4J_VECTOR_DIMENSIONS": "1536",
            "NEO4J_SIMILARITY_FUNCTION": "cosine",
            "OPENAI_API_KEY": "your-openai-api-key",
            "OPENAI_EMBEDDING_MODEL": "text-embedding-3-small",
            "DEBUG": "true"
          }
        }
      }
    }

    Local Development (Direct Node path): If developing locally, point the command to your node executable and args to the dist/index.js file of the package.

  8. Install Memento MCP via Smithery

    main

    To automatically install Memento MCP for use with Claude Desktop, use the Smithery CLI. This is the easiest method for setting up the server in a managed environment.

    npx -y @smithery/cli install @gannonh/memento-mcp --client claude
  9. Manage Neo4j Database (Reset, Backup, and Upgrade)

    main

    Upgrading Neo4j

    To upgrade the version without losing data:

    1. Update the Neo4j image version in docker-compose.yml.
    2. Run docker-compose down && docker-compose up -d neo4j.
    3. Reinitialize the schema with npm run neo4j:init.

    Backing Up Data

    Simply copy the local data directory:

    cp -r ./neo4j-data ./neo4j-data-backup-$(date +%Y%m%d)

    Complete Database Reset

    To wipe everything and start fresh:

    # Stop and remove container
    docker-compose stop neo4j
    docker-compose rm -f neo4j
    
    # Delete data directory
    rm -rf ./neo4j-data/*
    
    # Restart and reinitialize
    docker-compose up -d neo4j
    npm run neo4j:init
    cp -r ./neo4j-data ./neo4j-data-backup-$(date +%Y%m%d)
  10. Optimize Claude integration with System Prompts

    main

    To ensure Claude uses Memento MCP effectively, include the following instructions in your system prompt:

    You have access to the Memento MCP knowledge graph memory system, which provides you with persistent memory capabilities.
    Your memory tools are provided by Memento MCP, a sophisticated knowledge graph implementation.
    When asked about past conversations or user information, always check the Memento MCP knowledge graph first.
    You should use semantic_search to find relevant information in your memory when answering questions.
  11. Install Memento MCP locally

    main

    For development or contributing to the project, you can install the package via npm or by cloning the repository.

    # Install via npm
    npm install @gannonh/memento-mcp
    
    # Or clone and install from source
    git clone https://github.com/gannonh/memento-mcp.git
    cd memento-mcp
    npm install