AI Frameworks·
intermediate
·10 min read·Apr 4, 2026·Updated Oct 10, 2026
By Rad Tome·Lead AI Systems Architect·How we verify this

Memory MCP Server Knowledge Graph Guide

Build persistent AI memory across chat sessions using the official Knowledge Graph MCP server. Manage entities, relations, observations, and JSON storage.

memoryknowledge graphpersistent statecontext retentionmodel context protocolclaude desktopentities and relations
Config Target: claude_desktop_config.json
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ]
    }
  }
}
Interactive Tool
1-Click Export

Generate & Test Memory Graph MCP Server Config

One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.

Open in Generator

Memory MCP Server Knowledge Graph Guide

Large language model conversations are traditionally ephemeral. When a developer terminates an inference session or resets a chat window, the agent suffers complete amnesia. Project constraints, team hierarchies, architectural decisions, and user preferences established over hours of interaction vanish from the context window. While system prompts and static retrieval-augmented generation (RAG) provide static background knowledge, they do not provide dynamic, agent-writable long-term memory.

The Memory Model Context Protocol (MCP) server addresses this challenge by providing AI hosts with a persistent, queryable Knowledge Graph engine. Operating over standard JSON-RPC 2.0 stdio streams, the server enables agents to autonomously extract structured entities, map interconnected relationships, record chronological observations, and recall past context across completely independent chat sessions.


1. Problem Statement and Architecture

Standard vector databases store dense embeddings of unstructured text chunks. While effective for semantic document search, vector stores struggle with structured relational recall—such as remembering that "Alex is the tech lead for Project Orion, which depends on Redis cluster 7.2 managed by DevOps". Unstructured chunk retrieval often misses exact entity relationships or pulls conflicting historical assertions.

The Memory MCP server implements a deterministic Entity-Relation-Observation (ERO) knowledge graph stored as a structured JSON database:

  • ▸Entities: Discrete named concepts, services, users, or code repositories (Nodes).
  • ▸Relations: Directed semantic connections between entities (Edges), such as manages, depends_on, owns, or migrated_from.
  • ▸Observations: Fine-grained textual facts and chronological properties associated with individual entities.
code
+-----------------------------------------------------------------------------------+
|                              Client Architecture                                  |
|                                                                                   |
|  +--------------------+        JSON-RPC 2.0 (stdio)        +-------------------+  |
|  |  Claude / Cursor   | <================================> |   server-memory   |  |
|  +--------------------+                                    +---------+---------+  |
+----------------------------------------------------------------------|------------+
                                                                       | Read / Write
                                                                       v Atomic Lock
                                                             +-------------------+
                                                             |    memory.json    |
                                                             |  (Knowledge Graph)|
                                                             +-------------------+

When an agent interacts with the Memory MCP server, it can query existing graph subgraphs before planning an action, insert new entities during user discussions, and update or delete superseded observations when system parameters evolve.


2. Prerequisites and Environment Matrix

The official memory server is distributed through npm as @modelcontextprotocol/server-memory. It requires Node.js 18 or higher and direct write access to a local filesystem directory.

ComponentMinimum VersionRecommendedNotes
Node.js18.18.0+20.x LTS or 22.xRuntime for the server process
Storage EngineLocal DiskSSD / NVMeAtomic file system writes to JSON store
Claude Desktop0.7.0+LatestSupported desktop client
Cursor IDE0.42.0+LatestFull agentic mode with tool execution
OpenAI Codex CLI0.1.0+LatestTerminal-based workflow orchestration

Verify that Node.js and npm are present in your workspace:

bash
node --version
npm --version

3. Multi-Host Configuration Snippets

The server accepts an optional environment variable MEMORY_FILE_PATH pointing to the exact path where the knowledge graph JSON file should be persisted. If omitted, the server defaults to storing data in the application's working directory or temporary storage. Specifying an explicit absolute path is strongly recommended to prevent accidental data loss during system cleanups.

Claude Desktop

Edit your claude_desktop_config.json:

json
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"],
      "env": {
        "MEMORY_FILE_PATH": "/Users/developer/.mcp/memory.json"
      }
    }
  }
}

Cursor IDE

In your project .cursor/mcp.json or global user configuration:

json
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"],
      "env": {
        "MEMORY_FILE_PATH": "/Users/developer/.mcp/memory.json"
      }
    }
  }
}

OpenAI Codex CLI

In ~/.codex/config.toml:

toml
[mcp_servers.memory]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-memory@2026.8.31"]
env = { MEMORY_FILE_PATH = "/Users/developer/.mcp/memory.json" }

4. Step-by-Step Tool Discovery and Invocation

