project-brain-mcp
An MCP server that provides CLI coding agents with persistent decision memory, codebase dependency-graph awareness, plan validation against architectural constraints, and a self-bootstrapping constraints.md file.
README
project-brain-mcp
Standalone MCP server that gives CLI
coding agents (Claude Code, Cline, Cursor, opencode) persistent decision
memory, codebase dependency-graph awareness, plan validation against
architectural constraints, and a self-bootstrapping constraints.md file —
backed by a local SQLite database (.project-brain/decisions.db) in each
project it's wired into.
CLI agent support status
| Agent | Status |
|---|---|
| Claude Code | ✅ Tested end-to-end (indexing, dependency graph, decision memory, plan validation, bootstrap, all 24 tools). |
| Cline | ⚠️ Skill package shipped (skills/cline/), install script support present — not yet verified end-to-end. |
| Cursor | ⚠️ Skill package shipped (skills/cursor/), install script support present — not yet verified end-to-end. |
| opencode | ⚠️ Skill package shipped (skills/opencode/), install script support present — not yet verified end-to-end. |
If you try this with Cline, Cursor, or opencode, please open an issue with what worked / didn't — that feedback directly shapes which agent gets verified next.
Use case scenarios
These are real flows this server enables once wired into a project (the examples below are from testing against a Laravel/PHP codebase, but the same flows apply to any supported language):
-
Onboarding into an unfamiliar codebase. Run
index_codebaseonce, thenrun_bootstrap— the agent walks every module, records its inferred purpose/constraints/caveats vialog_module_intent, and generates a draftconstraints.md(Architectural Boundaries, Technology Constraints) for you to review and correct. -
"What breaks if I change this?" Before editing a shared model or service, the agent calls
get_dependents/get_blast_radiusto see every file that transitively depends on it — e.g. confirming that changingapp/Models/User.phponly affectsdatabase/seeders/DatabaseSeeder.php, not half the app. -
Don't repeat past mistakes. When an approach fails (a library doesn't fit, a migration breaks under load, etc.), the agent logs it with
log_failure. In a later session,get_context(topic)surfaces that failure before the agent tries the same thing again. -
Plan review against architectural rules. Before executing a multi-step plan,
validate_plan(task, steps)checks each step against logged hard constraints and graph-derived boundaries, returningPLAN: blockedwith specific fixes if a step would violate one. -
"Where do I even start?" For a feature request described in plain English,
find_entry_points(intent)does a semantic search over indexed modules — e.g.intent="HTTP request entry point for the web application"returned the relevant controllers in a Laravel app. -
Tracking structural drift over time.
diff_graph(since_commit)shows which dependency edges were added/removed since a given commit — useful after pulling a large set of changes before continuing work.
Supported languages
The code-graph indexer (index_codebase) parses these file types via
tree-sitter:
| Language | Extensions |
|---|---|
| TypeScript / JavaScript | .ts, .tsx, .js, .jsx, .mjs, .cjs |
| Python | .py |
| Rust | .rs |
| Go | .go |
| Java | .java |
| C / C++ | .c, .h, .cpp, .cc, .cxx, .hpp, .hh |
| PHP | .php (PSR-4 use resolution via composer.json) |
Other file types are indexed as plain nodes but produce no dependency edges.
Prerequisites
- Node.js
^20 || ^22 || >=24 - A git working tree for the project you want to wire this into (most tools
work without git, but
diff_graphand the incremental CLI ingest path use the current commit hash)
Install & build
git clone <this-repo>
cd code-brain-mcp
npm install
npm run build
This produces dist/src/index.js (the MCP server entry point) and
dist/cli/index.js (the project-brain CLI for remote ingest, see below).
Setup in a project
Option A — automated install script (recommended)
From the root of the project you want to add code-brain-mcp to:
/path/to/code-brain-mcp/scripts/install.sh
The script:
- Detects which agent(s) you use, based on marker files in your project:
- Claude Code:
CLAUDE.mdor.claude/ - Cline:
.clinerulesor.cline/ - Cursor:
.cursorrulesor.cursor/ - opencode:
AGENTS.mdor.opencode/
- Claude Code:
- Installs/merges the matching skill package from
skills/<agent>/into your project (project-memory instructions + a bootstrap flow), preserving any existing content in those files (code-brain-mcp's block is wrapped in<!-- code-brain-mcp:start/end -->markers). - Registers the MCP server in your agent's config (
.mcp.json,.cursor/mcp.json,opencode.json). Cline stores MCP config outside the repo — the script prints the entry to add manually via the Cline "MCP Servers" panel. - Creates
.project-brain/(the local SQLite database directory) if it doesn't already exist. - Installs a
.git/hooks/post-commithook (for the optional remote-ingest workflow, see below).
If no marker file is detected, the script exits with instructions for adding one manually.
Option B — manual config (Claude Code)
Add to .mcp.json (or your global ~/.claude.json under mcpServers):
{
"mcpServers": {
"code-brain": {
"command": "node",
"args": ["/path/to/code-brain-mcp/dist/src/index.js"]
}
}
}
Then copy skills/claude-code/CLAUDE.md and skills/claude-code/bootstrap.md
into your project so Claude Code knows how/when to call the tools.
First run
You don't need to type these calls yourself. Once
skills/claude-code/CLAUDE.mdis installed in your project root (viascripts/install.shor copied manually), Claude Code auto-loads it every session and treats the steps below as always-on behavior — it calls these tools on its own as part of normal work, andget_session_health()self-corrects if it skips one. The steps below are what happens under the hood, useful mainly for the very first run or for manual/CLI testing.
In a fresh Claude Code session in your project:
start_session()get_context(topic="...")— loads project memory, required before other tool calls per the session-health checker.index_codebase(incremental=false)— builds the initial dependency graph.get_bootstrap_status()— ifnever_run, runrun_bootstrap(path)repeatedly (seeskills/<agent>/bootstrap.mdfor the full multi-turn flow) to populateconstraints.mdwith the project's architectural boundaries and technology constraints.
After that, CLAUDE.md (or the equivalent rule file for your agent) describes
the always-on behaviors: calling get_dependents/get_dependencies/
get_blast_radius before changing a module, validate_plan before executing
a multi-step plan, log_decision/log_failure to build up project memory,
etc.
Transport modes
| Mode | Default | Auth | Notes |
|---|---|---|---|
local (stdio) |
yes | none | Single project, single SQLite file, spawned by your agent. |
remote (HTTP) |
set TRANSPORT_MODE=remote |
PROJECT_BRAIN_TOKEN bearer token (required — server refuses to start without it) |
Enables WAL mode + SQLITE_BUSY_TIMEOUT_MS for concurrent access; see scripts/project-brain.service for a systemd unit example. |
Remote mode env vars: TRANSPORT_MODE, PROJECT_BRAIN_TOKEN, HOST
(default 127.0.0.1), PORT (default 8420), SQLITE_BUSY_TIMEOUT_MS
(default 5000).
Remote ingest CLI
For the remote-server setup, the project-brain CLI (dist/cli/index.js)
pushes graph updates from a separate machine/CI job:
project-brain index --full --push --url https://your-server --token $PROJECT_BRAIN_TOKEN
project-brain index --since <commit> --push --url https://your-server --token $PROJECT_BRAIN_TOKEN
The installed post-commit git hook runs the --since HEAD~1 --push
incremental form automatically if PROJECT_BRAIN_URL is set in your
environment.
Project memory file: constraints.md
export_constraints_file() generates a human-readable constraints.md at
your project root (YAML frontmatter + Architectural Boundaries / Technology
Constraints / Flagged-for-review sections). Edit it by hand, then call
ingest_constraints_file() to sync your edits back into the database. See
constraints.md in this repo for a live example of the format.
A note on secrets
index_codebase never reads or stores raw file contents — it only parses
source files (per the extensions listed above) for import/dependency edges,
and stores file paths + module names in .project-brain/decisions.db. It
never reads .env files or similar.
The decisions/failures/module_intents/constraints tables store
free-text written by your agent via log_decision, log_failure, and
log_module_intent — avoid having your agent paste secrets/credentials into
those calls, the same way you would with any chat. .project-brain/ is
already in .gitignore, so this database stays local and is never committed.
Roadmap
- Verify Cline / Cursor / opencode support. Skill packages and install
paths exist for all three (
skills/<agent>/), but only Claude Code has been tested end-to-end so far. - Plugin-based language support. Today, adding a language means adding a
tree-sitter grammar dependency and a walker function in
src/parser/treesitter.ts(see PHP support as the most recent example). The goal is to make this a drop-in plugin interface so the community can add languages (Java/Kotlin for Android, C#/.NET, etc.) without touching core indexer code. - Composer autoload beyond PSR-4. PHP support currently resolves
usestatements via PSR-4 only;classmap/files/psr-0autoload strategies and multi-composer.jsonmonorepos are not yet covered. - Non-code / document repos. The dependency-graph model is code-specific today (tree-sitter ASTs). An exploratory direction is a parallel "document graph" mode for non-code repositories (e.g. a folder of legal contracts or policy documents) — same decision-memory/constraints-file mechanics, but relationships derived from document structure/references instead of imports. This is an early idea, not yet scoped into a spec.
Contributions and issue reports toward any of the above are welcome.
Development
npm test # vitest
npm run build # tsc
npm run dev # run the server directly via tsx, stdio mode
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。