Skip to main content
Glama
skylarng89

CogMemory MCP Server

by skylarng89

CogMemory MCP 服务器

一个统一的模型上下文协议服务器,为 AI 编码代理提供四个上下文子系统:

  1. 记忆 — 决策、约定、错误、活动上下文、变更日志、计划、任务、会话

  2. 知识图谱 — 实体、关系、观察

  3. 规格文档 — 长文文档(PRD/SRS),可选地链接到知识图谱实体

  4. 代码图谱 — 静态结构图(符号/边)+ 命名执行轨迹 + AI 生成的注释

存储:SQLite,通过 better-sqlite3。每个作用域一个 .db 文件。


快速开始

安装

git clone <repo> && cd cogmemory-mcp
pnpm install
pnpm run build

在 VS Code 中配置

添加到 .vscode/mcp.json(工作区作用域):

{
  "servers": {
    "cogmemory": {
      "command": "node",
      "args": ["/absolute/path/to/cogmemory-mcp/dist/index.js"]
    }
  }
}

或者添加到你的用户 mcp.json 以实现全局可用。

使用 MCP Inspector 运行(开发)

pnpm run inspect

Related MCP server: LumenCore

作用域配置

CogMemory 按优先级顺序解析作用域:

  1. 工作区根目录下的 .cogmemory/config.json:

    { "scope": "global" }
  2. 环境变量:COGMEMORY_SCOPE=global

  3. 默认值:workspace

路径

作用域

数据库路径

workspace

<workspace_root>/.cogmemory/memory.db

global

~/.cogmemory/global.db


工作区解析与多根支持

CogMemory 按优先级顺序解析工作区根目录(.cogmemory/memory.db 所在位置):

  1. --workspace <path> 命令行参数(最高优先级)

  2. COGMEMORY_WORKSPACE 环境变量

  3. 从当前工作目录向上查找,寻找最近的包含 .cogmemory/ 目录的父目录

  4. 回退到当前工作目录

多根 VS Code 工作区

在 VS Code 多根工作区中,每个文件夹是一个独立的工作区根目录。CogMemory 的处理方式如下:

  • 单根 — 自动工作。VS Code 将当前工作目录设置为工作区文件夹,--workspace 通过 mcp.json 传入。

  • 多根 — 每个工作区文件夹可以有自己的 .cogmemory/。通过不同的 --workspace 路径将每个指向 CogMemory,或者在父目录中放置一个共享的 .cogmemory/。

推荐的多根 mcp.json(按文件夹):

{
  "servers": {
    "cogmemory-frontend": {
      "command": "node",
      "args": [
        "/path/to/cogmemory-mcp/dist/index.js",
        "--workspace",
        "/path/to/frontend"
      ]
    },
    "cogmemory-backend": {
      "command": "node",
      "args": [
        "/path/to/cogmemory-mcp/dist/index.js",
        "--workspace",
        "/path/to/backend"
      ]
    }
  }
}

或者使用共享数据库(所有根共用一个位置):

{
  "servers": {
    "cogmemory": {
      "command": "node",
      "args": [
        "/path/to/cogmemory-mcp/dist/index.js",
        "--workspace",
        "/shared/root"
      ]
    }
  }
}

或者使用全局作用域以跨所有工作区共享:

{
  "servers": {
    "cogmemory": {
      "command": "node",
      "args": ["/path/to/cogmemory-mcp/dist/index.js"]
    }
  }
}
export COGMEMORY_SCOPE=global

工具参考

记忆工具

工具

描述

start_session

开始一个工作会话(返回会话 ID)

end_session

结束会话,存储摘要

get_session_summary

回忆会话详情,包括决策、错误、变更日志

remember_decision

记录一个决策及其理由和标签

remember_convention

记录/更新约定(设计令牌、模式、命名风格)

log_error

记录一个错误及其签名和解决方案

set_active_context

按键更新当前活动上下文/任务

get_active_context

按键读取当前活动上下文

log_change

追加变更日志条目

add_plan_item

添加一个计划项

update_plan_status

更改计划项状态

create_task

创建一个任务,可选地链接到计划

update_task_status

更改任务状态

recall

跨决策/约定/错误/变更日志的统一搜索

知识图谱工具

工具

描述

create_entity

添加实体(按名称+类型去重)

create_relation

用类型化关系链接两个实体

add_observation

为实体附加一个事实

search_knowledge

查询实体、关系、观察

规格文档工具

工具

描述

create_spec

存储一个长文文档

get_spec

按 ID 或精确标题检索

update_spec

更新内容/标题,自动递增版本

代码图谱工具

工具

描述

index_codebase

遍历工作区,通过 ts-morph 提取符号 + 边(JS/TS)

query_code_graph

查找符号的调用者/被调用者/导入(1 跳)

generate_codemap

从入口符号开始 BFS,有界子图,可选轨迹 + 注释

annotate_symbol

为符号或轨迹附加叙述性文本


架构

cogmemory-mcp/
├── src/
│   ├── index.ts                 # entry point, server bootstrap
│   ├── config.ts                # scope resolution, path resolution
│   ├── types.ts                 # shared TS types mirroring schema
│   ├── db/
│   │   ├── connection.ts        # DB open/close, pragma setup
│   │   ├── schema.sql           # full schema (reference)
│   │   └── migrate.ts           # idempotent schema application
│   ├── tools/
│   │   ├── memory.ts            # decisions/conventions/errors/context/changelog/recall
│   │   ├── plan-tasks.ts        # plan + tasks tools
│   │   ├── sessions.ts          # start/end session, summary
│   │   ├── knowledge-graph.ts   # entities/relations/observations
│   │   ├── specs.ts             # spec CRUD
│   │   ├── code-graph.ts        # index_codebase, query_code_graph
│   │   └── codemap.ts           # generate_codemap, annotate_symbol
│   └── indexing/
│       ├── ts-analyzer.ts       # ts-morph symbol/edge extraction
│       └── walker.ts            # file discovery, gitignore respect
├── schema.sql                   # reference copy
├── package.json
├── tsconfig.json
└── README.md

模式(15 张表)

  • 记忆(8): sessions、decisions、conventions、errors、context、changelog、plan、tasks

  • 知识图谱(3): entities、relations、observations

  • 规格文档(1): specs

  • 代码图谱(4): symbols、edges、execution_traces、codemap_annotations


编译指示

在每次打开连接时设置:

PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = ON;

开发

pnpm run dev        # Run with tsx (no build step)
pnpm run build      # Compile TypeScript
pnpm run start      # Run compiled output
pnpm run inspect    # Launch MCP Inspector
pnpm run smoke-test # Run smoke test script

许可证

MIT

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides AI coding assistants with persistent project memory to retain architectural decisions, code patterns, and domain knowledge across sessions. It stores data locally in a SQLite database, allowing agents to remember, recall, and manage project-specific context using full-text search.
    8 npm
    Apache 2.0
  • A
    license
    A
    quality
    B
    maintenance
    Provides persistent cross-session memory and full-text search for AI coding assistants, storing project context, decisions, and preferences while enabling searchable access to conversation history via local SQLite.
    8
    1
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Acts as a persistent memory and cross-tool shared context store, and builds a queryable codebase knowledge graph to slash token usage via structural answers.
    9
    37 npm
    19
    MIT