MegaMemory

0xK3vinMIT更新放缓

给编码 Agent 用的持久化项目知识图谱,通过 MCP 服务器提供语义检索、进程内向量嵌入和网页浏览器,让 Agent 跨会话记住代码上下文。

Persistent project knowledge graph for coding agents. MCP server with semantic search, in-process embeddings, and web explorer.

v1.6.2发布于 2026-05-03 00:22 UTC735star75fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
npm install -g megamemory
megamemory install
硬件要求按 README 说明

README 未说明显存或 GPU 要求;需 Node.js >= 18,嵌入模型约 23MB 首次使用时自动下载,之后无需联网。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

给编码 agent 用的持久化项目知识图谱 MCP 服务器,让 agent 跨会话记住架构与决策

给编码 Agent 用的持久化项目知识图谱,通过 MCP 服务器提供语义检索、进程内向量嵌入和网页浏览器,让 Agent 跨会话记住代码上下文。

核心能力

  • 用 MCP 工具让 agent 读写概念节点与关系边
  • 内置 all-MiniLM-L6-v2 做进程内语义检索
  • 概念按 feature/module/pattern 等类型与五种关系建模
  • 提供 d3-force 网页图谱浏览器可视化
  • 支持两个 knowledge.db 双向合并与冲突解决

容易踩的坑

