Note: This project has been developed and maintained using Claude Code for enhanced code quality, accuracy, and completeness.
A Model Context Protocol (MCP) server that provides memory storage and retrieval capabilities using Mem0. This tool allows you to store and search through memories, making it useful for maintaining context and making informed decisions based on past interactions.
- Store memories with user-specific context
- Search through stored memories with relevance scoring
- Simple and intuitive API
- Built on the Model Context Protocol
- Automatic error handling
- Support for multiple user contexts
Follow these steps to run the server from the source code on your local machine. This is the best way to test changes before deployment.
1. Prerequisites
- Node.js (v16 or higher)
- pnpm package manager (install with
npm i -g pnpm
or visit pnpm.io) - A Mem0 API key, which can be obtained from the Mem0 Dashboard
2. Setup
-
Clone the repository:
git clone https://github.com/lowapple/mcp-mem0.git cd mcp-mem0
-
Install dependencies:
pnpm install
-
Copy
.env.example
to.env
and add your API key and optional user ID:cp .env.example .env
Then edit
.env
with your values:MEM0_API_KEY=your-api-key-here MEM0_USER_ID=your-user-id-here # Optional: defaults to 'mcp-mem0-user'
3. Running the Development Server
- To start the server in development mode with hot-reloading:
pnpm dev
- The server will now be running locally. You can connect your AI tools (like Cursor or VS Code) to this local instance for testing.
4. Configuring AI Tools for Local Testing
Cursor:
- Go to
Settings > Features > MCP Servers
- Click
+ Add New MCP Server
- Configure as follows:
- Name:
mem0
- Type:
command
- Command:
pnpm dev
- Working Directory: Set this to the absolute path of your cloned
mcp-mem0
directory
- Name:
VS Code:
- Add the following to your User Settings (JSON):
"mcp.servers": { "mem0": { "command": "pnpm", "args": ["dev"], "cwd": "/path/to/your/cloned/mcp-mem0" // IMPORTANT: Replace with the actual path } }
The server uses the following environment variables:
MEM0_API_KEY
(required): Your Mem0 API key obtained from the Mem0 DashboardMEM0_USER_ID
(optional): Default user ID for memory operations. If not provided, defaults to'mcp-mem0-user'
When using the tools, you can either:
- Provide a
userId
parameter in each tool call to override the default - Omit the
userId
parameter to use theMEM0_USER_ID
environment variable value - If neither is provided, the system will use
'mcp-mem0-user'
as the fallback
Store new memories with enhanced metadata support for better organization.
{
"name": "memory_add",
"arguments": {
"content": "User prefers dark mode interface and minimal design",
"userId": "user123", // Optional: will use MEM0_USER_ID env var if not provided
"metadata": {
"category": "preferences",
"importance": 8,
"tags": ["UI", "interface", "design"],
"source": "user_conversation"
}
}
}
Advanced search with filtering, pagination, and sorting capabilities.
{
"name": "memory_search",
"arguments": {
"query": "interface preferences",
"userId": "user123", // Optional: will use MEM0_USER_ID env var if not provided
"filters": {
"category": "preferences",
"tags": ["UI"],
"importance_min": 5
},
"limit": 10,
"sort": "importance"
}
}
Update existing memories by ID to modify content or metadata.
{
"name": "memory_update",
"arguments": {
"memory_id": "mem_abc123",
"userId": "user123", // Optional: will use MEM0_USER_ID env var if not provided
"updates": {
"content": "Updated: User prefers dark mode with high contrast",
"metadata": {
"importance": 9,
"tags": ["UI", "interface", "accessibility"]
}
}
}
}
Delete memories by ID with support for both single and bulk operations.
{
"name": "memory_delete",
"arguments": {
"memory_id": "mem_abc123",
"userId": "user123", // Optional: will use MEM0_USER_ID env var if not provided
"confirm": true
}
}
For bulk deletion:
{
"name": "memory_delete",
"arguments": {
"memory_ids": ["mem_abc123", "mem_def456"],
"userId": "user123", // Optional: will use MEM0_USER_ID env var if not provided
"confirm": true
}
}
{
"content": [
{
"type": "text",
"text": "Memory added successfully with ID: mem_abc123"
}
],
"isError": false
}
{
"content": [
{
"type": "text",
"text": "Memory: User prefers dark mode interface\nRelevance: 0.95\nCategory: preferences\nImportance: 8\nTags: UI, interface, design\nSource: user_conversation\nID: mem_abc123\n---"
}
],
"isError": false
}
{
"content": [
{
"type": "text",
"text": "Memory mem_abc123 updated successfully"
}
],
"isError": false
}
Single deletion:
{
"content": [
{
"type": "text",
"text": "Memory mem_abc123 deleted successfully"
}
],
"isError": false
}
Bulk deletion:
{
"content": [
{
"type": "text",
"text": "Deleted 2 memories successfully"
}
],
"isError": false
}
You can run this server inside a Docker container, which is useful for isolated and consistent environments.
1. Build the Docker Image From the root of the project, run the following command:
docker build -t mcp-mem0 .
2. Configure in AI Tools
Add the following to your settings.json
to use the Dockerized server:
"mcpServers": {
"mem0": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"MEM0_API_KEY",
"-e",
"MEM0_USER_ID",
"mcp-mem0"
],
"env": {
"MEM0_API_KEY": "your-api-key-here",
"MEM0_USER_ID": "your-user-id-here"
}
}
}
The project includes a comprehensive test suite with unit and integration tests using Jest and TypeScript.
# Run all tests
NODE_OPTIONS='--experimental-vm-modules' pnpm test
# Run tests with coverage report
NODE_OPTIONS='--experimental-vm-modules' pnpm test:coverage
# Run tests in watch mode for development
NODE_OPTIONS='--experimental-vm-modules' pnpm test:watch
- Unit Tests: Located in
__tests__/client/
and__tests__/services/
mem0-client.test.ts
: 25 tests for Mem0 API client operationsmcp-server.test.ts
: 23 tests for MCP server functionality
- Integration Tests: Located in
__tests__/integration/
mcp-integration.test.ts
: 8 tests for end-to-end scenarios
- Test Utilities: Helper functions in
__tests__/utils/test-helpers.ts
The project aims for 80% code coverage across all metrics (branches, functions, lines, statements).
To create a production-ready build:
pnpm build
To start the server from the built files (located in the dist
directory):
pnpm start
This is useful for running the server as a persistent service.
The server includes error handling for:
- API connection issues
- Invalid memory operations
- Search errors
- Authentication failures
Example error response:
{
"content": [
{
"type": "text",
"text": "Error: Failed to search memories: Invalid API key"
}
],
"isError": true
}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT