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.
Install the package globally for convenient access:
npm install -g @pinkpixel/mem0-mcp
Then run the server with:
mem0-mcp
For occasional use, run directly with npx without installation:
npx -y @pinkpixel/mem0-mcp
Clone, build, and run from source:
git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install
npm run build
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"
]
}
}
}
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"
]
}
}
}
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"
]
}
}
}
If using Supabase storage mode:
-- 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
);
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"
}
}
}
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"
}
}
}
Deletes a specific memory by ID:
{
"tool": "delete_memory",
"arguments": {
"memoryId": "mem_123456",
"userId": "user123",
"agentId": "my-assistant",
"appId": "my-project"
}
}
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 IDDEFAULT_AGENT_ID
: Fallback agent IDDEFAULT_APP_ID
: Fallback app IDParameters in tool calls take precedence over environment variables.
When using Cloud Storage mode, additional parameters are available:
For add_memory
:
includes
: Specific preferences to includeexcludes
: Specific preferences to excludeinfer
: Whether to infer memories (default: true)immutable
: Whether the memory is immutable (default: false)expiration_date
: When the memory will expireFor 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
}
For debugging the MCP server:
npm run inspector
console.error()
instead of console.log()
to avoid interfering with the MCP protocolTo 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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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