CogMemory MCP Server
Provides a unified context system for AI coding agents with memory, knowledge graph, specs, and code graph subsystems, all stored in SQLite. Enables persistent recall of decisions, conventions, errors, project knowledge, and code structure.
README
CogMemory MCP Server
A unified Model Context Protocol server providing four context subsystems for AI coding agents:
- Memory — decisions, conventions, errors, active context, changelog, plan, tasks, sessions
- Knowledge Graph — entities, relations, observations
- Specs — long-form documents (PRD/SRS), optionally linked to a KG entity
- Code Graph — static structural graph (symbols/edges) + named execution traces + AI-generated annotations
Storage: SQLite via better-sqlite3. One .db file per scope.
Quick Start
Install
git clone <repo> && cd cogmemory-mcp
pnpm install
pnpm run build
Configure in VS Code
Add to .vscode/mcp.json (workspace-scoped):
{
"servers": {
"cogmemory": {
"command": "node",
"args": ["/absolute/path/to/cogmemory-mcp/dist/index.js"]
}
}
}
Or add to your user mcp.json for global availability.
Run with MCP Inspector (dev)
pnpm run inspect
Scope Configuration
CogMemory resolves scope in priority order:
-
.cogmemory/config.jsonin workspace root:{ "scope": "global" } -
Environment variable:
COGMEMORY_SCOPE=global -
Default:
workspace
Paths
| Scope | Database Path |
|---|---|
| workspace | <workspace_root>/.cogmemory/memory.db |
| global | ~/.cogmemory/global.db |
Workspace Resolution & Multi-Root Support
CogMemory resolves the workspace root (where .cogmemory/memory.db lives) in this priority order:
--workspace <path>CLI argument (highest priority)COGMEMORY_WORKSPACEenvironment variable- Walk up from CWD looking for the nearest parent containing a
.cogmemory/directory - Fallback to CWD
Multi-Root VS Code Workspaces
In a VS Code multi-root workspace, each folder is a separate workspace root. CogMemory handles this:
- Single-root — Works automatically. VS Code sets CWD to the workspace folder, and
--workspaceis passed viamcp.json. - Multi-root — Each workspace folder can have its own
.cogmemory/. Point each to CogMemory with different--workspacepaths, or place a shared.cogmemory/in a parent directory.
Recommended multi-root mcp.json (per-folder):
{
"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"
]
}
}
}
Or use a shared database (all roots in one place):
{
"servers": {
"cogmemory": {
"command": "node",
"args": [
"/path/to/cogmemory-mcp/dist/index.js",
"--workspace",
"/shared/root"
]
}
}
}
Or use global scope to share across all workspaces:
{
"servers": {
"cogmemory": {
"command": "node",
"args": ["/path/to/cogmemory-mcp/dist/index.js"]
}
}
}
export COGMEMORY_SCOPE=global
Tool Reference
Memory Tools
| Tool | Description |
|---|---|
start_session |
Begin a work session (returns session ID) |
end_session |
Close session, store summary |
get_session_summary |
Recall session details including decisions, errors, changelog |
remember_decision |
Log a decision with rationale and tags |
remember_convention |
Log/update a convention (design token, pattern, style, naming) |
log_error |
Record an error with signature and resolution |
set_active_context |
Upsert current focus/task by key |
get_active_context |
Read current focus by key |
log_change |
Append changelog entry |
add_plan_item |
Add a roadmap item |
update_plan_status |
Change plan item status |
create_task |
Create a task, optionally linked to a plan |
update_task_status |
Change task status |
recall |
Unified search across decisions/conventions/errors/changelog |
Knowledge Graph Tools
| Tool | Description |
|---|---|
create_entity |
Add entity (deduped on name+type) |
create_relation |
Link two entities with a typed relation |
add_observation |
Attach a fact to an entity |
search_knowledge |
Query entities, relations, observations |
Specs Tools
| Tool | Description |
|---|---|
create_spec |
Store a long-form document |
get_spec |
Retrieve by ID or exact title |
update_spec |
Update content/title, auto-bumps version |
Code Graph Tools
| Tool | Description |
|---|---|
index_codebase |
Walk workspace, extract symbols + edges via ts-morph (JS/TS) |
query_code_graph |
Look up a symbol's callers/callees/imports (1-hop) |
generate_codemap |
BFS from entry symbol, bounded subgraph with optional traces + annotations |
annotate_symbol |
Attach narrative text to a symbol or trace |
Architecture
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
Schema (15 tables)
- Memory (8):
sessions,decisions,conventions,errors,context,changelog,plan,tasks - Knowledge Graph (3):
entities,relations,observations - Specs (1):
specs - Code Graph (4):
symbols,edges,execution_traces,codemap_annotations
Pragmas
Set on every connection open:
PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = ON;
Development
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
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。