This server provides persistent memory capabilities for AI agents through integration with Mem0.ai, allowing them to:
Store Memories: Save text content as memories associated with specific users, sessions, or agents with optional metadata
Search Memories: Retrieve relevant memories using semantic similarity or advanced filtering options
Delete Memories: Remove specific memories by their unique ID
Choose Storage Method: Use either persistent cloud storage (Mem0 API) or non-persistent local storage (OpenAI API)
Advanced Organization: Leverage metadata, complex filters, similarity thresholds, and other parameters for sophisticated memory management
Seamless Integration: Works with MCP clients like Claude Desktop, Cursor, or Cline for AI agent development
Supports Google's AI models for memory functionality and context management
Draws inspiration from LangChain for memory management capabilities
Provides integration with Ollama for local LLM support and embedding generation
Utilizes OpenAI's models for both text processing and embedding generation
Uses SQLite for local storage of memory data
@pinkpixel/mem0-mcp 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.
Features š§
Tools
add_memory: Stores a piece of text content as a memory associated with a specificuserId.Required:
content(string),userId(string)Optional:
sessionId(string),agentId(string),appId(string),metadata(object)Advanced (Cloud API):
includes(string),excludes(string),infer(boolean),outputFormat(string),customCategories(object),customInstructions(string),immutable(boolean),expirationDate(string)Stores the provided text, enabling recall in future interactions.
search_memory: Searches stored memories based on a natural language query for a specificuserId.Required:
query(string),userId(string)Optional:
sessionId(string),agentId(string),appId(string),filters(object),threshold(number)Advanced (Cloud API):
topK(number),fields(array),rerank(boolean),keywordSearch(boolean),filterMemories(boolean)Retrieves relevant memories based on semantic similarity.
delete_memory: Deletes a specific memory from storage by its ID.Required:
memoryId(string),userId(string)Optional:
agentId(string),appId(string)Permanently removes the specified memory.
Related MCP server: Just Prompt
Prerequisites š
This server supports three storage modes:
Cloud Storage Mode āļø (Recommended for production)
Requires a Mem0 API key (provided as
MEM0_API_KEYenvironment variable)Memories are persistently stored on Mem0's cloud servers
No local database needed
Full feature support with advanced filtering and search
Supabase Storage Mode šļø (Recommended for self-hosting)
Requires Supabase credentials (
SUPABASE_URLandSUPABASE_KEYenvironment variables)Requires OpenAI API key (
OPENAI_API_KEYenvironment variable) for embeddingsMemories are persistently stored in your Supabase database
Free tier available, self-hostable option
Requires initial database setup (SQL migrations provided below)
Local Storage Mode š¾ (Development/testing only)
Requires an OpenAI API key (provided as
OPENAI_API_KEYenvironment variable)Memories are stored in an in-memory vector database (non-persistent by default)
Data is lost when the server restarts unless configured for persistent storage
Installation & Configuration āļø
You can run this server in three main ways:
Installing via Smithery
To install Mem0 Memory Server for Claude Desktop automatically via Smithery:
1. Global Installation (Recommended for frequent use)
Install the package globally and use the mem0-mcp command:
After global installation, you can run the server directly:
Configure your MCP client to use the global command:
Cloud Storage Configuration (Global Install)
Supabase Storage Configuration (Global Install)
Local Storage Configuration (Global Install)
2. Using npx (Recommended for occasional use)
Configure your MCP client (e.g., Claude Desktop, Cursor, Cline, Roo Code, etc.) to run the server using npx:
Cloud Storage Configuration (npx)
Supabase Storage Configuration (npx)
Local Storage Configuration (npx)
3. Running from Cloned Repository
Note: This method requires you to git clone the repository first.
Clone the repository, install dependencies, and build the server:
Then, configure your MCP client to run the built script directly using node:
Cloud Storage Configuration (Cloned Repository)
Supabase Storage Configuration (Cloned Repository)
Local Storage Configuration (Cloned Repository)
Important Notes:
Replace
/absolute/path/to/mem0-mcp/with the actual absolute path to your cloned repositoryUse the
build/index.jsfile, not thesrc/index.tsfileThe MCP server requires clean stdout for protocol communication - any libraries or code that writes to stdout may interfere with the protocol
Supabase Setup šļø
If you choose to use Supabase storage mode, you'll need to set up your Supabase database with the required table.
1. Create a Supabase Project
Go to supabase.com and create a new project
Note your project URL and anon key from the project settings
2. Run SQL Migrations
Run these SQL commands in your Supabase SQL Editor:
3. Set Environment Variables
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)
Benefits of Supabase Mode
ā 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
Parameter Configuration šÆ
Understanding Mem0 Parameters
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 torun_idin Mem0) (optional)
Environment Variable Fallbacks š
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
Priority Order (Important!)
Tool Parameters (highest priority) - Values provided by the LLM in tool calls
Environment Variables (fallback) - Values from your MCP configuration
Example Behavior:
If LLM provides parameters:
Result: Uses session-123, different-agent, and special-project
If LLM omits parameters:
Result: Uses john-doe, my-assistant, and my-project
Controlling LLM Behavior
To ensure your environment variables are used, instruct your LLM:
"Use the default user ID configured in the environment"
"Don't specify userId, agentId, or appId parameters"
"Let the server use the configured defaults"
System Prompt Recommendation
For best results, include instructions in your system prompt like:
Example configuration using DEFAULT_USER_ID:
Or when running directly with node:
Storage Mode Comparison š
Cloud Storage (Mem0 API) āļø
Persistent by default - Your memories remain available across sessions and server restarts
No local database required - All data is stored on Mem0's servers
Higher retrieval quality - Uses Mem0's optimized search algorithms
Additional fields - Supports
agent_idandthresholdparametersFully managed - No setup or maintenance required
Requires - A Mem0 API key
Supabase Storage šļø
Persistent storage - Data is stored in your Supabase PostgreSQL database
Free tier available - Generous free tier for development and small projects
Self-hostable - Can run your own Supabase instance for complete control
SQL access - Direct database access for advanced queries and analytics
Scalable - Grows with your needs, from free tier to enterprise
Vector search - Uses pgvector extension for efficient similarity search
Real-time features - Built-in real-time subscriptions and webhooks
Requires - Supabase project setup and OpenAI API key for embeddings
Local Storage (OpenAI API) š¾
In-memory by default - Data is stored only in RAM and is not persistent long-term. While some caching may occur, you should not rely on this for permanent storage.
Data loss risk - Memory data will be lost on server restart, system reboot, or if the process is terminated
Recommended for - Development, testing, or temporary use only
For persistent storage - Use the Cloud Storage or Supabase options if you need reliable long-term memory
Uses OpenAI embeddings - For vector search functionality
Self-contained - All data stays on your machine
Requires - An OpenAI API key
Development š»
Clone the repository and install dependencies:
Build the server:
For development with auto-rebuild on file changes:
Debugging š
Since MCP servers communicate over stdio, debugging can be challenging. Here are some approaches:
Use the MCP Inspector: This tool can monitor the MCP protocol communication:
Console Logging: When adding console logs, always use
console.error()instead ofconsole.log()to avoid interfering with the MCP protocolEnvironment Files: Use a
.envfile for local development to simplify setting API keys and other configuration options
Technical Implementation Notes š§
Advanced Mem0 API Parameters
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:
Advanced Parameters for add_memory:
Parameter | Type | Description |
| object | Store additional context about the memory (e.g., location, time, identifiers). This can be used for filtering during retrieval. |
| string | Specific preferences to include in the memory. |
| string | Specific preferences to exclude from the memory. |
| boolean | Whether to infer memories or directly store messages (default: true). |
| string | Format version, either v1.0 (default, deprecated) or v1.1 (recommended). |
| object | List of categories with names and descriptions. |
| string | Project-specific guidelines for handling and organizing memories. |
| boolean | Whether the memory is immutable (default: false). |
| string | When the memory will expire (format: YYYY-MM-DD). |
| string | Organization ID associated with this memory. |
| string | Project ID associated with this memory. |
| 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:
Advanced Parameters for search_memory:
The Mem0 v2 search API offers powerful filtering capabilities that can be utilized through the filters parameter:
Parameter | Type | Description |
| object | Complex filters with logical operators and comparison conditions |
| integer | Number of top results to return (default: 10) |
| string[] | Specific fields to include in the response |
| boolean | Whether to rerank the memories (default: false) |
| boolean | Whether to search based on keywords (default: false) |
| boolean | Whether to filter the memories (default: false) |
| number | Minimum similarity threshold for results (default: 0.3) |
| string | Organization ID for filtering memories |
| string | Project ID for filtering memories |
The filters parameter supports complex logical operations (AND, OR) and various comparison operators:
Operator | Description |
| Matches any of the values specified |
| Greater than or equal to |
| Less than or equal to |
| Greater than |
| Less than |
| Not equal to |
| Case-insensitive containment check |
Example of using complex filters with the search_memory tool:
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.
SafeLogger
The MCP server implements a SafeLogger class that selectively redirects console.log calls from the mem0ai library to stderr without disrupting MCP protocol:
Intercepts console.log calls and examines stack traces to determine source
Only redirects log calls from mem0ai library or our own code
Preserves clean stdout for MCP protocol communication
Automatically cleans up resources on process exit
This allows proper functioning within MCP clients while maintaining useful debug information.
Environment Variables
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 scoping
Important Notes:
Session IDs are passed as tool parameters (e.g.,
"sessionId": "my-session"), not environment variablesWhen using the tools, parameters provided directly (e.g.,
agentId,appId,sessionId) take precedence over environment variables, giving you maximum flexibilityorg_id and project_id are set automatically by Mem0 and cannot be changed by users - use
appIdfor project scoping instead
Made with ā¤ļø by Pink Pixel