首次使用需联网下载约 23MB 嵌入模型,之后才离线可用;数据默认写入工作目录下的 .megamemory/knowledge.db,可用 MEGAMEMORY_DB_PATH 覆盖;web explorer 默认端口 4321,被占用时会提示另选。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.6.2
  1. v1.6.2最新正式版2026-05-03 · 2026-05-03 00:22 UTC

    Summary

    • Treat empty parent_id values as omitted when creating root concepts.
    • Make installer updates non-destructive for existing user configs and unmarked plugin/command files.
    • Add multi-process database concurrency regression coverage.

    Validation

    • npm test
    • npm run build
  2. v1.6.12026-03-20 · 2026-03-20 19:19 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/0xK3vin/MegaMemory/compare/v1.6.0...v1.6.1

  3. v1.6.02026-03-16 · 2026-03-16 01:28 UTC
    查看更新说明

    What's New

    Codex install target (#9)

    • megamemory install --target codex now configures megamemory for OpenAI's Codex CLI/IDE/App
    • Primary path uses codex mcp add CLI; falls back to writing TOML directly to ~/.codex/config.toml
    • Writes ~/.codex/AGENTS.md with knowledge graph workflow instructions

    SQLite concurrency fix (#8)

    • softDeleteNode(), hardDeleteNode(), and resolveConflict() now wrapped in transactions to prevent orphaned edges under concurrent multi-process access
    • Reentrant transaction support via _txDepth counter
    • runWithRetry() with exponential backoff for SQLITE_BUSY errors
    • busy_timeout increased from 1000ms to 5000ms
    • Graceful SIGINT/SIGTERM shutdown in MCP server
  4. v1.5.02026-03-03 · 2026-03-03 11:00 UTC
    查看更新说明

    Concurrency Safety & Schema v4

    This release adds robust multi-process SQLite safety and schema improvements for concurrent MCP access.

    Changes

    • SQLite busy_timeout & synchronous pragmas — busy_timeout=5000 and synchronous=NORMAL for multi-process safety
    • Atomic createConcept transactions — node + edges wrapped in a single transaction
    • Migration serialization — BEGIN IMMEDIATE prevents concurrent migration races
    • UNIQUE constraint on edges with auto-deduplication — schema v4 migration adds a unique index on (from_id, to_id, relation) and deduplicates existing edges
    • INSERT OR IGNORE for duplicate edge handling — prevents constraint violations on concurrent edge creation
  5. v1.4.12026-03-03 · 2026-03-03 04:57 UTC
    查看更新说明

    Strengthen megamemory prompt wording from suggestive to mandatory. Models with large thinking budgets were rationalizing away soft instructions — upgraded to 'You must call' language with explicit ordering and 'no implicit memory' framing. Ref #6.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    An MCP server that lets your coding agent build and query a graph of concepts, architecture, and decisions — so it remembers across sessions.

    The LLM is the indexer. No AST parsing. No static analysis. Your agent reads code, writes concepts in its own words, and queries them before future tasks. The graph stores concepts — features, modules, patterns, decisions — not code symbols.

    The Loop

    understand → work → update

    1. Session start — agent calls list_roots to orient itself
    2. Before a task — agent calls understand with a natural language query (or get_concept for exact ID lookup)
    3. After a task — agent calls create_concept or update_concept to record what it built

    Everything persists in a per-project SQLite database at .megamemory/knowledge.db.


    Installation

    npm install -g megamemory
    

    [!NOTE] Requires Node.js >= 18. The embedding model (~23MB) downloads automatically on first use.

    Quick Start

    megamemory install
    

    Run the interactive installer and choose your editor:

    [!NOTE] The installer only updates config files after a successful read/merge, and it will not overwrite existing plugin/command files unless they are already marked as MegaMemory-managed.

    With opencode
    megamemory install --target opencode
    

    One command configures:

    • MCP server in ~/.config/opencode/opencode.json
    • Workflow instructions in ~/.config/opencode/AGENTS.md
    • Skill tool plugin at ~/.config/opencode/tool/megamemory.ts
    • Bootstrap command /user:bootstrap-memory for initial graph population
    • Save command /user:save-memory to persist session knowledge

    Restart opencode after running install.

    With Claude Code
    megamemory install --target claudecode
    

    Configures:

    • MCP server in ~/.claude.json
    • Workflow instructions in ~/.claude/CLAUDE.md
    • Commands in ~/.claude/commands/
    With Antigravity
    megamemory install --target antigravity
    

    Configures:

    • MCP server in ./mcp_config.json (workspace-level)
    With Codex
    megamemory install --target codex
    

    Configures:

    • MCP server in ~/.codex/config.toml
    • Workflow instructions in ~/.codex/AGENTS.md
    With other MCP clients

    Add megamemory as a stdio MCP server. The command is just megamemory (no arguments). It reads/writes .megamemory/knowledge.db relative to the working directory, or set MEGAMEMORY_DB_PATH to override.

    {
      "megamemory": {
        "type": "local",
        "command": ["megamemory"],
        "enabled": true
      }
    }
    

    MCP Tools

    ToolDescription
    understandSemantic search over the knowledge graph. Returns matched concepts with children, edges, and parent context.
    get_conceptLook up a concept by its exact ID. Returns full context including children, edges, incoming edges, and parent.
    create_conceptAdd a new concept with optional edges and file references.
    update_conceptUpdate fields on an existing concept. Regenerates embeddings automatically.
    linkCreate a typed relationship between two concepts.
    remove_conceptSoft-delete a concept with a reason. History preserved.
    list_rootsList all top-level concepts with direct children.
    list_conflictsList unresolved merge conflicts grouped by merge group.
    resolve_conflictResolve a merge conflict by providing verified, correct content based on the current codebase.

    Concept kinds: feature · module · pattern · config · decision · component

    Relationship types: connects_to · depends_on · implements · calls · configured_by

    Knowledge Graph


    Web Explorer

    Visualize the knowledge graph in your browser:

    megamemory serve
    
    • Nodes are colored by kind and sized by edge count
    • Dashed edges show parent-child links; solid edges show relationships
    • Click any node to inspect summary, files, and edges
    • Search supports highlight/dim filtering
    • If port 4321 is taken, you'll be prompted to pick another
    megamemory serve --port 8080   # custom port
    

    How It Works

    src/
      index.ts       CLI entry + MCP server (9 tools)
      tools.ts       Tool handlers (understand, get_concept, create, update, link, remove, list_conflicts, resolve_conflict)
      db.ts          SQLite persistence (libsql, WAL mode, schema v3)
      embeddings.ts  In-process embeddings (all-MiniLM-L6-v2, 384 dims)
      merge.ts       Two-way merge engine for knowledge.db files
      merge-cli.ts   CLI handlers for merge, conflicts, resolve commands
      types.ts       TypeScript types
      cli-utils.ts   Colored output + interactive prompts
      install.ts     multi-target installer (opencode, Claude Code, Antigravity, Codex)
      web.ts         HTTP server for graph explorer
    plugin/
      megamemory.ts  Opencode skill tool plugin
    commands/
      bootstrap-memory.md  /user command for initial population
      save-memory.md       /user command to save session knowledge
    web/
      index.html     Single-file graph visualization (d3-force + Canvas)
    
    • Embeddings — In-process via Xenova/all-MiniLM-L6-v2 (ONNX, quantized). No API keys, and no network calls after the first model download.
    • Storage — SQLite with WAL mode, soft-delete history, and schema migrations (currently v3).
    • Search — Brute-force cosine similarity over node embeddings; fast enough for graphs with <10k nodes.
    • Merge — Two-way merge with conflict detection by concept ID, with AI-assisted conflict resolution via MCP tools.

    CLI Commands

    CommandDescription
    megamemoryStart the MCP stdio server
    megamemory installConfigure editor/agent integration
    megamemory serveLaunch the web graph explorer
    megamemory mergeMerge two knowledge.db files
    megamemory conflictsList unresolved merge conflicts
    megamemory resolveResolve a merge conflict
    megamemory --helpShow help
    megamemory --versionShow version

    Merging Knowledge Graphs

    When branches diverge, each may update .megamemory/knowledge.db independently. Since SQLite files cannot be auto-merged by git, megamemory provides dedicated merge commands.

    Merge two databases
    megamemory merge main.db feature.db --into merged.db
    

    Concepts are compared by ID: identical nodes are deduplicated, and conflicting nodes are kept as ::left/::right variants under one merge group UUID. Use --left-label and --right-label to replace default side labels with branch names.

    megamemory merge main.db feature.db --into merged.db --left-label main --right-label feature-xyz
    
    View conflicts
    megamemory conflicts            # human-readable summary
    megamemory conflicts --json     # machine-readable output
    megamemory conflicts --db path  # specify database path
    
    Resolve conflicts manually
    megamemory resolve <merge-group-uuid> --keep left    # keep the left version
    megamemory resolve <merge-group-uuid> --keep right   # keep the right version
    megamemory resolve <merge-group-uuid> --keep both    # keep both as separate concepts
    
    AI-assisted resolution

    When an AI agent runs /merge, it calls list_conflicts, verifies both versions against current source files, then calls resolve_conflict with resolved: {summary, why?, file_refs?} plus a verification reason. It does not pick a side blindly; it resolves to what the codebase currently reflects.


    License

    MIT