mem0 (long-term memory).com
mem0 (long-term memory).com logo

Mem0 (Long-Term Memory)

Provides persistent long-term memory capabilities through semantic indexing, retrieval, and search functions with suppor...

Created byApr 22, 2025
A template implementation of the Model Context Protocol (MCP) server integrated with Mem0 for providing AI agents with persistent memory capabilities.
Use this as a reference point to build your MCP servers yourself, or give this as an example to an AI coding assistant and tell it to follow this example for structure and code correctness!

Overview

This project demonstrates how to build an MCP server that enables AI agents to store, retrieve, and search memories using semantic search. It serves as a practical template for creating your own MCP servers, simply using Mem0 and a practical example.
The implementation follows the best practices laid out by Anthropic for building MCP servers, allowing seamless integration with any MCP-compatible client.

Features

The server provides three essential memory management tools:
  1. `save_memory`: Store any information in long-term memory with semantic indexing
  1. `get_all_memories`: Retrieve all stored memories for comprehensive context
  1. `search_memories`: Find relevant memories using semantic search

Prerequisites

  • Python 3.12+
  • Supabase or any PostgreSQL database (for vector storage of memories)
  • API keys for your chosen LLM provider (OpenAI, OpenRouter, or Ollama)
  • Docker if running the MCP server as a container (recommended)

Installation

Using uv

  1. Install uv if you don't have it:
  1. Clone this repository:
  1. Install dependencies:
  1. Create a .env file based on .env.example:
  1. Configure your environment variables in the .env file (see Configuration section)

Using Docker (Recommended)

  1. Build the Docker image:
  1. Create a .env file based on .env.example and configure your environment variables

Configuration

The following environment variables can be configured in your .env file:
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

Running the Server

Using uv

SSE Transport

The MCP server will essentially be run as an API endpoint that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client iself can spin up the MCP server, so nothing to run at this point.

Using Docker

SSE Transport

The MCP server will essentially be run as an API endpoint within the container that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client iself can spin up the MCP server container, so nothing to run at this point.

Integration with MCP Clients

SSE Configuration

Once you have the server running with SSE transport, you can connect to it using this configuration:
Note for Windsurf users: Use serverUrl instead of url in your configuration:
Note for n8n users: Use host.docker.internal instead of localhost since n8n has to reach outside of it's own container to the host machine:So the full URL in the MCP node would be: http://host.docker.internal:8050/sse
Make sure to update the port if you are using a value other than the default 8050.

Python with Stdio Configuration

Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:

Docker with Stdio Configuration

Building Your Own Server

This template provides a foundation for building more complex MCP servers. To build your own:
  1. Add your own tools by creating methods with the @mcp.tool() decorator
  1. Create your own lifespan function to add your own dependencies (clients, database connections, etc.)
  1. Modify the utils.py file for any helper functions you need for your MCP server
  1. Feel free to add prompts and resources as well with @mcp.resource() and @mcp.prompt()
A template implementation of the Model Context Protocol (MCP) server integrated with Mem0 for providing AI agents with persistent memory capabilities.
Use this as a reference point to build your MCP servers yourself, or give this as an example to an AI coding assistant and tell it to follow this example for structure and code correctness!

Overview

This project demonstrates how to build an MCP server that enables AI agents to store, retrieve, and search memories using semantic search. It serves as a practical template for creating your own MCP servers, simply using Mem0 and a practical example.
The implementation follows the best practices laid out by Anthropic for building MCP servers, allowing seamless integration with any MCP-compatible client.

Features

The server provides three essential memory management tools:
  1. `save_memory`: Store any information in long-term memory with semantic indexing
  1. `get_all_memories`: Retrieve all stored memories for comprehensive context
  1. `search_memories`: Find relevant memories using semantic search

Prerequisites

  • Python 3.12+
  • Supabase or any PostgreSQL database (for vector storage of memories)
  • API keys for your chosen LLM provider (OpenAI, OpenRouter, or Ollama)
  • Docker if running the MCP server as a container (recommended)

Installation

Using uv

  1. Install uv if you don't have it:
  1. Clone this repository:
  1. Install dependencies:
  1. Create a .env file based on .env.example:
  1. Configure your environment variables in the .env file (see Configuration section)

Using Docker (Recommended)

  1. Build the Docker image:
  1. Create a .env file based on .env.example and configure your environment variables

Configuration

The following environment variables can be configured in your .env file:
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

Running the Server

Using uv

SSE Transport

The MCP server will essentially be run as an API endpoint that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client iself can spin up the MCP server, so nothing to run at this point.

Using Docker

SSE Transport

The MCP server will essentially be run as an API endpoint within the container that you can then connect to with config shown below.

Stdio Transport

With stdio, the MCP client iself can spin up the MCP server container, so nothing to run at this point.

Integration with MCP Clients

SSE Configuration

Once you have the server running with SSE transport, you can connect to it using this configuration:
Note for Windsurf users: Use serverUrl instead of url in your configuration:
Note for n8n users: Use host.docker.internal instead of localhost since n8n has to reach outside of it's own container to the host machine:So the full URL in the MCP node would be: http://host.docker.internal:8050/sse
Make sure to update the port if you are using a value other than the default 8050.

Python with Stdio Configuration

Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:

Docker with Stdio Configuration

Building Your Own Server

This template provides a foundation for building more complex MCP servers. To build your own:
  1. Add your own tools by creating methods with the @mcp.tool() decorator
  1. Create your own lifespan function to add your own dependencies (clients, database connections, etc.)
  1. Modify the utils.py file for any helper functions you need for your MCP server
  1. Feel free to add prompts and resources as well with @mcp.resource() and @mcp.prompt()