Skip to main content
Glama
emasoudy

mem0-custom-mcp

by emasoudy

Mem0 Custom MCP Server

License: MIT Node.js Version TypeScript MCP Protocol

A custom Model Context Protocol (MCP) server that connects to self-hosted Mem0 API instances. Enables Claude Code to use your own Mem0 deployment for memory management.

Why This Exists

The official @mem0/mcp-server and community @pinkpixel/mem0-mcp packages only support:

  • Mem0's cloud platform (requires MEM0_API_KEY)

  • Supabase backend

  • Local storage

Neither supports connecting to custom self-hosted Mem0 API endpoints.

This custom MCP server bridges that gap by providing a wrapper around your self-hosted Mem0 API.

Related MCP server: Claude Memory

Features

  • ✅ Connects to self-hosted Mem0 API at custom endpoints

  • ✅ Implements MCP stdio protocol for Claude Code integration

  • ✅ Supports all core Mem0 operations:

    • add_memory - Store new memories

    • search_memories - Semantic search through memories

    • get_memories - Retrieve all memories for a user

    • delete_memory - Delete specific memories

  • ✅ Environment variable configuration

  • ✅ Full TypeScript implementation with type safety

  • 120-second timeout for slow Mem0 API responses (handles LLM processing delays)

Installation

# Clone the repository
git clone https://github.com/emasoudy/mem0-custom-mcp.git
cd mem0-custom-mcp

# Install dependencies
npm install

# Build the project
npm run build

From npm (Future - when published)

# This will be available after npm publish
npm install -g mem0-custom-mcp

Configuration

