Skip to content
Back to search

mcp-mem0

MCP server for long term agent memory with Mem0. Also useful as a template to get you started building your own MCP server with Python!

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/coleam00--mcp-mem0/badge.svg)](/listings/coleam00--mcp-mem0)

HTML

<a href="/listings/coleam00--mcp-mem0"><img src="/api/listings/coleam00--mcp-mem0/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Using uv

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

   pip install uv

2. Clone this repository:

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

3. Install dependencies:

   uv pip install -e .

4. Create a `.env` file based on `.env.example`:

   cp .env.example .env

5. Configure your environment variables in the `.env` file (see Configuration section)

Using Docker (Recommended)

1. Build the Docker image:

   docker build -t mcp/mem0 --build-arg PORT=8050 .

2. Create a `.env` file based on `.env.example` and configure your environment variables

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 211 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <h1 align="center">MCP-Mem0: Long-Term Memory for AI Agents</h1>
  2. <p align="center">
  3. <img src="public/Mem0AndMCP.png" alt="Mem0 and MCP Integration" width="600">
  4. </p>
  5. A template implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server integrated with [Mem0](https://mem0.ai) for providing AI agents with persistent memory capabilities.
  6. 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!
  7. ## Overview
  8. 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.
  9. The implementation follows the best practices laid out by Anthropic for building MCP servers, allowing seamless integration with any MCP-compatible client.
  10. ## Features
  11. The server provides three essential memory management tools:
  12. 1. **`save_memory`**: Store any information in long-term memory with semantic indexing
  13. 2. **`get_all_memories`**: Retrieve all stored memories for comprehensive context
  14. 3. **`search_memories`**: Find relevant memories using semantic search
  15. ## Prerequisites
  16. - Python 3.12+
  17. - Supabase or any PostgreSQL database (for vector storage of memories)
  18. - API keys for your chosen LLM provider (OpenAI, OpenRouter, or Ollama)
  19. - Docker if running the MCP server as a container (recommended)
  20. ## Installation
  21. ### Using uv
  22. 1. Install uv if you don't have it:
  23. ```bash
  24. pip install uv
  25. ```
  26. 2. Clone this repository:
  27. ```bash
  28. git clone https://github.com/coleam00/mcp-mem0.git
  29. cd mcp-mem0
  30. ```
  31. 3. Install dependencies:
  32. ```bash
  33. uv pip install -e .
  34. ```
  35. 4. Create a `.env` file based on `.env.example`:
  36. ```bash
  37. cp .env.example .env
  38. ```
  39. 5. Configure your environment variables in the `.env` file (see Configuration section)
  40. ### Using Docker (Recommended)
  41. 1. Build the Docker image:
  42. ```bash
  43. docker build -t mcp/mem0 --build-arg PORT=8050 .
  44. ```
  45. 2. Create a `.env` file based on `.env.example` and configure your environment variables
  46. ## Configuration
  47. The following environment variables can be configured in your `.env` file:
  48. | Variable | Description | Example |
  49. |----------|-------------|----------|
  50. | `TRANSPORT` | Transport protocol (sse or stdio) | `sse` |
  51. | `HOST` | Host to bind to when using SSE transport | `0.0.0.0` |
  52. | `PORT` | Port to listen on when using SSE transport | `8050` |
  53. | `LLM_PROVIDER` | LLM provider (openai, openrouter, or ollama) | `openai` |
  54. | `LLM_BASE_URL` | Base URL for the LLM API | `https://api.openai.com/v1` |
  55. | `LLM_API_KEY` | API key for the LLM provider | `sk-...` |
  56. | `LLM_CHOICE` | LLM model to use | `gpt-4o-mini` |
  57. | `EMBEDDING_MODEL_CHOICE` | Embedding model to use | `text-embedding-3-small` |
  58. | `DATABASE_URL` | PostgreSQL connection string | `postgresql://user:pass@host:port/db` |
  59. ## Running the Server
  60. ### Using uv
  61. #### SSE Transport
  62. ```bash
  63. # Set TRANSPORT=sse in .env then:
  64. uv run src/main.py
  65. ```
  66. The MCP server will essentially be run as an API endpoint that you can then connect to with config shown below.
  67. #### Stdio Transport
  68. With stdio, the MCP client iself can spin up the MCP server, so nothing to run at this point.
  69. ### Using Docker
  70. #### SSE Transport
  71. ```bash
  72. docker run --env-file .env -p:8050:8050 mcp/mem0
  73. ```
  74. The MCP server will essentially be run as an API endpoint within the container that you can then connect to with config shown below.
  75. #### Stdio Transport
  76. With stdio, the MCP client iself can spin up the MCP server container, so nothing to run at this point.
  77. ## Integration with MCP Clients
  78. ### SSE Configuration
  79. Once you have the server running with SSE transport, you can connect to it using this configuration:
  80. ```json
  81. {
  82. "mcpServers": {
  83. "mem0": {
  84. "transport": "sse",
  85. "url": "http://localhost:8050/sse"
  86. }
  87. }
  88. }
  89. ```
  90. > **Note for Windsurf users**: Use `serverUrl` instead of `url` in your configuration:
  91. > ```json
  92. > {
  93. > "mcpServers": {
  94. > "mem0": {
  95. > "transport": "sse",
  96. > "serverUrl": "http://localhost:8050/sse"
  97. > }
  98. > }
  99. > }
  100. > ```
  101. > **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:
  102. >
  103. > So the full URL in the MCP node would be: http://host.docker.internal:8050/sse
  104. Make sure to update the port if you are using a value other than the default 8050.
  105. ### Python with Stdio Configuration
  106. Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:
  107. ```json
  108. {
  109. "mcpServers": {
  110. "mem0": {
  111. "command": "your/path/to/mcp-mem0/.venv/Scripts/python.exe",
  112. "args": ["your/path/to/mcp-mem0/src/main.py"],
  113. "env": {
  114. "TRANSPORT": "stdio",
  115. "LLM_PROVIDER": "openai",
  116. "LLM_BASE_URL": "https://api.openai.com/v1",
  117. "LLM_API_KEY": "YOUR-API-KEY",
  118. "LLM_CHOICE": "gpt-4o-mini",
  119. "EMBEDDING_MODEL_CHOICE": "text-embedding-3-small",
  120. "DATABASE_URL": "YOUR-DATABASE-URL"
  121. }
  122. }
  123. }
  124. }
  125. ```
  126. ### Docker with Stdio Configuration
  127. ```json
  128. {
  129. "mcpServers": {
  130. "mem0": {
  131. "command": "docker",
  132. "args": ["run", "--rm", "-i",
  133. "-e", "TRANSPORT",
  134. "-e", "LLM_PROVIDER",
  135. "-e", "LLM_BASE_URL",
  136. "-e", "LLM_API_KEY",
  137. "-e", "LLM_CHOICE",
  138. "-e", "EMBEDDING_MODEL_CHOICE",
  139. "-e", "DATABASE_URL",
  140. "mcp/mem0"],
  141. "env": {
  142. "TRANSPORT": "stdio",
  143. "LLM_PROVIDER": "openai",
  144. "LLM_BASE_URL": "https://api.openai.com/v1",
  145. "LLM_API_KEY": "YOUR-API-KEY",
  146. "LLM_CHOICE": "gpt-4o-mini",
  147. "EMBEDDING_MODEL_CHOICE": "text-embedding-3-small",
  148. "DATABASE_URL": "YOUR-DATABASE-URL"
  149. }
  150. }
  151. }
  152. }
  153. ```
  154. ## Building Your Own Server
  155. This template provides a foundation for building more complex MCP servers. To build your own:
  156. 1. Add your own tools by creating methods with the `@mcp.tool()` decorator
  157. 2. Create your own lifespan function to add your own dependencies (clients, database connections, etc.)
  158. 3. Modify the `utils.py` file for any helper functions you need for your MCP server
  159. 4. Feel free to add prompts and resources as well with `@mcp.resource()` and `@mcp.prompt()`

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.