Optimized Memory MCP server

Integrates with SQLite to provide a persistent knowledge graph for efficient memory management and relationship modeling across conversations.
Back to servers
Setup instructions
Provider
Herman Wong
Release date
Jan 01, 2025
Language
Python
Stats
6 stars

This MCP (Model Context Protocol) server implementation provides persistent memory capabilities for AI assistants using a knowledge graph structure. It allows Claude to remember information about users across multiple conversations through entities, relations, and observations stored in a local SQLite database.

Installation

You can set up the MCP memory server using either Docker or NPX.

Docker Installation

  1. Build the Docker image:

    docker build -t mcp/memory -f src/memory/Dockerfile .
    
  2. Add this configuration to your claude_desktop_config.json:

    {
      "mcpServers": {
        "memory": {
          "command": "docker",
          "args": ["run", "-i", "--rm", "mcp/memory"]
        }
      }
    }
    

NPX Installation

Alternatively, you can use NPX to run the server:

  1. Add this configuration to your claude_desktop_config.json:
    {
      "mcpServers": {
        "memory": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-memory"
          ]
        }
      }
    }
    

Usage

System Prompt Configuration

To use the memory server effectively, you need to configure an appropriate system prompt. Here's an example for chat personalization that you can add to the "Custom Instructions" field of a Claude.ai Project:

Follow these steps for each interaction:

1. User Identification:
   - You should assume that you are interacting with default_user
   - If you have not identified default_user, proactively try to do so.

2. Memory Retrieval:
   - Always begin your chat by saying only "Remembering..." and retrieve all relevant information from your knowledge graph
   - Always refer to your knowledge graph as your "memory"

3. Memory
   - While conversing with the user, be attentive to any new information that falls into these categories:
     a) Basic Identity (age, gender, location, job title, education level, etc.)
     b) Behaviors (interests, habits, etc.)
     c) Preferences (communication style, preferred language, etc.)
     d) Goals (goals, targets, aspirations, etc.)
     e) Relationships (personal and professional relationships up to 3 degrees of separation)

4. Memory Update:
   - If any new information was gathered during the interaction, update your memory as follows:
     a) Create entities for recurring organizations, people, and significant events
     b) Connect them to the current entities using relations
     b) Store facts about them as observations

Available API Tools

The MCP memory server provides several tools that Claude can use to interact with the knowledge graph:

Entity Management

  • create_entities: Create new entities in the knowledge graph

    {
      "entities": [
        {
          "name": "John_Smith",
          "entityType": "person",
          "observations": ["Speaks fluent Spanish"]
        }
      ]
    }
    
  • delete_entities: Remove entities and their relations

    {
      "entityNames": ["John_Smith"]
    }
    

Relation Management

  • create_relations: Create relationships between entities

    {
      "relations": [
        {
          "from": "John_Smith",
          "to": "Anthropic",
          "relationType": "works_at"
        }
      ]
    }
    
  • delete_relations: Remove specific relations

    {
      "relations": [
        {
          "from": "John_Smith",
          "to": "Anthropic",
          "relationType": "works_at"
        }
      ]
    }
    

Observation Management

  • add_observations: Add observations to existing entities

    {
      "observations": [
        {
          "entityName": "John_Smith",
          "contents": ["Graduated in 2019", "Prefers morning meetings"]
        }
      ]
    }
    
  • delete_observations: Remove specific observations

    {
      "deletions": [
        {
          "entityName": "John_Smith",
          "observations": ["Prefers morning meetings"]
        }
      ]
    }
    

Query Tools

  • read_graph: Read the entire knowledge graph (no input required)
  • search_nodes: Search for nodes matching a query
    {
      "query": "Spanish"
    }
    
  • open_nodes: Retrieve specific nodes by name
    {
      "names": ["John_Smith", "Anthropic"]
    }
    

Knowledge Graph Structure

Entities

Entities are the primary nodes in the graph, each having:

  • A unique name (identifier)
  • An entity type (e.g., "person", "organization")
  • A list of observations (facts about the entity)

Relations

Relations define connections between entities with:

  • Source entity ("from")
  • Target entity ("to")
  • Relationship type in active voice

Observations

Observations are discrete facts about entities:

  • Stored as strings
  • Attached to specific entities
  • Should contain one fact per observation

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "memory" '{"command":"npx","args":["-y","@modelcontextprotocol/server-memory"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "memory": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-memory"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "memory": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-memory"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later