The server is configured via environment variables:

  • MEM0_API_URL - Your Mem0 API endpoint (default: http://localhost:8888)

  • DEFAULT_USER_ID - Default user ID for memory operations (default: default)

Example configurations:

  • Local: http://localhost:8888

  • Docker: http://host.docker.internal:8888

  • Remote/VPN: http://your-server-ip:8888

Claude Code Configuration

You can configure this MCP server at either user level (available in all projects) or project level (specific project only).

User-level (available everywhere):

claude mcp add mem0 \
  --scope user \
  --command node \
  --arg "/absolute/path/to/mem0-custom-mcp/dist/index.js" \
  --env MEM0_API_URL=http://localhost:8888 \
  --env DEFAULT_USER_ID=default

Project-level (specific project only):

cd /path/to/your/project
claude mcp add mem0 \
  --scope project \
  --command node \
  --arg "/absolute/path/to/mem0-custom-mcp/dist/index.js" \
  --env MEM0_API_URL=http://localhost:8888 \
  --env DEFAULT_USER_ID=default

Option 2: Manual Configuration

User-level - Edit ~/.claude.json:

{
  "mcpServers": {
    "mem0": {
      "type": "stdio",
      "command": "node",
      "args": [
        "/absolute/path/to/mem0-custom-mcp/dist/index.js"
      ],
      "env": {
        "MEM0_API_URL": "http://localhost:8888",
        "DEFAULT_USER_ID": "default"
      }
    }
  }
}

Project-level - Edit .claude.json in your project root:

{
  "projects": {
    "your-project-path": {
      "mcpServers": {
        "mem0": {
          "type": "stdio",
          "command": "node",
          "args": [
            "/absolute/path/to/mem0-custom-mcp/dist/index.js"
          ],
          "env": {
            "MEM0_API_URL": "http://localhost:8888",
            "DEFAULT_USER_ID": "default"
          }
        }
      }
    }
  }
}

Verify installation:

claude mcp list
# Should show "mem0" in the list

Development

  • npm run build - Compile TypeScript to JavaScript

  • npm run dev - Build and run the server

  • npm start - Run the compiled server

Available Tools

add_memory

Store a new memory in Mem0.

Parameters:

  • content (required) - The content to store

  • user_id (optional) - User ID (defaults to env DEFAULT_USER_ID)

  • metadata (optional) - Additional metadata object

search_memories

Search memories using semantic search.

Parameters:

  • query (required) - Search query string

  • user_id (optional) - User ID (defaults to env DEFAULT_USER_ID)

  • limit (optional) - Maximum results (default: 10)

get_memories

Retrieve all memories for a user.

Parameters:

  • user_id (optional) - User ID (defaults to env DEFAULT_USER_ID)

  • limit (optional) - Maximum results (default: 100)

delete_memory

Delete a specific memory by ID.

Parameters:

  • memory_id (required) - ID of the memory to delete

Architecture

This MCP server acts as a bridge between Claude Code and your self-hosted Mem0 API instance:

┌─────────────────────────┐
│     Claude Code         │
└────────────┬────────────┘
             │ MCP stdio protocol
             │
┌────────────▼────────────┐
│   mem0-custom-mcp       │  ← This MCP server (Node.js)
│   (MCP wrapper)         │
└────────────┬────────────┘
             │ HTTP REST API (localhost:8888 or custom URL)
             │
┌────────────▼────────────┐
│  Self-Hosted Mem0 API   │  ← Mem0 API server (Python/FastAPI)
│  (your-server:8888)     │    Handles memory operations
└────────────┬────────────┘
             │
        ┌────┴─────┐
        │          │
   ┌────▼───┐  ┌──▼──────┐
   │PGVector│  │  Neo4j  │  ← Databases managed by Mem0 API
   │(Vector)│  │ (Graph) │
   └────────┘  └─────────┘

Flow:

  1. Claude Code calls MCP tools (add_memory, search_memories, etc.)

  2. mem0-custom-mcp receives requests via MCP stdio protocol

  3. mem0-custom-mcp forwards to Mem0 API via HTTP

  4. Mem0 API processes requests and manages PostgreSQL/Neo4j databases

  5. Results flow back through the chain to Claude Code

Note: This server does NOT directly access PostgreSQL or Neo4j. It communicates only with the Mem0 API endpoint, which handles all database operations.

Mem0 API Endpoints Used

This MCP server uses the following Mem0 API endpoints:

  • POST /v1/memories - Add new memory

    • Body: {"messages": [{"role": "user", "content": "..."}], "user_id": "...", "metadata": {}}

  • GET /v1/memories/{user_id} - Get all memories for a user

    • Path parameter: user_id

  • POST /v1/memories/search - Search memories with semantic search

    • Body: {"query": "...", "user_id": "...", "limit": 10}

  • DELETE /v1/memories/{memory_id} - Delete a specific memory

    • Path parameter: memory_id

Troubleshooting

Server won't start

Check debug logs in ~/.claude/debug/ for error messages.

Common issues:

  • Mem0 API not accessible (check VPN connection)

  • Invalid endpoint URL

  • Port conflicts

Connection timeout

The MCP server has a built-in 120-second timeout for Mem0 API requests. This accommodates the time needed for:

  • OpenAI API calls to generate embeddings

  • LLM processing to extract entities and relationships

  • Database operations (PostgreSQL + Neo4j)

Typical memory creation takes 30-60 seconds when using GPT-5-mini.

If you need to adjust the timeout, modify src/index.ts line 59:

const timeoutId = setTimeout(() => controller.abort(), 120000); // 2 minutes

Tool errors

Verify your Mem0 API is running:

# For local deployment
curl http://localhost:8888/health

# For remote/VPN deployment
curl http://your-server-ip:8888/health

Expected response:

{"status":"ok","db_connected":true,"stores":{"vector":"postgresql","graph":"neo4j"}}

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Development

# Clone and setup
git clone https://github.com/emasoudy/mem0-custom-mcp.git
cd mem0-custom-mcp
npm install

# Make changes to src/index.ts
# Build and test
npm run build
npm run dev  # Build and run

Changelog

See CHANGELOG.md for version history.

License

MIT License - see LICENSE for details.

Acknowledgments

Support

Available Tools

4 tools
add_memoryB

Store a new memory in Mem0

ParametersJSON Schema
NameRequiredDescriptionDefault
contentYesThe content to store as a memory
user_idNoUser ID (defaults to env DEFAULT_USER_ID)
metadataNoOptional metadata

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits itself. It only states that it stores a memory, but doesn't clarify whether it overwrites, appends, requires specific permissions, or what side effects occur. The word 'new' implies no overwriting but leaves other behaviors undisclosed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no filler, but it is almost too terse, offering minimal substance. It is concise and front-loaded, more efficient than verbose, though it trades away helpful context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has a complete schema and no output schema, the description covers only the basic action. It lacks usage context and behavioral caveats, but the schema mitigates some gaps. Overall, it is a minimally viable description for a straightforward create operation, but leaves room for improvement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema covers all three parameters with descriptions (content, user_id, metadata), achieving 100% schema coverage. The description adds no additional parameter semantics, so the baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the specific verb 'Store' targeting 'a new memory in Mem0', clearly distinguishing this write operation from sibling tools (search_memories, get_memories, delete_memory). The phrase 'new memory' confirms an insert action, leaving no ambiguity about its core function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided regarding when to use this tool versus alternatives. The description does not mention that this is for creating memories, while search/get/delete are for reading/removing, nor does it note any prerequisites or edge cases like duplicate handling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

delete_memoryB

Delete a specific memory by ID

ParametersJSON Schema
NameRequiredDescriptionDefault
memory_idYesID of the memory to delete

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It only states the basic action without mentioning permanence, error behavior for nonexistent IDs, permissions, or side effects. This is a significant gap for a delete operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that is front-loaded with the action and object. Every word contributes meaning, with zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with no annotations and no output schema, the description is minimally adequate but lacks details about deletion behavior (e.g., success criteria, error cases). It is not misleading but leaves important behavioral context unspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides 100% coverage for the single parameter (memory_id) with a clear description. The tool description adds no additional semantic information beyond what the schema states, so the baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific action ('Delete') on a specific resource ('a specific memory') with a clear identifier ('by ID'). This distinguishes it from sibling tools like add_memory (create), search_memories (query), and get_memories (retrieve).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, nor any exclusions or prerequisites beyond the implicit requirement of a memory ID. The description implies usage but offers no explicit context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_memoriesA

Retrieve all memories for a user

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results (default: 100)
user_idNoUser ID (defaults to env DEFAULT_USER_ID)

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full responsibility for behavioral disclosure. It only states the action without mentioning pagination, default limits, memory volume, ordering, or response format. For a retrieval tool that may return large datasets, this lack of behavioral context is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence with clear verb-object structure. Every word earns its place, and the information is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple with two optional parameters, but with no annotations and no output schema, the description is relatively thin. It lacks context about return format, behavior with large result sets, or how limit interacts with 'all memories'. Additional behavioral notes would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already describes both parameters (limit and user_id) with 100% coverage. The description adds no additional parameter semantics, so the baseline score of 3 is appropriate since the schema handles the details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Retrieve') and resource ('all memories for a user'), clearly distinguishing this from sibling tools like search_memories (focused retrieval) and add/delete memory operations. The word 'all' explicitly communicates the bulk scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'all memories' implies a bulk retrieval use case, but the description does not explicitly mention when to prefer this over search_memories or other alternatives. No exclusions or prerequisites are stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_memoriesC

Search for memories using semantic search

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results (default: 10)
queryYesSearch query
user_idNoUser ID (defaults to env DEFAULT_USER_ID)

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry behavioral disclosure. It only states 'semantic search' and omits critical behavioral traits such as result ordering, pagination, prerequisites (like user_id), performance implications, or read-only status.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that starts with the action verb and resource, wasting no words. It is optimally structured for quick comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description should explain return values and search behavior, but it does not. It also lacks details on default limit, user_id handling, and ranking semantics, making it incomplete for a search tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema includes descriptions for all three parameters (query, limit, user_id), providing 100% coverage. The description adds no extra parameter meaning beyond the schema, so it earns the baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs a semantic search over memories, with a specific verb and resource. It distinguishes from sibling tools like get_memories by highlighting 'semantic search', though it could more explicitly contrast with them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus alternatives like get_memories or add_memory. The description only defines what it does, leaving the agent without directional context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv1.1.0
    • First observedadd_memory
    • First observeddelete_memory
    • First observedget_memories
    • First observedsearch_memories

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation5/5

Each tool serves a clearly distinct purpose: adding, searching, retrieving all, and deleting memories. The descriptions clearly differentiate search from retrieval, so there is no ambiguity.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern (add, search, get, delete + memory/memories). The singular/plural variation is minor and does not hinder predictability.

Tool Count5/5

With only 4 tools, the server is well-scoped and focused on the fundamental memory operations. Each tool is essential and there is no bloat.

Completeness4/5

The set covers the core lifecycle of memories (create, read, search, delete), but lacks an update operation. This is a minor gap for a memory store, making the surface slightly incomplete.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that provides Claude Code with persistent memory across sessions, including session checkpoints, image persistence, and bidirectional sync with claude.ai projects.
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A MCP server that gives Claude Code and other AI assistants long-term memory by automatically extracting technical knowledge from conversations and retrieving relevant experiences in future sessions.
    6 npm
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    A server that wraps a self-hosted mem0 REST API as MCP tools for Claude Desktop and Claude Code, enabling memory operations such as adding, searching, and managing memories via natural language.
    6
    1
    MIT