mem0-custom-mcp

mem0-custom-mcp

A custom MCP server that connects to self-hosted Mem0 API instances, enabling Claude Code to manage memories via custom endpoints.

Category
访问服务器

README

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.

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

From GitHub (Recommended for now)

# 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).

Option 1: Using CLI (Recommended)

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选