Labsco
pinkpixel-dev logo

Mem0 MCP

β˜… 97

from pinkpixel-dev

Integrates with Mem0.ai to provide persistent memory capabilities for LLMs, supporting cloud, Supabase, and local storage.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedPaid serviceAdvanced setup

Mem0 MCP Logo

npm version License: MIT Node.js TypeScript MCP Mem0 Downloads GitHub Stars smithery badge

@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 🧠

Modernized & Advanced Tools (v0.8.0)

  • add_memory: Stores a memory from text content or structured message arrays.
    • Inputs: content (string) or messages (array of role/content objects), userId (string), runId / sessionId (string), agentId (string), appId (string), metadata (object), infer (boolean), customInstructions (string), waitForCompletion (boolean, default: true), timeoutMs (number, default: 15000)
    • Behavior: Cloud V3 additions are asynchronous. By default, this tool polls the background queue until completed. Pass waitForCompletion: false to get the eventId immediately.
  • search_memories: Searches memories using semantic and BM25 hybrid filters.
    • Inputs: query (string), userId (string), runId / sessionId (string), agentId (string), appId (string), filters (object), threshold (number), topK (number), rerank (boolean), referenceDate (string)
    • Behavior: Automatically nests scope variables inside the V3 filters block to prevent API validation errors.
  • search_memory: Backward-compatible alias for search_memories.
  • list_memories: Paginated listing of memory records scoped by identifiers.
    • Inputs: userId (string), runId / sessionId (string), agentId (string), appId (string), filters (object), page (number), pageSize (number)
  • get_memory: Retrieves a single memory record by its ID.
    • Inputs: memoryId (string)
  • update_memory: Modifies the text or metadata of an existing memory.
    • Inputs: memoryId (string), text (string), metadata (object)
  • delete_memory: Deletes a specific memory record by ID.
    • Inputs: memoryId (string)
  • get_memory_history: Retrieves the audit trail of memory revisions (cloud only).
    • Inputs: memoryId (string)
  • get_memory_capabilities: Exposes the feature matrix and support flags of the active backend storage mode.
    • Inputs: None
  • batch_update_memories: Performs bulk updates of text contents for multiple memories (cloud only).
    • Inputs: updates (array of { memoryId: string, text: string } objects)
  • batch_delete_memories: Performs bulk deletions of multiple memories.
    • Inputs: memoryIds (array of strings), confirm (boolean, must be true to execute)
  • rate_memory: Submits quality feedback evaluation for a memory record (cloud only).
    • Inputs: memoryId (string), feedback (string: positive, negative, very_negative), reason (string, optional)
  • get_memory_event: Manually retrieves details of a specific background event job (cloud only).
    • Inputs: eventId (string)
  • list_memory_events: Lists history logs of background memory processing events (cloud only).
    • Inputs: page (number), pageSize (number)
  • create_memory_export: Initiates an asynchronous memory export query job (cloud only).
    • Inputs: schema (object), filters (object, optional), exportInstructions (string, optional)
  • get_memory_export: Retrieves status and download metadata of a memory export job (cloud only).
    • Inputs: exportId (string)

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_id and threshold parameters
  • Fully 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:

Copy & paste β€” that's it
git clone https://github.com/pinkpixel-dev/mem0-mcp
cd mem0-mcp
npm install

Build the server:

Copy & paste β€” that's it
npm run build

For development with auto-rebuild on file changes:

Copy & paste β€” that's it
npm run watch

Debugging 🐞

Since MCP servers communicate over stdio, debugging can be challenging. Here are some approaches:

  1. Use the MCP Inspector: This tool can monitor the MCP protocol communication:
Copy & paste β€” that's it
npm run inspector
  1. Console Logging: When adding console logs, always use console.error() instead of console.log() to avoid interfering with the MCP protocol

  2. Environment Files: Use a .env file for local development to simplify setting API keys and other configuration options

Technical Implementation Notes πŸ”§

1. Platform V3 Async Additions & Polling

Mem0 Cloud V3 addition is an asynchronous background task. When calling add_memory, the server submits the request to /v3/memories/add/ and receives an eventId.

  • Synchronous Polling (Default): The server polls the event status endpoint (/v1/event/{id}/) every 500ms for up to timeoutMs (default 15000ms) until the status becomes SUCCEEDED or FAILED. Once resolved, it returns the final outcome.
  • Asynchronous Execution: Pass "waitForCompletion": false to bypass polling. The server will immediately return the eventId and a PENDING status.

2. Nested V3 Filter Normalization

The Mem0 Cloud V3 search and list endpoints reject top-level scope IDs (user_id, agent_id, app_id, run_id) and return an HTTP 400 error. V3 requires these fields inside the nested filters object. To prevent breaking client configurations, this server automatically normalizes top-level scope variables (userId, agentId, appId, runId/sessionId) and merges them into the nested filters object under the hood before sending the API request.

3. Capability Gating

Different backends support different feature sets. Call get_memory_capabilities to get a structured capability matrix of the active backend.

  • Cloud Mode: Fully supports all features (apiVersion: "v3", async events, listing, audit histories, logical queries).
  • Supabase / Local Modes: Standard V1 vector interfaces. Unsupported cloud-specific tools (like get_memory_history or list_memories) will fail gracefully with clear feature-unavailable messages.

4. Logging & Protocol Stability

MCP servers communicate using JSON-RPC over stdout. Any unexpected library logs printed to stdout will corrupt the protocol channel and cause clients to crash. This server overrides the default console output methods (such as console.log) to redirect/mute standard logging, ensuring clean stdio communication.


Made with πŸ’– by Pink Pixel