Upon client connection, the server registers seven graph manipulation tools:

Tool NamePurpose
create_entitiesCreate new entity nodes with name, entityType, and observations
create_relationsCreate directed relational edges between existing entities
add_observationsAppend new factual observations to existing entity records
delete_entitiesRemove entities and their cascaded relations
delete_observationsRemove specific outdated observations from an entity
read_graphRetrieve the entire serialized knowledge graph
search_nodesQuery entities and observations by substring keyword matching

Entity Creation Wire Frame

When the user tells an agent: "Remember that Project Alpha is a Next.js frontend managed by Jordan", the host issues:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "create_entities",
    "arguments": {
      "entities": [
        {
          "name": "ProjectAlpha",
          "entityType": "software_project",
          "observations": ["Built using Next.js 15 App Router", "Target deployment on Vercel"]
        },
        {
          "name": "Jordan",
          "entityType": "person",
          "observations": ["Engineering Lead for ProjectAlpha"]
        }
      ]
    }
  }
}

The server responds affirming node creation:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Created 2 entities successfully."
      }
    ],
    "isError": false
  }
}

Relation Creation Wire Frame

The host then links the two entities together:

json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "create_relations",
    "arguments": {
      "relations": [
        {
          "from": "Jordan",
          "to": "ProjectAlpha",
          "relationType": "leads_and_manages"
        }
      ]
    }
  }
}

5. Common Errors and Production Troubleshooting

1. EACCES: permission denied on Memory File

  • ▸Symptom: Server initialization or tool invocation crashes with EACCES: permission denied, open '/var/root/memory.json'.
  • ▸Root Cause: The client spawned the server under a restricted user profile or MEMORY_FILE_PATH points to a protected system directory.
  • ▸Solution: Set MEMORY_FILE_PATH to a dedicated directory inside your user home folder (~/.mcp/memory.json on macOS/Linux or C:\Users\<USER>\.mcp\memory.json on Windows). Ensure parent directories exist prior to launching.
bash
# macOS / Linux
mkdir -p ~/.mcp && chmod 700 ~/.mcp

# Windows PowerShell
New-Item -ItemType Directory -Force -Path "$HOME\.mcp"

2. Entity Fragmentation and Near-Duplicate Nodes

  • ▸Symptom: The AI creates parallel disconnected nodes such as UserAuthService, user-auth-service, and AuthService.
  • ▸Root Cause: The agent issues create_entities without first calling search_nodes to inspect existing nomenclature.
  • ▸Solution: Include an explicit operating rule in your system prompt instructing the agent to always execute search_nodes before inserting new concepts, and perform graph consolidation when duplicates appear.

3. Stale Context and Conflicting Observations

  • ▸Symptom: The agent asserts outdated specifications despite recent changes.
  • ▸Root Cause: New observations were added without calling delete_observations on superseded statements.
  • ▸Solution: Instruct your assistant to prune outdated observations whenever architectural decisions or version pins change.

6. External Citations and Security Guardrails

When persisting user context across sessions, observe core data privacy practices:

  1. ▸Exclude Sensitive Secrets: Never store unencrypted API keys, database credentials, or sensitive personal data inside plaintext memory files.
  2. ▸Backup and Versioning: Because the knowledge graph is stored as human-readable JSON, commit the file to a private Git repository or configure snapshot backups to prevent accidental graph corruption.
  3. ▸Verified Package Hashes: Pin dependencies to audited registry releases to ensure server supply-chain security.
Technical Changelog

Weekly Protocol Diffs & Verified Drops

New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.

Zero marketing spam. 1-click unsubscribe anytime.

Ready to Deploy?

Build your full agent toolstack in the Visual Generator

Combine Memory with databases, search APIs, and memory graphs in a single configuration file.

Customize in Generator
Developer Verification & Feedback
0 reports

Did this setup guide work with your AI host?

Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:

Memory MCP Server Knowledge Graph Guide FAQ

What is the Memory MCP Server Knowledge Graph Guide?

Build persistent AI memory across chat sessions using the official Knowledge Graph MCP server. Manage entities, relations, observations, and JSON storage.

How do I configure Memory MCP Server Knowledge Graph Guide in Claude Desktop or Cursor?

You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.

Can I use Memory MCP Server Knowledge Graph Guide with the OpenAI Codex CLI?

Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.

RT

Written by Rad Tome

Lead AI Systems Architect & Maintainer, MCP Codex

@RadTome

Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.

Editorial Integrity: Package names are checked against the npm registry and repositories against the GitHub API. Where a package could not be verified, the guide says so instead of giving you a command to run.

Related Guides