Mem0 (Autonomous Memory) MCP server

Provides autonomous memory capabilities for storing, retrieving, and utilizing conversation information across sessions, with automatic extraction and categorization of user data for enhanced contextual interactions.
Back to servers
Setup instructions
Provider
Pink Pixel
Release date
Mar 12, 2025
Language
Python
Stats
56 stars

Mem0 MCP Server provides persistent memory capabilities for Large Language Models (LLMs) through the Model Context Protocol. It allows AI agents to store and retrieve information across conversation sessions using the mem0ai Node.js SDK.

Installation Options

Global Installation

Install the package globally for convenient access:

npm install -g @pinkpixel/mem0-mcp

Then run the server with:

mem0-mcp

Using npx

For occasional use, run directly with npx without installation:

npx -y @pinkpixel/mem0-mcp

From Cloned Repository

Clone, build, and run from source:

git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install
npm run build

Storage Modes

Cloud Storage Mode (Recommended for Production)

Uses Mem0's cloud servers for persistent storage:

{
  "mcpServers": {
    "mem0-mcp": {
      "command": "mem0-mcp",
      "args": [],
      "env": {
        "MEM0_API_KEY": "YOUR_MEM0_API_KEY_HERE",
        "DEFAULT_USER_ID": "user123",
        "DEFAULT_AGENT_ID": "your-agent-id",
        "DEFAULT_APP_ID": "your-app-id"
      },
      "disabled": false,
      "alwaysAllow": [
        "add_memory",
        "search_memory",
        "delete_memory"
      ]
    }
  }
}

Supabase Storage Mode (Self-hosting Option)

Stores data in your Supabase database:

{
  "mcpServers": {
    "mem0-mcp": {
      "command": "mem0-mcp",
      "args": [],
      "env": {
        "SUPABASE_URL": "YOUR_SUPABASE_PROJECT_URL",
        "SUPABASE_KEY": "YOUR_SUPABASE_ANON_KEY",
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE",
        "DEFAULT_USER_ID": "user123",
        "DEFAULT_AGENT_ID": "your-agent-id",
        "DEFAULT_APP_ID": "your-app-id"
      },
      "disabled": false,
      "alwaysAllow": [
        "add_memory",
        "search_memory",
        "delete_memory"
      ]
    }
  }
}

Local Storage Mode (Development Only)

Uses in-memory storage (data is lost on restart):

{
  "mcpServers": {
    "mem0-mcp": {
      "command": "mem0-mcp",
      "args": [],
      "env": {
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE",
        "DEFAULT_USER_ID": "user123"
      },
      "disabled": false,
      "alwaysAllow": [
        "add_memory",
        "search_memory",
        "delete_memory"
      ]
    }
  }
}

Supabase Setup

If using Supabase storage mode:

  1. Create a Supabase project at supabase.com
  2. Execute these SQL commands in your Supabase SQL Editor:
-- Enable the vector extension
create extension if not exists vector;

-- Create the memories table
create table if not exists memories (
  id text primary key,
  embedding vector(1536),
  metadata jsonb,
  created_at timestamp with time zone default timezone('utc', now()),
  updated_at timestamp with time zone default timezone('utc', now())
);

-- Create the vector similarity search function
create or replace function match_vectors(
  query_embedding vector(1536),
  match_count int,
  filter jsonb default '{}'::jsonb
)
returns table (
  id text,
  similarity float,
  metadata jsonb
)
language plpgsql
as $$
begin
  return query
  select
    t.id::text,
    1 - (t.embedding <=> query_embedding) as similarity,
    t.metadata
  from memories t
  where case
    when filter::text = '{}'::text then true
    else t.metadata @> filter
  end
  order by t.embedding <=> query_embedding
  limit match_count;
end;
$$;

-- Create the memory_history table for history tracking
create table if not exists memory_history (
  id text primary key,
  memory_id text not null,
  previous_value text,
  new_value text,
  action text not null,
  created_at timestamp with time zone default timezone('utc', now()),
  updated_at timestamp with time zone,
  is_deleted integer default 0
);

