Tutorial

MCP Memory Server - Persistent Context for AI Assistants

Set up the Memory MCP server for persistent context across AI conversations. Learn how file-based storage works and explore use cases for project memory and knowledge graphs.

What Is the Memory MCP Server?

The Memory MCP server gives AI assistants the ability to remember information across conversations. By default, AI chat sessions are stateless - when you close a conversation and start a new one, the AI has no memory of what you discussed. The Memory server solves this by providing a persistent knowledge graph that the AI can read from and write to.

Built on the official @modelcontextprotocol/server-memory package, it stores entities, relationships, and observations in a local JSON file. This means your data stays on your machine - nothing is sent to external servers. The AI can create entities (like "Project X uses React and TypeScript"), add observations to them, and query them in future conversations.

This guide covers setup, how persistence works under the hood, practical use cases, and comparisons with other memory approaches.

Setting Up the Memory Server

Claude Desktop Setup

Add the Memory server to your Claude Desktop configuration:

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

The MEMORY_FILE_PATH environment variable controls where the knowledge graph is stored. If omitted, it defaults to a file in the server's working directory. We strongly recommend setting an explicit path so your memory persists across npx updates.

Cursor Setup

Add the server to your Cursor MCP configuration at .cursor/mcp.json:

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

Using a project-relative path (like ./memory/project-memory.json) is ideal for Cursor because each project gets its own memory. Add the memory directory to your .gitignore if the memory contains sensitive information.

Verifying the Setup

After restarting your client, ask the AI: "What tools do you have for memory?" It should list tools like create_entities, add_observations, search_nodes, and open_nodes. If these don't appear, check the tools not showing troubleshooting guide.

How Persistence Works

The Memory server uses a simple but effective file-based storage system. All data is stored as a JSON file on disk with this structure:

{
  "entities": [
    {
      "name": "ProjectAlpha",
      "entityType": "project",
      "observations": [
        "Uses React 19 with TypeScript",
        "Deployed on Vercel",
        "Database is PostgreSQL on Supabase",
        "Has 3 team members: Alice, Bob, Charlie"
      ]
    },
    {
      "name": "Alice",
      "entityType": "person",
      "observations": [
        "Frontend lead on ProjectAlpha",
        "Prefers functional components",
        "Timezone: PST"
      ]
    }
  ],
  "relations": [
    {
      "from": "Alice",
      "to": "ProjectAlpha",
      "relationType": "works_on"
    }
  ]
}

Every time the AI creates an entity or adds an observation, the entire JSON file is rewritten. This is simple and reliable for typical usage (hundreds of entities), but may become slow with thousands of entries. The file is human-readable, so you can also edit it manually.

Important: The Memory server reads from and writes to this file on every operation. If you delete the file, all memory is lost. Back up important memory files regularly.

Use Cases

1. Project Context

The most common use case is storing project details so the AI remembers your tech stack, architecture decisions, and team conventions across sessions. Instead of re-explaining your project every time, you tell the AI once and it remembers.

You: "Remember that our project uses Next.js 15 with App Router,
      Tailwind CSS, and Drizzle ORM with PostgreSQL."

AI: [Creates entity "CurrentProject" with these observations]

--- Next conversation ---

You: "Add a new API route for user profiles."

AI: [Checks memory, sees Next.js 15 + App Router + Drizzle]
    "I'll create a route handler at app/api/profiles/route.ts
     using Drizzle ORM for the database queries..."

2. Conversation Memory

Store key decisions and action items from previous conversations. The AI can track what you discussed, what was decided, and what's still pending.

3. Knowledge Graphs

Build structured knowledge about your codebase, team, or domain. The Memory server's entity-relationship model is essentially a simple knowledge graph. Entities can represent anything - people, projects, services, APIs, bugs - and relationships connect them.

4. Personal Preferences

Store coding preferences so the AI adapts to your style: "I prefer single quotes in TypeScript", "Always use named exports", "Use early returns instead of nested if-else". Once stored, the AI applies these preferences automatically.

5. Meeting Notes and Action Items

After meetings, ask the AI to store key decisions and action items. In the next session, ask "What action items do we have?" and the AI retrieves them from memory.

Comparison with Other Memory Approaches

Approach Persistence Privacy Best For
MCP Memory Server Local file (permanent) Fully local Structured knowledge, project context
Claude Projects Cloud (per project) Anthropic servers Document-heavy context
CLAUDE.md files File in repo Fully local Codebase conventions, team-shared
System prompts Per session Varies Fixed instructions
RAG / Vector DB Database Self-hosted or cloud Large document collections

The MCP Memory server is the best choice when you want structured, queryable, fully local memory that works across any MCP-compatible client. It's lightweight, requires no infrastructure, and gives the AI granular control over what to remember and retrieve.

Tips for Effective Memory Usage

  • Be explicit: Tell the AI "Remember this" or "Save this to memory" - it won't automatically save things unless instructed.
  • Use entity types: Categorize entities as "project", "person", "decision", "preference" for better organization.
  • Clean up periodically: Over time, memory accumulates outdated information. Periodically ask the AI to review and prune old entries.
  • Separate memories per project: Use different MEMORY_FILE_PATH values for different projects to keep memories focused and relevant.
  • Back up memory files: The memory file is just JSON - include it in your backup strategy. You can even version control it (minus sensitive data).

Advanced: Custom Memory Servers

If the default Memory server doesn't meet your needs, you can build a custom memory server. Common customizations include:

  • SQLite backend: Replace JSON file storage with SQLite for better performance with large datasets.
  • Vector search: Add embedding-based search so the AI can find relevant memories by semantic similarity, not just exact matches.
  • Expiring memories: Add TTL (time-to-live) to observations so outdated information is automatically cleaned up.
  • Shared team memory: Store the knowledge graph in a shared location (network drive, S3) so team members share a common context.

For a deeper dive into building custom servers, see our Claude integration tutorial.

Frequently Asked Questions

Related Guides

Ready to explore MCP servers?

Browse 100+ curated MCP servers
Step-by-step setup tutorials
Community-driven reviews and ratings