Mem0 (Long-Term Memory) MCP server

Provides persistent long-term memory capabilities through semantic indexing, retrieval, and search functions with support for multiple LLM providers and PostgreSQL vector storage.
Back to servers
Provider
Cole Medin
Release date
Apr 13, 2025
Language
Python
Stats
284 stars

This is a Model Context Protocol (MCP) server implementation that integrates with Mem0, providing AI agents with persistent memory capabilities. It allows agents to save, retrieve, and semantically search memories, creating a more cohesive and context-aware AI experience.

Prerequisites

Before installing the MCP-Mem0 server, ensure you have:

  • Python 3.12+
  • Supabase or any PostgreSQL database (for vector storage)
  • API keys for your chosen LLM provider (OpenAI, OpenRouter, or Ollama)
  • Docker (recommended, but optional)

Installation

Using uv

  1. Install uv if you don't have it:

    pip install uv
    
  2. Clone the repository:

    git clone https://github.com/coleam00/mcp-mem0.git
    cd mcp-mem0
    
  3. Install dependencies:

    uv pip install -e .
    
  4. Create a configuration file:

    cp .env.example .env
    

Using Docker (Recommended)

  1. Build the Docker image:

    docker build -t mcp/mem0 --build-arg PORT=8050 .
    
  2. Create and configure your .env file based on the .env.example template

Configuration

Configure the following environment variables in your .env file:

Variable Description Example
TRANSPORT Transport protocol (sse or stdio) sse
HOST Host to bind to when using SSE transport 0.0.0.0
PORT Port to listen on when using SSE transport 8050
LLM_PROVIDER LLM provider (openai, openrouter, or ollama) openai
LLM_BASE_URL Base URL for the LLM API https://api.openai.com/v1
LLM_API_KEY API key for the LLM provider sk-...
LLM_CHOICE LLM model to use gpt-4o-mini
EMBEDDING_MODEL_CHOICE Embedding model to use text-embedding-3-small
DATABASE_URL PostgreSQL connection string postgresql://user:pass@host:port/db

Running the Server

Using Python with SSE Transport

Set TRANSPORT=sse in your .env file, then run:

uv run src/main.py

This runs the MCP server as an API endpoint that clients can connect to.

Using Docker with SSE Transport

docker run --env-file .env -p 8050:8050 mcp/mem0

Connecting to the Server

SSE Configuration

After starting the server with SSE transport, connect to it using this configuration:

{
  "mcpServers": {
    "mem0": {
      "transport": "sse",
      "url": "http://localhost:8050/sse"
    }
  }
}

Special Configuration Notes

For Windsurf users:

{
  "mcpServers": {
    "mem0": {
      "transport": "sse",
      "serverUrl": "http://localhost:8050/sse"
    }
  }
}

For n8n users: Use host.docker.internal instead of localhost:

http://host.docker.internal:8050/sse

Python with Stdio Configuration

For Claude Desktop, Windsurf, or other MCP clients:

{
  "mcpServers": {
    "mem0": {
      "command": "your/path/to/mcp-mem0/.venv/Scripts/python.exe",
      "args": ["your/path/to/mcp-mem0/src/main.py"],
      "env": {
        "TRANSPORT": "stdio",
        "LLM_PROVIDER": "openai",
        "LLM_BASE_URL": "https://api.openai.com/v1",
        "LLM_API_KEY": "YOUR-API-KEY",
        "LLM_CHOICE": "gpt-4o-mini",
        "EMBEDDING_MODEL_CHOICE": "text-embedding-3-small",
        "DATABASE_URL": "YOUR-DATABASE-URL"
      }
    }
  }
}

Docker with Stdio Configuration

{
  "mcpServers": {
    "mem0": {
      "command": "docker",
      "args": ["run", "--rm", "-i", 
               "-e", "TRANSPORT", 
               "-e", "LLM_PROVIDER", 
               "-e", "LLM_BASE_URL", 
               "-e", "LLM_API_KEY", 
               "-e", "LLM_CHOICE", 
               "-e", "EMBEDDING_MODEL_CHOICE", 
               "-e", "DATABASE_URL", 
               "mcp/mem0"],
      "env": {
        "TRANSPORT": "stdio",
        "LLM_PROVIDER": "openai",
        "LLM_BASE_URL": "https://api.openai.com/v1",
        "LLM_API_KEY": "YOUR-API-KEY",
        "LLM_CHOICE": "gpt-4o-mini",
        "EMBEDDING_MODEL_CHOICE": "text-embedding-3-small",
        "DATABASE_URL": "YOUR-DATABASE-URL"
      }
    }
  }
}

Using the Memory Tools

The server provides three main memory management tools:

  1. save_memory: Store information in long-term memory with semantic indexing
  2. get_all_memories: Retrieve all stored memories
  3. search_memories: Find relevant memories using semantic search

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