Knowledge Graph Memory MCP server

Build and query persistent semantic networks for data management.
Back to servers
Provider
Anthropic
Release date
Nov 19, 2024
Language
TypeScript
Package
Stats
86.3K downloads
41.2K stars

The Knowledge Graph Memory Server is a persistent memory implementation that allows Claude to remember information about users across conversations using a local knowledge graph structure. It organizes information through entities, relations, and observations to create a robust system for storing and retrieving user data.

Installation

You can install the Knowledge Graph Memory Server using either Docker or NPX. Choose the installation method that works best for your environment.

Setting up with Claude Desktop

Add one of the following configurations to your claude_desktop_config.json file:

Docker Setup

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

NPX Setup

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

NPX with Custom Settings

You can configure the server using environment variables:

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/path/to/custom/memory.json"
      }
    }
  }
}

VS Code Installation

For VS Code, you can add the configuration to your User Settings JSON file. Open your settings by pressing Ctrl + Shift + P and typing Preferences: Open Settings (JSON).

NPX Option for VS Code

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

Docker Option for VS Code

{
  "mcp": {
    "servers": {
      "memory": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "-v",
          "claude-memory:/app/dist",
          "--rm",
          "mcp/memory"
        ]
      }
    }
  }
}

Alternatively, you can add the configuration to .vscode/mcp.json in your workspace to share with others. Note that in this case, the mcp key is not needed.

Usage

Core Concepts

The Knowledge Graph Memory works with three main components:

Entities

Entities are primary nodes in the knowledge graph with:

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

Example:

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

Relations

Relations define connections between entities:

{
  "from": "John_Smith",
  "to": "Anthropic",
  "relationType": "works_at"
}

Observations

Observations are discrete facts about entities:

{
  "entityName": "John_Smith",
  "observations": [
    "Speaks fluent Spanish",
    "Graduated in 2019",
    "Prefers morning meetings"
  ]
}

API Functions

The server provides several tools for managing the knowledge graph:

Creating Entities

{
  "entities": [
    {
      "name": "John_Smith",
      "entityType": "person",
      "observations": ["Speaks Spanish", "Lives in New York"]
    },
    {
      "name": "Anthropic",
      "entityType": "organization",
      "observations": ["AI research company"]
    }
  ]
}

Creating Relations

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

Adding Observations

{
  "observations": [
    {
      "entityName": "John_Smith",
      "contents": ["Has two dogs", "Enjoys hiking"]
    }
  ]
}

Reading the Graph

The read_graph tool retrieves the entire knowledge graph with no input required.

Searching Nodes

{
  "query": "New York"
}

Opening Specific Nodes

{
  "names": ["John_Smith", "Anthropic"]
}

System Prompt Example

Here's an example prompt for chat personalization that you can use in 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

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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