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): sessionsdecisionsconventionserrorscontextchangelogplantasks

  • 知识图谱(3): entitiesrelationsobservations

  • 规格文档(1): specs

  • 代码图谱(4): symbolsedgesexecution_tracescodemap_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

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    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
    Apache 2.0
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI coding agents to maintain persistent, cross-session memory of codebase architecture, naming conventions, and decisions through MCP tools. Eliminates repetitive project re-explanation by automatically injecting stored context into every session with local-first SQLite storage and optional team sharing capabilities.
    4
    MIT
  • 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

View all related MCP servers

Related MCP Connectors

  • Persistent memory and knowledge graphs for AI agents. Hybrid search, context checkpoints, and more.

  • Universal memory for AI agents and tools. Save, organize and search context anywhere.

  • Give your AI agent a persistent map of your project's structure, dependencies, and bugs.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/skylarng89/cogmemory-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server