SuperAPI AI Directory

mem0-mcp-selfhosted

Self-hosted mem0 for Claude Code: Qdrant vector search, Neo4j knowledge graph, Ollama embeddings and session hooks for automatic cross-session memory.

Open website

About this tool

mem0-mcp-selfhosted is a self-hosted mem0 MCP server project for Claude Code, with the goal of letting Claude Code run a complete memory service on top of a self-built Qdrant vector store, Neo4j graph store, and Ollama embedding model, with the main LLM optionally being Anthropic (Claude) or Ollama.

In terms of purpose, this project provides cross-session memory for Claude Code: it injects relevant memories at session startup, saves summaries at session end, and allows Claude to actively search for and save memories during a session.

Main capabilities include: using the mem0ai package directly as a library; supporting two main LLM choices, Claude's OAT token and fully localized Ollama; exposing 11 MCP tools (9 of which are core memory tools) for complete memory management; registering the memory_assistant MCP prompt to provide Claude with a quick-start guide for using the memory tools. The default infrastructure is Qdrant on localhost:6333 and the Ollama embedding model on localhost:11434 (bge-m3, 1024 dimensions).

In terms of usage, Python >= 3.10 and uv are required. Under the default (Anthropic) configuration, after adding the MCP server globally, all default values work out of the box, uvx will automatically download, install, and run the server in an isolated environment, and Claude Code will start it on demand when the MCP connection starts. The server automatically reads the OAT token from ~/.claude/.credentials.json, with no manual configuration required. Under the fully local (Ollama) configuration, setting MEM0_PROVIDER=ollama applies to both the main LLM and the graph LLM provider, while still using the same infrastructure defaults, and per-service overrides (such as MEM0_LLM_URL, MEM0_EMBED_URL) remain available. It can also be added to a single project by creating .mcp.json in the project root directory. All configuration is done through environment variables, and a .env file can be created or settings can be set in the MCP configuration.

CLAUDE.md integration and Claude Code Hooks provideA complementary memory behavior layer: CLAUDE.md rules tell Claude how to proactively use memory tools during a session; Hooks automatically inject and save memory at session boundaries, without the need for manual tool calls. Both Hooks are non-fatal; if mem0 is unreachable or an error occurs, Claude Code continues normally. Installing the Hooks adds hook entries to .claude/settings.json, and the installer is idempotent. At session start, the context Hook searches mem0 using two queries, deduplicates by memory ID, and injects them as numbered lines; at session stop, the stop Hook reads the JSONL transcript, extracts the last 6 user/assistant messages, builds a summary prompt, and calls memory.add(infer=True) to extract atomic facts; graphs are forcibly disabled in the Hook to stay within the 15s/30s timeout budget.

Regarding authentication, the server resolves the Anthropic token via a priority-based fallback chain; in Claude Code, the credentials file method always takes precedence over ANTHROPIC_API_KEY. OAT tokens use the Claude subscription; the server automatically detects the token type and configures the SDK, and proactively refreshes before expiration (default 30 minutes); on authentication failure, a three-step defense strategy is initiated. API keys use standard pay-as-you-go billing.

Regarding graph memory: graph memory is disabled by default (MEM0_ENABLE_GRAPH=false) to protect the Claude quota; each add_memory with graphs enabled triggers 3 additional LLM calls (entity extraction, relationship generation, conflict resolution). A local Ollama model (such as Qwen3:14b) or Gemini can be used to eliminate Claude quota consumption, and the gemini_split provider can be used to route graph pipeline calls per operation to balance accuracy.

Regarding operating modes, for remote deployments, MCP SDK >= 1.23.0 enables DNS rebinding protection by default. Tests are divided into unit tests, contract tests (verifying assumptions about mem0ai internals), and integration tests (against real infrastructure). All mem0ai telemetry is suppressed; MEM0_TELEMETRY=false is set at package import time, and no PostHog events are sent.

Limitations and information not provided: the material does not provide specific prices, billing plans, performance metricsor details such as the list of supported platforms.