local-memory-mcp

local-memory-mcp

A local-first long-term memory system for AI coding agents, exposed as an MCP server.

Category
访问服务器

README

local-memory-mcp

A local-first long-term memory system for AI coding agents, exposed as an MCP server. Built for Kiro CLI but compatible with any MCP-capable client.

Why

AI agents forget everything between sessions. This gives them persistent, searchable, semantically-aware memory — stored entirely on your machine.

Architecture

┌─────────────────────────────────────────────────┐
│  MCP Server (stdio)                             │
│                                                 │
│  Tools: store_memory · recall · search_memories │
│         get_memory · forget · relate            │
│         query_graph · consolidate · memory_stats│
├─────────────────────────────────────────────────┤
│  Memory Engine                                  │
│  ┌───────────┬──────────┬───────────────────┐   │
│  │ Retrieval │ Embeddings│ Consolidation    │   │
│  │ (hybrid)  │ (local)   │ (decay + merge)  │   │
│  └───────────┴──────────┴───────────────────┘   │
├─────────────────────────────────────────────────┤
│  Storage Layer                                  │
│  ┌──────────┬───────────┬────────┬──────────┐   │
│  │ Memories │ Vectors   │ FTS5   │ Knowledge│   │
│  │ (SQLite) │(sqlite-vec)│(SQLite)│ Graph    │   │
│  └──────────┴───────────┴────────┴──────────┘   │
└─────────────────────────────────────────────────┘

Hybrid retrieval combines four signals into a single score:

Signal Weight Source
Vector similarity 50% sqlite-vec (L2 distance on 384-dim embeddings)
Full-text search 25% SQLite FTS5
Recency 15% Exponential decay, 30-day half-life
Importance 10% User-assigned + access-frequency boosting

Embeddings run fully locally via Transformers.js (ONNX runtime) using all-MiniLM-L6-v2. No API keys. No network calls after first model download.

Knowledge graph stores typed entities and weighted relations in SQLite with BFS traversal up to 3 hops.

Consolidation applies importance decay, merges near-duplicate memories, and prunes forgotten ones.

Dual-scope storage

Every memory lives in one of two scopes:

  • Global (~/.local-memory/memory.db) — your preferences, facts, cross-project knowledge
  • Project (.local-memory/memory.db in repo root) — project-specific context, decisions, patterns

The agent can query either scope or both. Project scope auto-detects from .git, package.json, Cargo.toml, pyproject.toml, or go.mod.

Tools

Tool Description
store_memory Store a memory with type, scope, importance, and optional entity extraction
recall Semantic recall — hybrid search combining all four signals
search_memories Keyword-based full-text search
get_memory Fetch a specific memory by ID
forget Delete a memory and cascade to embeddings + graph
relate Create/strengthen entity relationships in the knowledge graph
query_graph Traverse the knowledge graph from an entity (BFS, 1-3 hops)
consolidate Decay old memories, merge duplicates, prune weak ones
memory_stats Counts for memories, entities, and relations per scope

Quickstart

Install

git clone https://github.com/smankoo/local-memory-mcp.git
cd local-memory-mcp
npm install
npm run build

Configure Kiro CLI

Option A — Auto-configure:

npx tsx scripts/install-kiro.ts          # global
npx tsx scripts/install-kiro.ts --project # project-level

Option B — Manual:

Add to ~/.kiro/settings/mcp.json:

{
  "mcpServers": {
    "memory": {
      "command": "node",
      "args": ["/absolute/path/to/local-memory-mcp/dist/index.js"],
      "env": {
        "MEMORY_DIR": "~/.local-memory"
      }
    }
  }
}

Then restart Kiro CLI and run /mcp to verify.

Other MCP clients

Any client that speaks MCP over stdio works. The server binary is dist/index.js:

node /path/to/local-memory-mcp/dist/index.js

Environment variables

Variable Default Description
MEMORY_DIR ~/.local-memory Global data directory
MEMORY_PROJECT auto-detected CWD Project root override
EMBEDDING_MODEL Xenova/all-MiniLM-L6-v2 HuggingFace model for embeddings

Configuration

Tuning knobs are in src/utils/config.ts:

Parameter Default Description
deduplicationThreshold 0.92 Cosine similarity above which a new memory updates the existing one
consolidationThreshold 0.85 Similarity above which two memories are merged during consolidation
decayRate 0.995 Daily importance multiplier (0.995^30 ≈ 0.86, so ~14% decay/month)
minImportanceBeforePrune 0.05 Memories below this with <2 accesses get pruned

Development

npm run dev          # watch mode
npm test             # run tests (downloads model on first run, ~60s)
npm run build        # production build

Project structure

src/
├── index.ts                # Entry point — stdio transport
├── server.ts               # MCP tool definitions
├── engine/
│   ├── memory-engine.ts    # Orchestrator — store, recall, forget, consolidate
│   ├── retrieval.ts        # Hybrid scoring (vector + FTS + recency + importance)
│   ├── embeddings.ts       # Local embedding via Transformers.js
│   ├── consolidation.ts    # Decay, merge, prune lifecycle
│   └── graph.ts            # Entity relationship engine
├── storage/
│   ├── database.ts         # SQLite + sqlite-vec + FTS5 initialization
│   ├── schema.ts           # Drizzle ORM schema
│   ├── memory-store.ts     # CRUD for memories table
│   ├── vector-store.ts     # sqlite-vec operations
│   ├── fts-store.ts        # FTS5 search with query sanitization
│   └── graph-store.ts      # Entity + relation tables, BFS traversal
└── utils/
    ├── config.ts           # Environment + defaults
    ├── scoring.ts          # Recency decay, hybrid scoring, cosine similarity
    └── id.ts               # nanoid generation

Tech stack

  • TypeScript + tsup (ESM, Node 22)
  • better-sqlite3 + Drizzle ORM for structured storage
  • sqlite-vec for vector similarity search
  • SQLite FTS5 for full-text search
  • @huggingface/transformers for local embeddings (ONNX)
  • @modelcontextprotocol/sdk for the MCP server
  • Vitest for testing

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选