✨ mem0 MCP Server: A memory system using mem0 for AI applications with model context protocl (MCP) integration. Enables long-term memory for AI agents as a drop-in MCP server.
A Model Context Protocol (MCP) server that integrates with Mem0.ai to provide persistent memory capabilities for LLMs. It allows AI agents to store and retrieve information across sessions.
This server uses the mem0ai
Node.js SDK for its core functionality.
add_memory
: Stores a piece of text content as a memory associated with a specific userId
.
content
(string), userId
(string)sessionId
(string), agentId
(string), appId
(string), metadata
(object)includes
(string), excludes
(string), infer
(boolean), outputFormat
(string), customCategories
(object), customInstructions
(string), immutable
(boolean), expirationDate
(string)search_memory
: Searches stored memories based on a natural language query for a specific userId
.
query
(string), userId
(string)sessionId
(string), agentId
(string), appId
(string), filters
(object), threshold
(number)topK
(number), fields
(array), rerank
(boolean), keywordSearch
(boolean), filterMemories
(boolean)delete_memory
: Deletes a specific memory from storage by its ID.
memoryId
(string), userId
(string)agentId
(string), appId
(string)This server supports three storage modes:
Cloud Storage Mode ☁️ (Recommended for production)
MEM0_API_KEY
environment variable)Supabase Storage Mode 🗄️ (Recommended for self-hosting)
SUPABASE_URL
and SUPABASE_KEY
environment variables)OPENAI_API_KEY
environment variable) for embeddingsLocal Storage Mode 💾 (Development/testing only)
OPENAI_API_KEY
environment variable)You can run this server in three main ways:
Install the package globally and use the mem0-mcp
command:
npm install -g @pinkpixel/mem0-mcp
After global installation, you can run the server directly:
mem0-mcp
Configure your MCP client to use the global command:
{
"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"
]
}
}
}
{
"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"
]
}
}
}
{
"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"
]
}
}
}
npx
(Recommended for occasional use)Configure your MCP client (e.g., Claude Desktop, Cursor, Cline, Roo Code, etc.) to run the server using npx
:
{
"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"
]
}
}
}
{
"mcpServers": {
"mem0-mcp": {
"command": "npx",
"args": [
"-y",
"@pinkpixel/mem0-mcp"
],
"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"
]
}
}
}
{
"mcpServers": {
"mem0-mcp": {
"command": "npx",
"args": [
"-y",
"@pinkpixel/mem0-mcp"
],
"env": {
"OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE",
"DEFAULT_USER_ID": "user123"
},
"disabled": false,
"alwaysAllow": [
"add_memory",
"search_memory",
"delete_memory"
]
}
}
}
Note: This method requires you to git clone the repository first.
Clone the repository, install dependencies, and build the server:
git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install
npm run build
Then, configure your MCP client to run the built script directly using node
:
{
"mcpServers": {
"mem0-mcp": {
"command": "node",
"args": [
"/absolute/path/to/mem0-mcp/build/index.js"
],
"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"
]
}
}
}
{
"mcpServers": {
"mem0-mcp": {
"command": "node",
"args": [
"/absolute/path/to/mem0-mcp/build/index.js"
],
"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"
]
}
}
}
{
"mcpServers": {
"mem0-mcp": {
"command": "node",
"args": [
"/absolute/path/to/mem0-mcp/build/index.js"
],
"env": {
"OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE",
"DEFAULT_USER_ID": "user123"
},
"disabled": false,
"alwaysAllow": [
"add_memory",
"search_memory",
"delete_memory"
]
}
}
}
Important Notes:
/absolute/path/to/mem0-mcp/
with the actual absolute path to your cloned repositorybuild/index.js
file, not the src/index.ts
fileIf you choose to use Supabase storage mode, you'll need to set up your Supabase database with the required table.
Run 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
);
Add these to your MCP configuration:
SUPABASE_URL
: Your Supabase project URL (e.g., https://your-project.supabase.co
)SUPABASE_KEY
: Your Supabase anon keyOPENAI_API_KEY
: Your OpenAI API key (for embeddings)✅ Persistent Storage - Data survives server restarts ✅ Free Tier Available - Generous free tier for development ✅ Self-Hostable - Can run your own Supabase instance ✅ Scalable - Grows with your needs ✅ SQL Access - Direct database access for advanced queries ✅ Real-time Features - Built-in real-time subscriptions
The server uses four key parameters to organize and scope memories:
userId
- Identifies the user (required)agentId
- Identifies the LLM/agent making the tool call (optional)appId
- Identifies the user's project/application - this controls project scope! (optional)sessionId
- Identifies the conversation session (maps to run_id
in Mem0) (optional)The MCP server supports environment variable fallbacks for user identification and project settings:
DEFAULT_USER_ID
: Fallback user ID when not provided in tool callsDEFAULT_AGENT_ID
: Fallback agent ID for identifying the LLM/agentDEFAULT_APP_ID
: Fallback app ID for project scoping// Your MCP config
"env": {
"DEFAULT_USER_ID": "john-doe",
"DEFAULT_AGENT_ID": "my-assistant",
"DEFAULT_APP_ID": "my-project"
}
If LLM provides parameters:
{
"tool": "add_memory",
"arguments": {
"content": "Remember this",
"userId": "session-123", // ← Overrides DEFAULT_USER_ID
"agentId": "different-agent", // ← Overrides DEFAULT_AGENT_ID
"appId": "special-project" // ← Overrides DEFAULT_APP_ID
// sessionId omitted // ← No fallback, will be undefined
}
}
Result: Uses session-123
, different-agent
, and special-project
If LLM omits parameters:
{
"tool": "add_memory",
"arguments": {
"content": "Remember this"
// All IDs omitted - uses environment variables
}
}
Result: Uses john-doe
, my-assistant
, and my-project
To ensure your environment variables are used, instruct your LLM:
For best results, include instructions in your system prompt like:
When creating memories, use:
- agentId: "my-assistant"
- appId: "my-project"
- sessionId: "current-conversation-id"
Example configuration using DEFAULT_USER_ID
:
{
"mcpServers": {
"mem0-mcp": {
"command": "npx",
"args": [
"-y",
"@pinkpixel/mem0-mcp"
],
"env": {
"MEM0_API_KEY": "YOUR_MEM0_API_KEY_HERE",
"DEFAULT_USER_ID": "user123",
"ORG_ID": "your-org-id",
"PROJECT_ID": "your-project-id"
}
}
}
}
Or when running directly with node
:
git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install
npm run build
{
"mcpServers": {
"mem0-mcp": {
"command": "node",
"args": [
"path/to/mem0-mcp/build/index.js"
],
"env": {
"OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE",
"DEFAULT_USER_ID": "user123"
}
}
}
}
agent_id
and threshold
parametersClone the repository and install dependencies:
git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install
Build the server:
npm run build
For development with auto-rebuild on file changes:
npm run watch
Since MCP servers communicate over stdio, debugging can be challenging. Here are some approaches:
npm run inspector
Console Logging: When adding console logs, always use console.error()
instead of console.log()
to avoid interfering with the MCP protocol
Environment Files: Use a .env
file for local development to simplify setting API keys and other configuration options
When using the Cloud Storage mode with the Mem0 API, you can leverage additional parameters for more sophisticated memory management. While not explicitly exposed in the tool schema, these can be included in the metadata
object when adding memories:
add_memory
:Parameter | Type | Description |
---|---|---|
metadata | object | Store additional context about the memory (e.g., location, time, identifiers). This can be used for filtering during retrieval. |
includes | string | Specific preferences to include in the memory. |
excludes | string | Specific preferences to exclude from the memory. |
infer | boolean | Whether to infer memories or directly store messages (default: true). |
output_format | string | Format version, either v1.0 (default, deprecated) or v1.1 (recommended). |
custom_categories | object | List of categories with names and descriptions. |
custom_instructions | string | Project-specific guidelines for handling and organizing memories. |
immutable | boolean | Whether the memory is immutable (default: false). |
expiration_date | string | When the memory will expire (format: YYYY-MM-DD). |
org_id | string | Organization ID associated with this memory. |
project_id | string | Project ID associated with this memory. |
version | string | Memory version (v1 is deprecated, v2 recommended for new applications). |
To use these parameters with the MCP server, include them in your metadata object when calling the add_memory
tool. For example:
{
"content": "Important information to remember",
"userId": "user123",
"sessionId": "project-abc",
"metadata": {
"includes": "important context",
"excludes": "sensitive data",
"immutable": true,
"expiration_date": "2025-12-31",
"custom_instructions": "Prioritize this memory for financial questions",
"version": "v2"
}
}
search_memory
:The Mem0 v2 search API offers powerful filtering capabilities that can be utilized through the filters
parameter:
Parameter | Type | Description |
---|---|---|
filters | object | Complex filters with logical operators and comparison conditions |
top_k | integer | Number of top results to return (default: 10) |
fields | string[] | Specific fields to include in the response |
rerank | boolean | Whether to rerank the memories (default: false) |
keyword_search | boolean | Whether to search based on keywords (default: false) |
filter_memories | boolean | Whether to filter the memories (default: false) |
threshold | number | Minimum similarity threshold for results (default: 0.3) |
org_id | string | Organization ID for filtering memories |
project_id | string | Project ID for filtering memories |
The filters
parameter supports complex logical operations (AND, OR) and various comparison operators:
Operator | Description |
---|---|
in | Matches any of the values specified |
gte | Greater than or equal to |
lte | Less than or equal to |
gt | Greater than |
lt | Less than |
ne | Not equal to |
icontains | Case-insensitive containment check |
Example of using complex filters with the search_memory
tool:
{
"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
}
This would search for memories related to Alice's hobbies where the user_id is "alice" AND the agent_id is either "travel-agent" OR "sports-agent", returning at most 5 results with a similarity score of at least 0.5.
For more detailed information on these parameters, refer to the Mem0 API documentation.
The MCP server implements a SafeLogger
class that selectively redirects console.log calls from the mem0ai library to stderr without disrupting MCP protocol:
This allows proper functioning within MCP clients while maintaining useful debug information.
The server recognizes several environment variables that control its behavior:
MEM0_API_KEY
: API key for cloud storage modeOPENAI_API_KEY
: API key for local storage mode (embeddings)DEFAULT_USER_ID
: Default user ID for memory operationsDEFAULT_AGENT_ID
: Default agent ID for identifying the LLM/agentDEFAULT_APP_ID
: Default app ID for project scopingImportant Notes:
"sessionId": "my-session"
), not environment variablesagentId
, appId
, sessionId
) take precedence over environment variables, giving you maximum flexibilityappId
for project scoping insteadMade with ❤️ by Pink Pixel
No configuration available
This service may require manual configuration, please check the details on the left
Related projects feature coming soon
Will recommend related projects based on sub-categories