Using the MCP Server

Available Tools

add_memory

Stores text content as a memory:

{
  "tool": "add_memory",
  "arguments": {
    "content": "Important information to remember",
    "userId": "user123",
    "sessionId": "conversation-123",
    "agentId": "my-assistant",
    "appId": "my-project",
    "metadata": {
      "location": "New York",
      "category": "finance"
    }
  }
}

search_memory

Searches stored memories based on a query:

{
  "tool": "search_memory",
  "arguments": {
    "query": "What did we discuss about finance?",
    "userId": "user123",
    "sessionId": "conversation-123",
    "agentId": "my-assistant",
    "appId": "my-project",
    "threshold": 0.5,
    "filters": {
      "category": "finance"
    }
  }
}

delete_memory

Deletes a specific memory by ID:

{
  "tool": "delete_memory",
  "arguments": {
    "memoryId": "mem_123456",
    "userId": "user123",
    "agentId": "my-assistant",
    "appId": "my-project"
  }
}

Parameter Configuration

The server uses these key parameters:

  • userId - Identifies the user (required)
  • agentId - Identifies the LLM/agent (optional)
  • appId - Controls project scope (optional)
  • sessionId - Identifies the conversation (optional)

Environment variables can provide defaults:

  • DEFAULT_USER_ID: Fallback user ID
  • DEFAULT_AGENT_ID: Fallback agent ID
  • DEFAULT_APP_ID: Fallback app ID

Parameters in tool calls take precedence over environment variables.

Advanced Usage

Cloud Storage Advanced Parameters

When using Cloud Storage mode, additional parameters are available:

For add_memory:

  • includes: Specific preferences to include
  • excludes: Specific preferences to exclude
  • infer: Whether to infer memories (default: true)
  • immutable: Whether the memory is immutable (default: false)
  • expiration_date: When the memory will expire

For search_memory:

  • top_k: Number of results to return (default: 10)
  • rerank: Whether to rerank results (default: false)
  • keyword_search: Whether to use keyword search (default: false)
  • threshold: Minimum similarity score (default: 0.3)

Example with advanced parameters:

{
  "query": "What are Alice's hobbies?",
  "userId": "user123",
  "filters": {
    "AND": [
      {
        "user_id": "alice"
      },
      {
        "agent_id": {"in": ["travel-agent", "sports-agent"]}
      }
    ]
  },
  "threshold": 0.5,
  "top_k": 5
}

Debugging

For debugging the MCP server:

  1. Use the MCP Inspector:
npm run inspector
  1. Use console.error() instead of console.log() to avoid interfering with the MCP protocol

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 "mem0-mcp" '{"command":"npx","args":["-y","@pinkpixel/mem0-mcp"],"env":{"MEM0_API_KEY":"YOUR_MEM0_API_KEY_HERE","DEFAULT_USER_ID":"user123","DEFAULT_AGENT_ID":"your-agent-id","DEFAULT_APP_ID":"your-app-id"},"disabled":false,"alwaysAllow":["add_memory","search_memory","delete_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": {
        "mem0-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "@pinkpixel/mem0-mcp"
            ],
            "env": {
                "MEM0_API_KEY": "YOUR_MEM0_API_KEY_HERE",
                "DEFAULT_USER_ID": "user123",
                "DEFAULT_AGENT_ID": "your-agent-id",
                "DEFAULT_APP_ID": "your-app-id"
            },
            "disabled": false,
            "alwaysAllow": [
                "add_memory",
                "search_memory",
                "delete_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": {
        "mem0-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "@pinkpixel/mem0-mcp"
            ],
            "env": {
                "MEM0_API_KEY": "YOUR_MEM0_API_KEY_HERE",
                "DEFAULT_USER_ID": "user123",
                "DEFAULT_AGENT_ID": "your-agent-id",
                "DEFAULT_APP_ID": "your-app-id"
            },
            "disabled": false,
            "alwaysAllow": [
                "add_memory",
                "search_memory",
                "delete_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