ProjectBrain (projectbrain-mcp v0.8.9)

Local SQLite Code Graph, Program Slicer, and Syntax-Verified Symbol Patcher for AI Coding Agents.
ProjectBrain indexes a repository locally into .projectbrain.db (SQLite WAL + FTS5) using tree-sitter and language AST parsers. It gives CLI and MCP coding agents four concrete primitives in a single dependency-light package—with no external database server, no Docker, no cloud embeddings, and no API keys:
- Program & Symbol Slicing (
projectbrain slice/brain_slice):- Slices exact functions, classes, methods, CommonJS/prototype assignments (
res.send,app.use), or line ranges (file.py:ClassName.methodorfile.py:120-160) directly from SQLite in< 20mswithout loading full files into the context window. - For large functions sliced around a target variable or call, computes an AST/Program Dependence Graph (PDG) slice across three orthogonal dimensions: backward data dependence (
def -> use), forward data dependence (def -> use), and enclosing control-flow guards (if/try/for/with), collapsing unrelated lines while keeping governing logic intact.
- Slices exact functions, classes, methods, CommonJS/prototype assignments (
- One-Turn Code Dossiers (
projectbrain dossier/brain_dossier):- Given a bug report, stack trace, or architectural question, ranks relevant symbols using sub-identifier BM25 + call/import/state-flow graph traversal and returns class-qualified (
ClassName.method) target code slices plus 1-hop caller/callee signatures in a single read.
- Given a bug report, stack trace, or architectural question, ranks relevant symbols using sub-identifier BM25 + call/import/state-flow graph traversal and returns class-qualified (
- Syntax-Verified Symbol Patching (
projectbrain patch/brain_patch):- Applies symbol-anchored edits (
@replace_body <Symbol>,@add_method <ClassName>,@replace <Symbol>,@sub <Symbol>) validated against Tree-sitter + language syntax compilers and caller arity contracts before touching disk, with automatic rollback on syntax errors and zero-change dry runs.
- Applies symbol-anchored edits (
- Closed-World Structural Verification (
projectbrain verify/projectbrain_verify_claim):- Verifies structural claims (
calls,reaches,imports,handles) with explicit evidence provenance (exact,import_resolved,candidate) and refuses to guess (UNKNOWN) when any traversed file has a syntax error or when a call goes through a dynamic local receiver (adapter.send(...)) whose type cannot be resolved statically.
- Verifies structural claims (
Language-Support Tiers
ProjectBrain indexes 29 file extensions across three explicit capability tiers:
| Tier | Languages / Formats | Capabilities |
|---|---|---|
| Tier 1: Deep AST + PDG + Contracts | Python (.py), TypeScript / JavaScript (.ts, .tsx, .js, .jsx, .mjs, .cjs) |
Full Tree-sitter + Python ast parsing (including CommonJS obj.method = function, chained assignments, Class.prototype.method, exports.foo, defineGetter, and @typing.overload stub deduplication); intra-function PDG data/control-dependence slicing (def -> use + enclosing guards); cross-file relative import, require('./mod'), & tsconfig path-alias resolution; class/module config & descriptor tracking (ConfigAttribute, Field, Column, constants); route extraction (Flask, FastAPI, Django, Next.js, Express, Hono); caller arity & SQL schema contract checks. |
| Tier 2: Tree-sitter Structural + Call Graph | Go (.go), Rust (.rs), Java (.java), Kotlin (.kt), C / C++ (.c, .h, .cpp, .hpp), C# (.cs), Ruby (.rb), PHP (.php) |
Structural symbol extraction (functions, methods, structs, classes, interfaces, traits); intra-file and cross-file call/import graph edges; signature skeletons; symbol & line-range slicing; syntax-verified symbol patching. |
| Tier 3: Schema, Query & Component Indexing | SQL (.sql), GraphQL (.graphql, .gql), Prisma (.prisma), Protobuf (.proto), Vue / Svelte (.vue, .svelte), Scala (.scala), Swift (.swift) |
DDL table/column/constraint extraction (CREATE TABLE, NOT NULL), schema-to-code linking, component script extraction, and symbol/line slicing. |
When to Use ProjectBrain vs. Plain grep
- When plain
rg/grepis faster: Looking up a single literal string or constant when you already know the exact identifier name and just want matching line numbers. - When ProjectBrain wins:
- Multi-hop call and dispatch questions (e.g., "how are exceptions routed to error handlers" or "how are redirects handled and when is auth stripped"), where following imports, mixins, and helper methods across files takes multiple turns of manual search/read loops.
- Reading specific methods inside large files (
projectbrain slice django/db/models/sql/query.py:Query.build_filterorprojectbrain slice res.send) without dumping a 2,500-line file into the prompt. - Safe symbol-anchored patching (
projectbrain patch --apply) where line numbers have drifted or where syntax errors must be rejected before writing to disk.
Quick Start
1. Install
pip install "projectbrain-mcp>=0.8.9"
2. Initialize a Repository (Minimal & Non-Destructive)
projectbrain --path /path/to/your/repo init
- Honors
.gitignore: Automatically respects root and nested.gitignoreand.git/info/excluderules. - Minimal Default Setup (
--ide auto): Creates.projectbrain.db(SQLite WAL), updates.gitignore, and writes.mcp.jsonandAGENTS.mdat the repo root using non-destructive<!-- projectbrain:start --> ... <!-- projectbrain:end -->markers. Only writes.cursor/,.vscode/, or.claude/configs if those directories already exist in your repository (or when--ide all/--ide claudeis explicitly passed). - Safe Execution Defaults: Direct shell execution over MCP (
brain_run) is disabled by default unless explicitly opted in viaPROJECTBRAIN_ALLOW_EXEC=1.
3. MCP Server Configuration
{
"mcpServers": {
"projectbrain": {
"command": "projectbrain-mcp",
"args": ["--lean", "/path/to/your/repo"]
}
}
}
4. Core CLI Commands
# 1. Slice exact symbols or line ranges (fast <20ms SQLite lookup on indexed repos)
projectbrain --path /path/to/repo slice Query.build_filter res.send should_strip_auth
# 2. Compile a 1-turn code dossier (target slices + callers + callees)
projectbrain --path /path/to/repo dossier "how are exceptions routed to error handlers"
# 3. Apply a syntax-verified, symbol-anchored patch (--apply to write, omit for dry-run diff)
projectbrain --path /path/to/repo patch --apply --spec-file patch.spec
# 4. Verify closed-world structural claims (calls, reaches, imports, handles)
projectbrain --path /path/to/repo verify "Session.send" calls "HTTPAdapter.send"
Reproducible Evaluation & Scale Benchmarks (projectbrain/eval/)
All correctness, retrieval, claim-verification, and external repository benchmarks can be run locally from the repository root:
# 1. Fixture regression guards, self-dogfooding, and zero-ID adversarial evaluation
python projectbrain/eval/run_eval.py
# 2. 200-file polyglot scale, incremental Salsa early-cutoff, FTS5, and recursive CTE latency benchmark
python projectbrain/eval/bench_scale.py
# 3. External repository benchmarks: pallets/flask, django/django, psf/requests, pallets/click, expressjs/express
python projectbrain/eval/bench_external.py --suite all
# 4. Full unit, integration, security, and regression test suite (202 tests)
pytest projectbrain/tests -q
1. Held-Out External Repository Benchmark (python projectbrain/eval/bench_external.py --suite heldout)
Tested on three open-source repositories across Python and CommonJS JavaScript (psf/requests, pallets/click, expressjs/express):
| Repository | Dossier Questions | Target Symbol Slice Recall | Cost per Hit | Additional Structural Checks |
|---|---|---|---|---|
psf/requests |
4 questions (proxies, redirects/auth, cookies, adapters/pool) |
15 / 15 (100%) |
3.71 KB |
verify_claim("Session.send", "calls", "HTTPAdapter.send") -> UNKNOWN (dynamic receiver adapter.send, never false REFUTED); slice_symbols(["should_strip_auth", "get_environ_proxies"]) -> 2 / 2 |
pallets/click |
3 questions (option/arg parsing, Group subcommand dispatch, ParamType converters) |
9 / 11 (81.8%) |
4.95 KB |
0 bare __init__ headers (all methods qualified as ClassName.method, e.g. Group.invoke, Group.resolve_command, ParamType.convert, Parameter.type_cast_value) |
expressjs/express |
3 questions (res.send content-type, app.use mounting, app.handle dispatch) |
6 / 6 (100%) |
2.34 KB |
lib/response.js: 32 functions indexed; lib/application.js: 18 functions indexed; slice_symbols(["res.send", "app.use", "app.handle"]) -> 3 / 3 |
| Combined Held-Out Total | 10 questions | 30 / 32 (93.8%) |
3.81 KB |
— |
2. Tuned External Repository Benchmarks (pallets/flask & django/django)
(Note: pallets/flask and django/django were used during v0.8.5–v0.8.8 development to tune dossier token budgets, PDG slicing, and incremental indexing latency.)
| Benchmark | v0.8.4 |
v0.8.6 |
v0.8.9 |
|---|---|---|---|
pallets/flask (6 Architectural Questions) — Target Function Slice Recall |
9 / 19 (47.4%) |
12 / 19 (63.2%) |
21 / 21 (100%, 19 / 19 subset) |
pallets/flask (6 Architectural Questions) — Total Dossier Output |
68.0 KB |
113.0 KB |
55.8 KB (-50.6% vs v0.8.6) |
pallets/flask (6 Architectural Questions) — Cost per Correct Hit |
7.6 KB |
9.4 KB |
2.66 KB |
pallets/flask — End-to-End Bug-Fix (dossier -> slice -> patch -> test) |
— | — | PASS (red -> green in 1.51 s, 0 syntax/contract errors) |
django/django (3,051 files) — Cold brain.load() / Cold Walk Latency |
~8,300 ms / 820 ms | ~8,300 ms / 820 ms | ~4,400 ms / ~245 ms |
django/django (3,051 files) — Single-File Edit incremental_index() Latency |
~7,000 ms (global rebuild) | ~7,000 ms (global rebuild) | 515 ms body edit (salsa_early_cutoff: True) / 894 ms interface edit |
3. Built-In Verification & Dogfooding Suite (python projectbrain/eval/run_eval.py)
| Suite | Scope | Metric | Result | Notes & Grep Comparison |
|---|---|---|---|---|
File Localization (eval/tasks.json) |
Small fixture repos (10 tasks) | Precision / Recall | 100% / 100% |
Regression guard on basic file ranking (many are grep-answerable) |
Multi-Hop Graph vs. Grep (eval/relationship_tasks.json) |
Small fixture repos (8 tasks, incl. negative controls) | Pass Rate | 8 / 8 (100%) |
Tests 2-hop call paths where single-file grep misses the intermediate module |
Closed-World Claim Verification (eval/claim_tasks.json) |
Small fixture repos (22 tasks) | Exact Verdict Accuracy | 22 / 22 (100%) |
0 false supports, 0 false refutations; returns UNKNOWN on syntax-broken files |
Self-Dogfooding (compile_context) |
ProjectBrain repo (3 tasks, 6 target symbols) | Symbol Recall & Token Savings | 100% (6 / 6 symbols) |
22.2%–29.9% fewer tokens than disciplined grep + 120-line windows (93.1%–97.6% vs full files); grep recall is 100% on 2 tasks and 0% on 1 task |
Adversarial Zero-Identifier (compile_context) |
ProjectBrain repo (4 tasks, 8 target symbols; zero function names in prompt) | Symbol Recall & Token Savings | 87.5% (7 / 8 symbols) |
100% recall on 3 tasks and 50% on 1 task vs 50.0% (4 / 8) for disciplined grep; token delta vs grep ranges from -6.0% to +26.4% |
Changelog (v0.8.5 – v0.8.9)
- CommonJS / Prototype Method Indexing, Dynamic Dispatch Verification, and Held-Out Benchmarks (
v0.8.9):- JS CommonJS & Prototype Indexing:
_parse_jsnow indexesobj.method = function, chained assignments (res.contentType = res.type = function),Class.prototype.method = function,exports.foo = function,module.exports = function, anddefineGetter(obj, 'prop', function), plus CommonJSrequire('./mod')symbol bindings. Onexpressjs/express,lib/response.jsindexes 32 functions (up from 10),lib/application.jsindexes 18 functions (up from 2), andres.send,app.use, andapp.handleslice cleanly. - Dynamic Receiver Dispatch ->
UNKNOWNinverify_claim: When a function calls.method()on a local variable or dynamic receiver (adapter.send(request)inSession.send),verify_claim("Session.send", "calls", "HTTPAdapter.send")now returnsUNKNOWN(explaining that the dynamic receiver cannot be resolved statically) instead of a falseREFUTED. - Class-Qualified Headers & Retrieval: All dossier headers and call-graph pointers now format methods as
ClassName.method(eliminating ambiguous bare__init__or bareconvertheaders),@typing.overloadstubs are filtered during Python indexing, andeval/bench_external.pynow includes a held-out benchmark suite acrosspsf/requests,pallets/click, andexpressjs/express.
- JS CommonJS & Prototype Indexing:
- Tree-sitter CST Program Dependence Graph (PDG) Slicing for JS/TS/Go/Rust/Java (
v0.8.8):- Added
_analyze_treesitter_cst_pdgsocompute_multidim_program_sliceuses real Tree-sitter Concrete Syntax Trees for.ts,.tsx,.js,.jsx,.go,.rs, and.javain addition to Python'sastmodule.
- Added
- Dossier Token Budget, Docstring Folding, Visible PDG Provenance, and $O(\Delta)$ Incremental Graph Updates (
v0.8.7):- Folded multi-line Python docstrings (
> 3lines) in dossier slices, wiredcompute_multidim_program_sliceintocompile_dossier()with# [PDG Slice: ...]banners, and added incrementalCodeGraph.update_files+ SQLitegraph_deltapersistence.
- Folded multi-line Python docstrings (
Metadata
Release files for projectbrain-mcp 0.8.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| projectbrain_mcp-0.8.9.tar.gz | 230.2 kB | Without provenance | Details for projectbrain_mcp-0.8.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| projectbrain_mcp-0.8.9-py3-none-any.whl | Python 3 | none | any | Details for projectbrain_mcp-0.8.9-py3-none-any.whl |
Total release size: 419.7 kB
Release files / projectbrain_mcp-0.8.9.tar.gz
| Download URL | projectbrain_mcp-0.8.9.tar.gz |
|---|---|
| Size | 230.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f2141978eb02e699032e82116ebcb4e30a9dd04484c5301227fd488a580abee
|
|
BLAKE2b-256 checksum How to use checksums |
54b4cdf47caf7483ac65bd713b0e3482e29446c0a800cf7b7467a146272415cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / projectbrain_mcp-0.8.9-py3-none-any.whl
| Download URL | projectbrain_mcp-0.8.9-py3-none-any.whl |
|---|---|
| Size | 189.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d42c11daf4f8a64fd1bda60289305c53f281fd8ef1e3262229b51d325231d1f
|
|
BLAKE2b-256 checksum How to use checksums |
de6c7614b5374fca9cba0737f1af2688e269f80b97da66bc474c068c12d389f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for projectbrain-mcp 0.8.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.