Local Brain MCP
A local MCP server for AI assistants to store and retrieve personal memories on disk, with optional semantic search using embeddings.
README
Local Brain MCP
Local Brain MCP is a small MCP server that you run locally on your machine. It lets AI assistants store and retrieve personal memories on your own disk, and optionally use semantic (embedding) search for RAG‑style workflows.
You run the server on your computer (e.g. python server.py); Cursor and other MCP clients connect to it at http://localhost:3000/mcp. Optionally, you can expose it via something like Cloudflare Tunnel to use the same memory from other devices.
Features
-
Local, transparent storage
- SQLite database file on disk (
memory.dbby default). - DB location is configured via environment variables (see “Database layout”). The
dbUrltool argument is intentionally ignored so all clients share the same configured DB. - Simple schema:
memoriestable withtitle,content,tags,source, timestamps, and IDs.
- SQLite database file on disk (
-
MCP tools
save_memory— insert a memory row (optionally generating an embedding).update_memory— patchtitle/content/tags/sourceon an existing row; optional embedding refresh whencontentchanges.delete_memory— remove a row by id (embeddings removed with it).fetch_memories— RAG-style retrieval: by default uses semantic vector search over embeddings; falls back to keyword search if embeddings are unavailable.backfill_all_embeddings— generate embeddings for older memories that don’t have one yet (after you configure an embedding provider).
-
Embeddings / vector search
- The server does not run an embedding model itself. Embeddings are handled by OpenAI (or optionally OpenRouter) via their APIs.
- Optional embeddings are stored in a separate
memory_embeddingstable. - OpenAI is the default: set
OPENAI_API_KEYand the server will use OpenAI’s embeddings API. Optionally, setEMBEDDING_PROVIDER=openrouterandOPENROUTER_API_KEYto use OpenRouter instead.
Quick start
- Install dependencies
Create and activate a virtual environment, then install Python deps.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Configure embeddings (optional but recommended)
Embeddings are generated by OpenAI’s API (the server has no built‑in embedding model). Set OPENAI_API_KEY and the server will call OpenAI to create and store embeddings for semantic search.
- Option A: OpenAI
export EMBEDDING_PROVIDER=openai # default, can be omitted
export OPENAI_API_KEY=sk-...
export EMBEDDING_MODEL=text-embedding-3-small # optional override
- Option B: OpenRouter
export EMBEDDING_PROVIDER=openrouter
export OPENROUTER_API_KEY=sk-or-...
# Any OpenRouter embedding model (example shown):
export EMBEDDING_MODEL=openai/text-embedding-3-small
# Optional but recommended for OpenRouter analytics:
export OPENROUTER_SITE_URL="https://your-site-or-localhost"
export OPENROUTER_APP_NAME="Local Brain MCP"
- Run the MCP server
From the project root:
source .venv/bin/activate
python server.py
You should see FastMCP start up and log something like:
Local Brain MCPlistening onhttp://0.0.0.0:3000- MCP endpoint:
http://localhost:3000/mcp
You can then point Cursor (or another MCP client) at http://localhost:3000/mcp as a remote MCP server.
Run with Docker Compose
If you prefer running this in Docker, use the included docker-compose.yml.
- Set env vars (optional, for embeddings)
Create a .env file in the project root (or export env vars in your shell):
# .env example
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-...
EMBEDDING_MODEL=text-embedding-3-small
- Build and start
docker compose up -d --build
# or, on systems with the legacy CLI:
docker-compose up -d --build
- Use the MCP endpoint
The server is available at:
http://localhost:3000/mcp
- Stop the service
docker compose down
# or:
docker-compose down
Notes:
- SQLite data is persisted in the Docker volume
memory_data. - Inside the container, the DB path is set to
MEMORY_DB_URL=/data/memory.db.
Cursor integration note (local env auto-load)
When you run server.py locally, it will also try to load environment overrides from ~/.cursor/mcp.json (specifically the mcpServers.local-brain-mcp.env block), if present. This helps you keep your server configuration in one place.
Database layout
By default, the SQLite file is memory.db in the project root. This can be overridden with:
- Env vars:
dbUrl,DB_URL, orMEMORY_DB_URL(first non‑empty wins).
Notes:
- The
dbUrltool parameter is intentionally ignored for path resolution. - If the chosen DB path is relative, it is resolved relative to the server’s current working directory.
Tables:
memoriesid(INTEGER, primary key)created_at(TEXT, ISO datetime, defaultdatetime('now'))title(TEXT, nullable)content(TEXT, required)tags(TEXT, JSON‑encoded list of strings)source(TEXT, optional source identifier)
MCP tools
save_memory
Purpose: Insert a new memory row (and optionally its embedding).
Parameters:
content(str, required): main text content of the memory.title(str, optional): short title.tags(List[str], optional): arbitrary tags, stored as JSON.source(str, optional): where the memory came from (e.g."cursor","cli","web").dbUrl(str, optional): accepted for API compatibility, but ignored for database path resolution.generate_embedding(bool, optional, defaultTrue):- If
True, and an embedding API is configured (e.g.OPENAI_API_KEY), the server calls OpenAI (or OpenRouter) to generate an embedding and stores it.
- If
Returns:
- A dict with
id,title,content,tags,source.
update_memory
Purpose: Update fields on an existing memory (omit fields you do not want to change).
Parameters:
memory_id(int, required): id of the row to update.title,content,tags,source(optional): new values; at least one must be provided.generate_embedding(bool, defaultTrue): whencontentchanges, ifTruerecompute the embedding; ifFalse, drop the stored embedding so vector search cannot use stale vectors.
Returns: dict with id, title, content, tags, source.
delete_memory
Purpose: Delete a memory by id.
Parameters:
memory_id(int, required).
Returns: { "id": <int>, "deleted": <bool> } (deleted is False if no row existed).
fetch_memories
Purpose: Retrieve memories relevant to a query, or the most recent rows when the query is empty.
Parameters:
query(str, optional): text query; if omitted or blank (or whitespace-only), returns the latest memories (recent-first)—a “list recent” behavior, not search.limit(int, optional, default5, max50): max number of results.dbUrl(str, optional): accepted for API compatibility, but ignored for database path resolution.use_vector_search(bool, optional, defaultTrue): RAG-style retrieval.True(default): embed the query and return memories ranked by semantic similarity; falls back to keyword search if embeddings are unavailable.False: keyword-only — SQLLIKEoncontentandtitle, ordered by recency.
fields(list of str, optional): if set, each result includes only these keys. Allowed:id,created_at,title,content,tags,source. Omit for all fields. Useful to shrink MCP tool payloads (e.g. excludecontentwhen listing or probing).tags_any(list of str, optional): if set, return only rows containing at least one of the provided tags (case-insensitive).source_prefix(str, optional): if set, return only rows wheresourcestarts with this prefix.
Returns:
- A list of dicts; by default each includes
id,created_at,title,content,tags,source. Withfields, only the requested keys are present.
Using this as a RAG memory
Typical pattern for an AI assistant:
-
On new long‑term information
Callsave_memorywith:content: the text snippet you want to remember.title/tags: short descriptors.generate_embedding=True(default) so it’s indexed semantically.
-
Before answering a user query
Callfetch_memorieswith the user’s question (or a brief summary) asquery. By default it uses RAG (semantic retrieval); use the top results as context when generating the answer. -
Fallback behavior
If embeddings are not configured or not yet stored, vector search cleanly degrades to keyword search, so the tools remain usable. -
Hygiene
Useupdate_memoryto correct a row without duplicating it; usedelete_memoryto drop obsolete entries.
Embedding backfill (recommended after enabling embeddings)
If you set an embedding provider/API key after you already have memories saved, run backfill_all_embeddings once to generate embeddings for older rows so semantic search works across your full history.
Development notes
- The server is implemented in
server.pyusing FastMCP. - All schema creation is performed on connection; deleting
memory.dbwill recreate an empty database on next start. - Embeddings are handled by OpenAI (or OpenRouter); configuration is via environment variables only.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.